Develop consumers and producers in Java

Continue your Apache Kafka journey by developing consumers and producers in Java to stream data using Red Hat OpenShift Streams for Apache Kafka.

Overview: Develop consumers and producers in Java

What to expect

In this tutorial, we are going to develop an example where one service is a producer, sending song descriptions to the songs-catalog topic, and another service consumes these song descriptions. 

In a real-world scenario, the consumer would take the songs and process them (i.e., storing them in a graph database such as Neo4j, or an Elasticsearch instance for searching capabilities), but for the sake of simplicity, in this case, the service prints them in the console (Figure 20).

 

The consumer shows that the broker successfully distributed messages by printing them.
Figure 20: The consumer shows that the broker successfully distributed messages by printing them.

 

Before continuing this learning path, please verify that you have the following tools installed in your development environment:

  • Java JDK 11+
  • Git 2.30+
  • Maven 3.8.3+

You will need to open four terminal windows to run this example: two terminals for running the services and two for sending requests to the services.