Illustrates a simple example how to produce and consume messages.
- Kafka
- maven
- Java >=8 (best: Openjdk)
- IDE (e.g. Eclipse, ...)
Before executing you need to add kafka and zookeeper to your OS hosts-file. Here is a list of hosts-file locations according to your operating systems
- Mac OS: /private/etc/hosts
- Linux: /etc/hosts
- Windows: C:\Windows\System32\drivers\etc\hosts
The format may vary a little but usually a new host with its hostname is defined using it's ip and the desired hostname. Thus, your host file needs to have the following entries:
127.0.0.1 kafka
127.0.0.1 zookeeper
Be aware that for some Operating Systems you might need to restart your network service or restart your computer. You may check if the entries are active by just pining with ping kafka
and ping zookeeper
, which should give you a response from 127.0.0.1.
To build the project execute:
mvn clean install
To run a consumer:
mvn exec:java@consumer
To run the producer:
mvn exec:java@producer