Message Identity

Component: NServiceBus
Standard support for version 5.x of NServiceBus has expired. For more information see our Support Policy.

Each message that is dispatched from an Endpoint has a unique identity. NServiceBus generates and stores this value as a header on the message named NServiceBus.MessageId.

Many features take advantage of message identity. For example, the Outbox uses message identity to deduplicate messages and recoverability uses message identity to keep track of how many times the endpoint has tried to process a message.

Specifying message identity

Message identity can be explicitly specified, overriding the default identity provided by NServiceBus.

It is important that the strategy used to generate message identities results in globally unique identifiers. If two messages ever have the same identity then some features will treat them as the same message. This will cause errors which are difficult to diagnose.

Message identity can be set by manipulating the NServiceBus.MessageId header in an Outgoing Message Mutator.

public class MessageIdFromMessageMutator :
    IBus bus;

    public MessageIdFromMessageMutator(IBus bus)
        this.bus = bus;

    public object MutateOutgoing(object message)
            msg: message,
            key: "NServiceBus.MessageId",
            value: GenerateIdForMessage(message));
        return message;

Last modified