0

Regarding the cancellation token, how does one use it to cancel a message? If I do not complete the message, does it get cancelled automatically (e.g. retried later when there is a connection)? Do I need to abandon it? Is the cancellation token only on the SubscriptionClient?

For example when I close the connection with CloseAsync(), cancellationToken.IsCancellationRequested is triggered.

Is that the only use of the cancellation token. A little light on how one can use the cancellation token would be very helpful.

Puzzle
  • 23
  • 1
  • 4

1 Answers1

0

Regarding the cancellation token, how does one use it to cancel a message?

You don't "cancel" a message. You can

  • Complete
  • Abandon
  • Defer
  • Dead-letter

In case you hold on to the message longer than LockDuration value, lock token of the message is lost and the message becomes available again. If you want proactively cancel message processing and return it back for another processor to pick up, you abandon the message.

Sean Feldman
  • 23,443
  • 7
  • 55
  • 80
  • Yes but cancellationtoken.IsCancellationRequested, is only called when I close my SubscriptionClient, not on whether I hold the message longer than the LockDuration...So how would I abandon, defer or dead-letter a message if I don't get a trigger... – Puzzle Jul 13 '18 at 15:11
  • You don't. Receive operation doesn't take a cancellation token. There's an [issue](https://github.com/Azure/azure-service-bus-dotnet/issues/439) for that. Lock token will be eventually lost and message will become available. – Sean Feldman Jul 14 '18 at 00:12
  • In your answers first line it reads: 'You don't "cancel" a message' and in the last line "you cancel the message.". – joeystdio Aug 30 '18 at 13:29
  • Updated. Last "cancel" should have been "abandon". Thank you for catching it. – Sean Feldman Aug 30 '18 at 16:10