top of page
Writer's picturepurav patel

publish-Subscribe Model in the command line using Apache Kafka

JMS(Java Messaging Service): JMS is an API that provides to create, send and read messages. JMS is also known as a messaging service. There are two types of messaging services. 1. Point to Point Messaging (one to one)

2. Publisher/Subscriber Messaging (one to many) Publisher/Subscriber Messaging :

In this messaging, one publisher sends the message, and other consumers which is more than one can receive the message. It is also known as broadcasting.

In real-time understanding, it is like if we subscribe to any application(i.e YouTube channel ) or news we get updates through email or notifications Topic: Here Topic behaves like a middleware or a Message broker where we can categorize the message, can define the audience(consumer) to whom we are sending the message. We can create multiple topics as needed. we can create partitions in Topic for multiple messages. For Example: On the university Website, if the professor wants to send different messages to different departments then we can categorize as per department for them into different Topics.



Now, We are going to create one JMS system using Apache Kafka and we will send and receive messages using the command line.

Kafka Architecture :

Step 1: Download Apache Kafka using the below link: unzip the file and store it on your local drive.

Step 2: Start Zookeeper using the command line : Here I am doing this for the Windows system so go to the file location where you have stored Kafka and execute below mentioned command: bin\windows\zookeeper-server-start.bat config\zookeeper.properties


Step 3: Start Kafka Server: in another tab of cmd please execute below mentioned command to start the Kafka server: bin\windows\kafka-server-start.bat config\server.properties

Step 4: Creating Topic: in the new cmd tab execute below mentioned command to create Topic: bin\windows\kafka-topics.bat --create --topic TopicName --bootstrap-server localhost:9092



Step 5: Writing Messages to Topic

In the same tab, we are writing some messages in Topic so It behaves as a producer(publisher ). Execute below mentioned command: bin\windows\kafka-console-producer.bat --topic TopicName --bootstrap-server localhost:9092


Step 6: Creating Cosumer to Receive Message: Open a new cmd tab and execute below mentioned command bin\windows\kafka-console-consumer.bat --topic TopicName --from-beginning --bootstrap-server localhost:9092


you can create multiple instances by executing the same command. Step 7:Sending message(Publishing the Message) after sending some messages, you can check consumer/subscriber instances you will automatically get messages.


For more details on Apache Kafka please check the below link: https://kafka.apache.org/quickstart

22 views0 comments

Recent Posts

See All

Battle of the Backends: Java vs Node.js

Comparing Java and Node.js involves contrasting two distinct platforms commonly used in backend development. Here’s a breakdown of their...

Comentários


bottom of page