Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Use AsyncEventingBasicConsumer in RabbitMQ #987

Merged
merged 1 commit into from
Apr 2, 2019

Conversation

mvelosop
Copy link
Collaborator

@mvelosop mvelosop commented Apr 2, 2019

Use AsyncEventingBasicConsumer instead of EventingBasicConsumer 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:

image

When placing the above order, the Ordering.API microservice aborts, as can be seen in the following images:

image

Processing just stops and alerts fire in health checks:

image

And the message gets stuck in the queue:

image

After applying the changes,

The exception is catched, logged and ignored as suggested in RabbitMQ's documentation:

image

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] EventBusRabbitMQ Message Processing Problem
1 participant