Message Identifier
Silverback will ensure that an x-message-id
header is always set with each message. This header is used mostly for tracing purpose and it's value is always printed in the logs generated by Silverback.
The producer will automatically generate a random Guid
to be used as message identifier. (This value will be used also as Kafka key by default, see Kafka Partitioning and Message Key.)
In the consumer side the message identifier may be used also to rebuild the chunks sequence, implement exactly once processing and similar. If the header is not present, the consumer may artificially set if with another identifier such as the Kafka key (see Kafka Partitioning and Message Key).
Custom value
It is of course possible to use a customized message identifier instead of a random Guid
, simply overriding the x-message-id
header as shown in the following snippet. More information about the message headers can be found in the Message Headers section.
using Silverback.Messaging.Messages;
namespace Sample
{
public class OrderSubmittedEvent
{
[Header(DefaultMessageHeaders.MessageId)]
public string UniqueOrderNumber { get; set; }
}
}
Note
This example assumes that only one message per each order is published to the same endpoint, because the message id should be unique in order for the various features relying on it to work properly.