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] Optionally include IConsumerContext and/or CancellationToken in consumer method invocation #224

Closed EtherZa closed 5 months ago

EtherZa commented 5 months ago

Added support for optionally including IConsumerContext and/or the CancellationToken in the consumer method invocation when supplying a type and method name.

As the CancellationToken is tied to the life of the message lock, it should be readily available in the method to prematurely terminate processing when the lock is lost.

Supplying the IConsumerContext as an argument, as opposed to constructor or setting injection, allows for a single consumer instance where appropriate.

public class SomeConsumer
{
  public async Task MyHandleMethod(SomeMessage msg, IConsumerContext consumerContext, CancellationToken cancellationToken)
  {
    // handle the msg
  }
}

Please note that the order of the parameters is not important.


IConsumer and IRequestHandler have not been modified so as to avoid creating a breaking change. Implementation would be trivial should there be appetite to change the signatures.

Though not direct solutions to #220 and #223, the submission addresses both issues for non-IConsumer/IRequestHandler implementations.

EtherZa commented 5 months ago

@zarusz there appears to be an issue with the SonarCloud secret

 The format of the analysis property sonar.token= is invalid
zarusz commented 5 months ago

Yes, I believe secrets are not passed to branch builds which are from external repo clones. I will have a look when I get a chance.

zarusz commented 5 months ago

@EtherZa I've changed the actions workflow some on master, can you please rebase your changes and push again?

zarusz commented 5 months ago

@EtherZa can you please rebase against master once more and ideally squash all your changes into 1 commit? I am trying to tweak the build workflow so that SonarCloud and secrets for integration test infra are shared for PR coming from cloned repos. Unfortunately, that might require a couple of back and forth to get right.

I have looked at your changes - looks good!

EtherZa commented 5 months ago

@zarusz - No worries, I've rebased, squashed and pushed.

zarusz commented 5 months ago

@EtherZa can you rebase once more? I've pushed some more tweaks to build workflow.

I see that sonar cloud integrates nicely already.

After that I am happy to merge.

EtherZa commented 5 months ago

Rebased and pushed without the unused variable.

EtherZa commented 5 months ago

Both SonarCloud issues resolved and pushed.

sonarcloud[bot] commented 5 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
91.3% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

zarusz commented 5 months ago

This is now merged. Thanks for your contribution @EtherZa! I will add this to the upcoming 2.3.0 release (soon).

EtherZa commented 5 months ago

Thank you!