zarusz / SlimMessageBus

Lightweight message bus interface for .NET (pub/sub and request-response) with transport plugins for popular message brokers.
Apache License 2.0
467 stars 78 forks source link

[Host] CancellationToken is not included as an OnHandle method paramter #223

Closed EtherZa closed 5 months ago

EtherZa commented 5 months ago

Neither IConsumer nor IRequestHandler include the CancellationToken associated with the message context as a method parameter.

It is accessible via IConsumerContext injection, but the implementation is not ideal as it breaks the facade of isolation from the message broker. Using setter injection also negates the ability to use a single consumer instance for concurrent processing.

zarusz commented 5 months ago

I agree in general, it would be better to have CancellationToken added as part of the consumer method.

There could also be an improvement added for concurrent consumers (.Instances(N) where N > 1) where the message processing pipeline would create N per-message scopes, rather than 1 nowadays.

In the long run, I was considering adding CancellationToken to the consumer methods in the future SMB v3. This perhaps would result in a breaking change to IConsumer<T>, or an additional interface that could be used.

I saw you have the PR for this feature using the consumer without the interface, which is a good middle-ground before v3.

zarusz commented 5 months ago

Closed via #224