question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What 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:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
phatboygcommented, Dec 9, 2016

When calling Publish and 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.

0reactions
phatboygcommented, Dec 9, 2016

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found