Skip to main content

Using Kafka

Features

Kafka is a popular publish-subscribe messaging system. JHipster has an optional support for Kafka, that will:

  • Configure Kafka clients with JHipster.
  • Add the necessary configuration in the application-*.yml
  • Generate a Docker Compose configuration file, so Kafka is usable by typing
    docker-compose -f src/main/docker/kafka.yml up -d

Prerequisite

Generate a new application and make sure to select Asynchronous messages using Apache Kafka when prompted for technologies you would like to use. A Docker Compose configuration file is generated and you can start Kafka with the command:

docker-compose -f src/main/docker/kafka.yml up -d

Consumer and Producer

A consumer (<appName>KafkaConsumer class) is running and can be adapted to your needs.

A producer (<appName>KafkaProducer class) is also available and can be called through a REST endpoint (<appName>KafkaResource class).

Running the app

Allow access to the endpoint in SecurityConfiguration.java:

.antMatchers("/api/<appName>-kafka/publish").permitAll()

If you invoke the endpoint http://localhost:8080/api/<appName>-kafka/publish?message=..., you should see the message logged to the console.