Tombstone Message
A tombstone message is a message with a null body, used to indicate that the record has been deleted. This technique is for example used with Kafka topics compaction, to get rid of obsolete records.
Consumer
Silverback maps by default the messages with a null body to a Tombstone or Tombstone<TMessage>. This behavior can be changed using the SkipNullMessages or UseLegacyNullMessageHandling of the IConsumerEndpointBuilder<TBuilder>, or setting the NullMessageHandlingStrategy property of the ConsumerEndpoint).
The Tombstone/Tombstone<TMessage> message exposes a single property containing the message identifier.
public class MyEndpointsConfigurator : IEndpointsConfigurator
{
public void Configure(IEndpointsConfigurationBuilder builder) =>
builder
.AddKafkaEndpoints(endpoints => endpoints
.Configure(config =>
{
config.BootstrapServers = "PLAINTEXT://kafka:9092";
})
.AddInbound(endpoint => endpoint
.ConsumeFrom("catalog-events")
.Configure(config =>
{
config.GroupId = "my-consumer";
})
.DeserializeJson(serializer => serializer
.UseFixedType<Product>())));
}
Important
In order to create a typed Tombstone<TMessage> it is required that either the consumed message declares the x-message-type header or a fixed type deserializer is used (as shown in the example above). Otherwise the null message will be mapped to a simple Tombstone.
Producer
A Tombstone<TMessage> (or Tombstone) can also be used to produce a null message.
public class MyEndpointsConfigurator : IEndpointsConfigurator
{
public void Configure(IEndpointsConfigurationBuilder builder) =>
builder
.AddKafkaEndpoints(endpoints => endpoints
.Configure(config =>
{
config.BootstrapServers = "PLAINTEXT://kafka:9092";
})
.AddOutbound<Product>(endpoint => endpoint
.ProduceTo("catalog-events")));
}
Note
The Tombstone<TMessage> messages are routed according to the type parameter TMessage. This means that they will be published to the outbound endpoints papped to the same TMessage (Product in the above example), as well as to the outbound endpoints explicitly mapping Tombstone.