From within a Quarkus application I need to publish tombstone messages to a compacted Apache Kafka topic. As my use-case is imperative I use an Emitter
for sending messages to the topic (as suggested in the quarkus blog). The code for non-tombstone messages (with payload) is:
@Dependent
public class Publisher {
@Inject
@Channel("theChannelName")
Emitter<MyDataStructure> emitter;
public CompletionStage<Void> publish(final MyDataStructure myData) {
OutgoingKafkaRecordMetadata<String> metadata =
OutgoingKafkaRecordMetadata.<String>builder()
.withKey(myData.getTopicKey())
.build();
return CompletableFuture.runAsync(
() -> emitter.send(Message.of(myData).addMetadata(metadata)));
}
}
The Emitter
also implements <M extends Message<? extends T>> void send(M msg)
which I hoped would allow me to craft a Message
with payload of null
as tombstone message. Unfortunately all implementations of the Message.of(..)
factory method, that allow to provide metadata (which is needed to provide the message-key), specify that payload, must not be {@code null}.
What is the proper way (following Quarkus / SmallRye Reactive Messaging concepts) to publish tombstone messages to a Kafka topic using an Emitter
?