Reading from Kafka
The next step is to read individual raw messages from the Kafka topic, raw-messages. In Kafka jargon, a consumer is needed. In the last chapter, we used the command-line tools to write events to a topic and to read events back to the topic. This recipe shows how to write a Kafka consumer in Java using the Kafka library.
Getting ready
The execution of the previous recipes in this chapter is needed.
How to do it...
- Create a file called
Consumer.java
in thesrc/main/java/doubloon/
directory with the following code:
package doubloon; import java.util.Properties; import org.apache.kafka.clients.consumer.ConsumerRecords; public interface Consumer { public static Properties createConfig(String servers, String groupId) { Properties props = new Properties(); props.put("bootstrap.servers", servers); props.put("group.id", groupId); props.put("enable.auto.commit", "true"); props.put("auto.commit.interval.ms", "1000"); props.put("auto...