This post describes sending Kafka events to dynamic topics in Quarkus.
Previously I suggested using the KafkaProducer, but it is pretty much obsolete since Quarkus 2, and all metadata is ignored. I ended up with serialization issues.
The solution is to use a standard Emitter and add metadata to the message. For example, this class uses a channel called reflector and routes one or more dynamic topics:

The reflector channel is initialized in the application.properties resource:
mp.messaging.outgoing.reflector.cloud-events-source=reflectorservice
mp.messaging.outgoing.reflector.connector=smallrye-kafka
mp.messaging.outgoing.reflector.value.serializer=org.apache.kafka.common.serialization.StringSerializer
mp.messaging.outgoing.reflector.cloud-events-mode=structured
mp.messaging.outgoing.reflector.cloud-events-type=reflector
The emit function simply creates metadata for the specific topic, then creates a message, adds the metadata, and sends it via the emitter.
I hope this post may be useful.
Hi, where is the interface Reflector?, best regards!!
LikeLiked by 1 person
Hi Antonio, oh that interface that is not framework related. That’s just our own abstraction, depending upon the event received we use different reflectors. This class handles general events, we use another for ingested web metrics etc.
LikeLiked by 1 person