Cancellation
See original GitHub issueWhat is the purpose of cancellation tokens in methods like Publish or Request? Example:
public class TestConsumer : IConsumer<Person>
{
public async Task Consume(ConsumeContext<Person> context)
{
await Task.Delay(10000, context.CancellationToken);
context.CancellationToken.ThrowIfCancellationRequested();
context.Respond(new PersonResponse() { Name = "SAD" });
}
}
IRequestClient<Person, PersonResponse> client = busControl.CreatePublishRequestClient<Person, PersonResponse>(TimeSpan.FromSeconds(30));
var cts = new CancellationTokenSource();
Task.Run(async () =>
{
await Task.Delay(3000);
cts.Cancel();
});
var c = await client.Request(new Person() { Name = "ELO" }, cts.Token);
In ‘Consume’ method I would expect to throw an exception. Is there anything I am missing here? How should we handle it? Should we build our own mechanism?
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Cancellation Definition & Meaning
1 · the act or an instance of canceling. The cancellation of the game was due to bad weather. ; 2 · something...
Read more >Statement from President Joe Biden on Student Loan Debt ...
I'm proud that my Administration is delivering on that promise and has already approved over $116 billion in debt cancellation for 3.4 ...
Read more >Cancellation Definition & Meaning
the fact or an instance of cancelling · something that has been cancelled, such as a theatre ticket, esp when it is available...
Read more >CANCELLATION definition | Cambridge English Dictionary
the act of deciding that an organized event will not happen or of stopping an order for something: Many trains are subject to...
Read more >Cancel your registration and plates
Once the registration has been cancelled, the vehicle will be removed from the next cancellation list that is provided to municipalities on October...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

When calling
Publishand passing a cancellationToken, if you no longer want to wait for the message to be published, you can cancel the operation.In the case of consuming a message, the CancellationToken is controlled by the transport, and if the transport fails or triggers a cancellation, it will set the cancellationToken to Cancel.
Cancellation of the request from the client side is not going to cancel the consumer on the receive endpoint. The only times that the consumeContext CancellationToken is set is when the transport aborts the message, which almost never happens. Once the message is sent from the client to RabbitMQ, the only thing that is cancelled is the wait on the client side.