1. Java
  2. Tutorial

Consume Messages

From another terminal, run the following command to run the consumer application which will read the events from the purchases topic and write the information to the terminal.

java -cp build/libs/kafka-java-getting-started-0.0.1.jar io.streamnative.developer.ConsumerExample

The consumer application will start and print any events it has not yet consumed and then wait for more events to arrive. On startup of the consumer, you should see output resembling this:

Consumed event from topic purchases: key = awalther   value = book
Consumed event from topic purchases: key = htanaka    value = book
Consumed event from topic purchases: key = sgarcia    value = gift card
Consumed event from topic purchases: key = sgarcia    value = t-shirts
Consumed event from topic purchases: key = sgarcia    value = gift card
Consumed event from topic purchases: key = sgarcia    value = book
Consumed event from topic purchases: key = sgarcia    value = gift card
Consumed event from topic purchases: key = sgarcia    value = t-shirts
Consumed event from topic purchases: key = sgarcia    value = batteries
Consumed event from topic purchases: key = htanaka    value = batteries
Consumed event from topic purchases: key = htanaka    value = book
Consumed event from topic purchases: key = awalther   value = book
Consumed event from topic purchases: key = htanaka    value = t-shirts
Consumed event from topic purchases: key = awalther   value = alarm clock
Consumed event from topic purchases: key = htanaka    value = alarm clock
Consumed event from topic purchases: key = sgarcia    value = gift card
Consumed event from topic purchases: key = sgarcia    value = t-shirts
Consumed event from topic purchases: key = sgarcia    value = book

Rerun the producer to see more events, or feel free to modify the code as necessary to create more or different events.

Once you are done, enter Ctrl-C to terminate the consumer application.

Previous
Produce Messages