Use AsyncEventHandler<MessagingEvent> for consumer message handling - #45
Merged
Merged
Conversation
Convert the consumer's ConsumeAsync callback from the synchronous EventHandler<IMessagingEvent> to RabbitMQ's AsyncEventHandler<MessagingEvent>, awaited inside ReceivedAsync. MessagingEvent moves into the MerQure project and derives from AsyncEventArgs so it satisfies the delegate constraint. Serialization switches from a lock to a SemaphoreSlim to allow awaiting.
Poltuu
approved these changes
Jun 9, 2026
Poltuu
left a comment
There was a problem hiding this comment.
j'avoue je maitrise pas les tenants et aboutissants
| /// </summary> | ||
| /// <param name="onMessageReceived">Handler called each time a message arrives for this consumer.</param> | ||
| Task ConsumeAsync(EventHandler<IMessagingEvent> onMessageReceived); | ||
| Task ConsumeAsync(AsyncEventHandler<MessagingEvent> onMessageReceived); |
There was a problem hiding this comment.
breaking mais j'imagine que c'est pas grave ?
Contributor
Author
There was a problem hiding this comment.
C'est justement le but même. J'avais oublié cet usage lors de la release précédente donc on se retrouve avec du sync over async en Consumer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Converts the consumer's
ConsumeAsynccallback from the synchronousEventHandler<IMessagingEvent>to RabbitMQ'sAsyncEventHandler<MessagingEvent>, awaited insideReceivedAsync— so message handlers can do real async work instead of being run synchronously.Changes
MerQure.RbMQ/Clients/Consumer.cs—ConsumeAsynctakesAsyncEventHandler<MessagingEvent>andawaits it inside the now-asyncReceivedAsynchandler. Serialization switches fromlocktoSemaphoreSlim(1,1)(also inStopConsuming) since you can'tawaitinside alock.MerQure/Events/MessagingEvent.cs(new, public) — moved out ofMerQure.RbMQand now derives fromAsyncEventArgsso it satisfies thewhere TEvent : AsyncEventArgsconstraint on RabbitMQ's delegate.MerQure.RbMQ/Events/MessagingEvent.cs— deleted (the internal version).MerQure/Clients/IConsumer.cs— interface signature updated.MerQure.Tools/Buses/Consumer.cs— caller lambda returnsTask.CompletedTask.tests/MerQure.Tools.Tests/Buses/ConsumerTests.cs— stub updated to the new delegate type.samples/— example handlers return the ack/nackTaskto match the async signature.Note
MessagingEventnow leaks a RabbitMQ.Client base type (AsyncEventArgs) into theMerQureabstraction layer. This was a deliberate choice to use RabbitMQ'sAsyncEventHandler<T>directly rather than aFunc<object, IMessagingEvent, Task>.Testing
dotnet test— 29 passed, 0 failed.