问题
How to configure MassTransit to retry context.Publish()
before failing, for example when RabbitMQ server is temporary unavailable?
回答1:
The problem with retry in this context is that the only real reason a Publish
call would fail is if the broker connection was lost (for any reason: network, etc.).
In that case, the connection which was used to receive the message is also lost, meaning that another node connected to the broker may have already picked up the message. So a retry in this case would be bad, since it would reconnect to the broker and send, but then the message could not be acknowledged (since it was likely picked up on another thread/worker).
The usual course of action here is to let it fail, and when the receive endpoint reconnects, the message will be redelivered to a consumer which will then call Publish
and reach the desired outcome.
You should make sure that your consumer can handle this (search for idempotent) properly to avoid a failure causing a break in your business logic.
来源:https://stackoverflow.com/questions/44412862/how-to-configure-masstransit-to-retry-context-publish-in-case-of-failure