Publish failure event when a message is moved to the error queue

Hi Sean, you have a few options here:

  1. You can subscribe to the OnMessageSentToErrorQueue event and send/publish from there.
    var endpointConfiguration = new EndpointConfiguration("MyEndpoint");
    endpointConfiguration.UseTransport<LearningTransport>();

    IMessageSession messageSession = null;

    endpointConfiguration.Recoverability().Delayed(s => s.NumberOfRetries(0));
    endpointConfiguration.Recoverability()
        .Failed(s => s.OnMessageSentToErrorQueue(fm =>
    {
        var options = new SendOptions();

        options.RequiredImmediateDispatch();//to make sure the send operation doesn't participate in the receive transaction
        options.SetDestination("SomeOtherEndpoint");
        return messageSession.Send(new ReportThatMessageFailed
        {
            Reason = fm.Exception.Message
        }, options);
    }));

    messageSession = await Endpoint.Start(endpointConfiguration)
        .ConfigureAwait(false);

Note the call to RequiredImmediateDispatch to make sure that the operation doesn’t enlist in the current receive transaction to make sure that it gets sent our no matter what.

  1. Subscribe to the MessageFailed event from ServiceControl, see Using ServiceControl Events • ServiceControl Contracts • Particular Docs

  2. Depending on the business requirements potentially use a saga to control the retry behaviour and report various statuses back to other endpoints. See Sagas • NServiceBus • Particular Docs

Can you share some more details on why you need to report that the message was moved to the error queue to other endpoints?

Cheers,

Andreas