Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue #891] Implement message recalling API in C# SDK #908

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions csharp/rocketmq-client-csharp/ClientManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ public async Task Shutdown()
request, response, metadata);
}

public async Task<RpcInvocation<Proto.RecallMessageRequest, Proto.RecallMessageResponse>>
RecallMessage(Endpoints endpoints, Proto.RecallMessageRequest request, TimeSpan timeout)
{
var metadata = _client.Sign();
var response = await GetRpcClient(endpoints).RecallMessage(metadata, request, timeout);
return new RpcInvocation<Proto.RecallMessageRequest, Proto.RecallMessageResponse>(
request, response, metadata);
}

public async Task<RpcInvocation<Proto.SendMessageRequest, Proto.SendMessageResponse>> SendMessage(
Endpoints endpoints, Proto::SendMessageRequest request, TimeSpan timeout)
{
Expand Down
10 changes: 10 additions & 0 deletions csharp/rocketmq-client-csharp/IClientManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ Task<RpcInvocation<HeartbeatRequest, HeartbeatResponse>> Heartbeat(Endpoints end
/// <returns>Task of response.</returns>
Task<RpcInvocation<NotifyClientTerminationRequest, NotifyClientTerminationResponse>> NotifyClientTermination(
Endpoints endpoints, NotifyClientTerminationRequest request, TimeSpan timeout);

/// <summary>
/// Recall messages.
/// </summary>
/// <param name="endpoints">The target endpoints.</param>
/// <param name="request">gRPC request of recalling messages.</param>
/// <param name="timeout">Request max duration.</param>
/// <returns>Task of response.</returns>
Task<RpcInvocation<RecallMessageRequest, RecallMessageResponse>> RecallMessage(
Endpoints endpoints, RecallMessageRequest request, TimeSpan timeout);

/// <summary>
/// Send message to remote endpoints.
Expand Down
24 changes: 24 additions & 0 deletions csharp/rocketmq-client-csharp/IRecallReceipt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Org.Apache.Rocketmq
{
public interface IRecallReceipt
{
string MessageId { get; }
}
}
2 changes: 2 additions & 0 deletions csharp/rocketmq-client-csharp/IRpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ Task<ForwardMessageToDeadLetterQueueResponse> ForwardMessageToDeadLetterQueue(Me
Task<NotifyClientTerminationResponse> NotifyClientTermination(Metadata metadata,
NotifyClientTerminationRequest request, TimeSpan timeout);

Task<RecallMessageResponse> RecallMessage(Metadata metadata, RecallMessageRequest request, TimeSpan timeout);

Task Shutdown();
}
}
34 changes: 34 additions & 0 deletions csharp/rocketmq-client-csharp/RecallReceipt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Org.Apache.Rocketmq
{
public sealed class RecallReceipt : IRecallReceipt
{
public RecallReceipt(string messageId)
{
MessageId = messageId;
}

public string MessageId { get; }

public override string ToString()
{
return $"{nameof(MessageId)}: {MessageId}";
}
}
}
9 changes: 9 additions & 0 deletions csharp/rocketmq-client-csharp/RpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,14 @@ internal static HttpMessageHandler CreateHttpHandler()
var call = _stub.NotifyClientTerminationAsync(request, callOptions);
return await call.ResponseAsync;
}

public async Task<Proto::RecallMessageResponse> RecallMessage(Metadata metadata, Proto.RecallMessageRequest request, TimeSpan timeout)
{
var deadline = DateTime.UtcNow.Add(timeout);
var callOptions = new CallOptions(metadata, deadline);

var call = _stub.RecallMessageAsync(request, callOptions);
return await call.ResponseAsync;
}
}
}
2 changes: 1 addition & 1 deletion csharp/rocketmq-client-csharp/SendReceipt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private SendReceipt(string messageId, string transactionId, MessageQueue message
}

public string MessageId { get; }

public string TransactionId { get; }

private MessageQueue MessageQueue { get; }
Expand Down
Loading