Skip to content

Preventing duplicate publishes when deferring inbound messages with second level retry #1198

@Qball1337

Description

@Qball1337

Hi, we are facing some problems when deferring a message when the exception was thrown after publishing another message:

public async Task Handle(InboundMessage message) //i am a rebus message handler 
{
        await DoWork();
        await _bus.Publish(new OutboundMessage { Body = "Hello darkness my old friend" });
        await DoMoreWork(); // throw error oeps!
}
public async Task Handle(IFailed<InboundMessage >message)
{
         await _bus.Advanced.TransportMessage.Defer(TimeSpan.FromSeconds(5));
}

The inboundMessage is placed correctly on the DLQ after the messages has been deferred (3 times in our case).
However... the Outbound message is not rolled back. Result => inbound message on the DLQ and 3 outgoing outbound messages :(

I tried the solution from this issue #1099
This is causing another error Could net get current message context! The message context can only be resolved when handling a Rebus message, and it looks like this attempt was made from somewhere else.
This is as expected because we are creating the RebusTransactionScope inside a message handler (mentioned here: #804)

Any other solution/thoughts on this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions