This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
Use AsyncEventingBasicConsumer in RabbitMQ #987
Merged
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.
Use
AsyncEventingBasicConsumer
instead ofEventingBasicConsumer
to properly use async event handlers on consumers.Taken from http://gigi.nullneuron.net/gigilabs/asynchronous-rabbitmq-consumers-in-net/
Closes #888.
As detected by @falamarzijahromi, the previous implementation was using async event handlers with
EventingBasicConsumer
(which isn't async) and this causes possible out-of-order message handling and improper exception handling. This is also explained in the above article.Even though the ordering issue doesn't seem to affect eShopOnContainers it was fixed because it's not adecuate to synchronously call async event handlers.
However, the exception handling does affect the services, as will be shown next.
To create this situation you can now force an exception in the consumer, by including the text
throw-fake-exception
somewhere in the message, like this:When placing the above order, the Ordering.API microservice aborts, as can be seen in the following images:
Processing just stops and alerts fire in health checks:
And the message gets stuck in the queue:
After applying the changes,
The exception is catched, logged and ignored as suggested in RabbitMQ's documentation:
NOTE: In a real-world application this situation should probably be handled with a Dead Letter eXchange (DLX).
After the error the service is still working and can process another order.