Rémy Schumm blog ingénieur

Kafka-Emitter on Quarkus

publiziert am 11. 07. 2019 um 06:07

This is going to be a very short post: Based on the the Quarkus Kafka-Guide, I wanted to write my first little messages to a Kafka-Topic without using the reactive stream model. This info was hard to find in the dokus…

…so I decided to write this little post:

in application.properties add just another Kafka-Config, like:

## nachricht-bus topic (WRITE)

…to prepare a topic nachricht-bus, where you will write to.
Then, the Java Code gets very easy:

package ch.schumm.halloquarkus;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

import org.eclipse.microprofile.config.inject.ConfigProperty;

import io.smallrye.reactive.messaging.annotations.Emitter;
import io.smallrye.reactive.messaging.annotations.Stream;

public class HalloService {

    @Stream("nachricht-bus") // Emit on the channel 'nachricht-bus'
    Emitter<String> nachrichtEmitter;

    public String sagHallo(String name) {
        return "neuste Nachricht: " + name;

The Quarkus Kafka modules will make the rest for you. You might have to configure the property e.g. kafka.bootstrap.servers=your-kafka-boostrap-server:9092 to point to the Kafka Boostrap Servers.

zurück zum Seitenanfang