This service provides a REST interface to help publish a message/event to a Kafka topic.
This service depends on pre-existing Kafka infrastructure. Use the below commands to bring up all Kafka components to quickly play with the Publisher.
Download Kafka latest tarball here. Setup Kafka locally on your machine.
tar -xzf kafka_2.13-3.4.0.tgz
cd kafka_2.13-3.4.0
Note: Define your KAFKA_HOME
environment variable to the Kafka installable path on your machine.
export KAFKA_HOME="<YOUR-KAFKA-PATH>"
Start the Kafka ZooKeeper service using the below command:
${KAFKA_HOME}/bin/zookeeper-server-start.sh ${KAFKA_HOME}/config/zookeeper.properties
This will bring up the ZooKeeper on default port 2181
.
Start the Kafka Broker service using the below command:
${KAFKA_HOME}/bin/kafka-server-start.sh ${KAFKA_HOME}/config/server.properties
Create a topic called "NewTopic"
${KAFKA_HOME}/bin/kafka-topics.sh --create --replication-factor 1 --partitions 1 --topic NewTopic --bootstrap-server localhost:9092
Start a console consumer to view the messages that will be produced out of the Events service via REST interface
${KAFKA_HOME}/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic NewTopic1 --from-beginning
Bring up the service using the below command in your project directory:
./gradlew bootRun
This will start the service on default port 8080
.
Use postman to hit the publish
endpoint to publish events to Kafka topic.