silverback icon indicating copy to clipboard operation
silverback copied to clipboard

Add CancellationToken to IPublisher methods

Open BEagle1984 opened this issue 3 years ago • 1 comments

Task IPublisher.PublishAsync(object, CancellationToken)

The cancellation token would be passed to the subscribing methods that could declare an additional parameter of type CancellationToken.

public Task OnMessageReceived(MyCommand command, CancellationToken cancellationToken) { ... }

The mechanism could be used by the consumer as well, to signal the subscribers that the broker is disconnecting (maybe because the application is exiting) and the pending operations should be aborted.

(Thank you @mjeanrichard for the input.)

BEagle1984 avatar Jan 21 '21 09:01 BEagle1984

Furthermore this CancellationToken could be forwarded to the Producer as well, to cancel the pending produce operation.

BEagle1984 avatar Feb 18 '21 12:02 BEagle1984