简体   繁体   中英

How to forward a message with exceptions to Rebus error queue

Using second-level retries in Rebus ( https://github.com/rebus-org/Rebus/wiki/Automatic-retries-and-error-handling ) I need to forward a message to an error queue after n retries.

This works:

_bus.Advanced.Routing.Send("my-queue.error",failedMessage.Message, failedMessage.Message);

But the exceptions accumulated in the failed message is not brought along, making the failed message in the error queue rather useless.

Ideally I would hook into the ITransport instance, and do something like this

await _transport.Send(errorQueueAddress, transportMessage, transactionContext);

(from PoisonQueueErrorHandler : https://github.com/rebus-org/Rebus/blob/333dbedf486acb92bd6c6250755537032c6215fd/Rebus/Retry/PoisonQueues/PoisonQueueErrorHandler.cs )

But there is no apparent way to get to that instance.

Any ideas on how to achieve this?

One way of forwarding the message to the error queue from your second level handler, is to simply throw exceptions – the usual n retries applies to 2nd level retries too, so if everything keeps failing, the message will eventually end up in the error queue.

If you really want to emulate Rebus' behavior when forwarding the message to the error queue, you can get the full error details as they would have been included by Rebus via the ErrorDescription property on IFailed<YourMessage> .

You can then create these headers when forwarding the message:

var details = failedMessage.ErrorDescription;

var headers = new Dictionary<string, string>
{
    {Headers.SourceQueue, "your-input-queue"},
    {Headers.ErrorDetails, details}
};

and then you should forward the transport message to the error queue, thus preserving message identity and all other headers completely intact:

await bus.Advanced.TransportMessage.Forward("error", headers);

I think this would be the most realistic emulation of Rebus' behavior.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM