Message Id strategy

Component: RabbitMQ Transport
NuGet Package NServiceBus.RabbitMQ (5.x)
Target NServiceBus Version: 7.x

By default, the message-id property of the AMQP standard is used to relay the message identity. If this property isn't set, the transport will throw an exception because NServiceBus requires a message identity to perform retries, de-duplication, etc., in a safe way.

For integration scenarios where the sender is not controlled, the receiver might need to employ a custom strategy that extracts a message identity from a custom header or part of the message body. This custom strategy can be configured by calling:

var transport = endpointConfiguration.UseTransport<RabbitMQTransport>();
transport.CustomMessageIdStrategy(
    customIdStrategy: deliveryArgs =>
    {
        var headers = deliveryArgs.BasicProperties.Headers;
        return headers["MyCustomId"].ToString();
    });
It is extremely important that the custom strategy is deterministic (it returns the same value when invoked multiple times for the same message), and that no two messages are assigned the same value.

Related Articles


Last modified