top of page

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.

ree


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 :

ree

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

ree

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

ree

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

ree

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


ree

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

ree

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


ree

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.

ree

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

 
 
 

Recent Posts

See All

Comments


MiIT Logo

Company

Contact Us

+1905-487-4880 

5160 Explorer Dr #34, Mississauga,ON L4W 4T7

+1929-743-3199

4466 Buttonwood Ln Lilburn, GA 30047

262 Chapman Rd, STE 240 Newark DE 19702

Stay up to date on the latest from MiIT

  • Instagram
  • Facebook
  • http://linkedin.com/company/miittechnologies/about/
  • Whatsapp

© All Content MiIT Technologies Inc.2019 - 2025. All rights reserved.

bottom of page