DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Trending

  • How the Go Runtime Preempts Goroutines for Efficient Concurrency
  • Transforming AI-Driven Data Analytics with DeepSeek: A New Era of Intelligent Insights
  • Why High-Performance AI/ML Is Essential in Modern Cybersecurity
  • Docker Model Runner: Streamlining AI Deployment for Developers

Kafka Event Exchange Between Local and Azure

Learn about a simple set-up involving a local machine and Azure VM, and see the step-by-step procedure to produce events from the local machine to Kafka broker.

By 
Praful Khandelwal user avatar
Praful Khandelwal
·
Apr. 08, 22 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
4.7K Views

Join the DZone community and get the full member experience.

Join For Free

While it may not be a daunting task to set up Kafka on a local machine or within a particular network and produce/consume messages, people do face challenges when they try to make it work across the network.

Let’s consider a hybrid scenario where your software solution is distributed across two different platforms (say AWS and Azure or on-premise and Azure), and there is a need to route messages from Kafka cluster hosted on one platform to the one hosted on another. This could be a valid business scenario wherein you are trying to consolidate your solution with one cloud platform, and in the interim, you need to have this routing in place till you complete your migration. Even in the long term, there may be a need to maintain solution across multiple platforms for various business and technical reasons.

In this article, we will be talking about a simple set-up involving local machine (macOS) and Azure VM. We’ll discuss the step-by-step procedure to produce events from local machine to Kafka broker hosted on Azure VM and also to consume those events back in local machine. While this does not cover the exact scenario described above, it gives a fair idea about how the Kafka messages can be exchanged across the network.

Prerequisites

  • Azure VM with Ubuntu server
  • MacOS machine with Homebrew installed

Setting up Kafka on Azure VM

Update packages.

$ apt-get update


Install Java.

$ apt install default-jdk


Download Kafka.

$ wget https://downloads.apache.org/kafka/3.1.0/kafka_2.13-3.1.0.tgz


Unzip the downloaded file.

$ tar -xzf kafka_2.13–3.1.0.tgz


Change directory to kafka_2.13–3.1.0.

$ cd kafka_2.13–3.1.0


Start ZooKeeper service (in terminal 1).

$ bin/zookeeper-server-start.sh config/zookeeper.properties


Start Kafka broker service (in terminal 2).

$ bin/kafka-server-start.sh config/server.properties


Create a topic (in terminal 3).

$ bin/kafka-topics.sh --create --topic azure-events --bootstrap-server localhost:9092


Start Kafka producer (in terminal 3) and write events to the above topic.

$ bin/kafka-console-producer.sh --topic azure-events --bootstrap-server localhost:9092


Start Kafka consumer (in terminal 4) and read events from the above topic.

$ bin/kafka-console-consumer.sh --topic azure-events --from-beginning --bootstrap-server localhost:9092


If we are able to produce and consume the events seamlessly on Azure VM, that means the above set-up is successful and we can move on.

Setting up Kafka on Local Machine (macOS)

Install Java.

$ brew cask install java


Install Kafka.

$ brew install kafka


Start ZooKeeper service (in terminal 1).

$ zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties


Start Kafka broker service (in terminal 2).

$ kafka-server-start /usr/local/etc/kafka/server.properties


Create a topic (in terminal 3).

$ kafka-topics --create --topic local-events --bootstrap-server localhost:9092


Start Kafka producer (in terminal 3) and write events to the above topic.

$ kafka-console-producer --topic local-events --bootstrap-server localhost:9092


Start Kafka consumer (in terminal 4) and read events from the above topic.

$ kafka-console-consumer --topic local-events --from-beginning --bootstrap-server localhost:9092


If you are able to produce and consume the events seamlessly on local machine, that means the above set-up is successful and we can move on.

Connecting Local Machine To Azure VM To Exchange Kafka Messages

Open port 9092 on Azure VM by creating inbound security rule. This can be done through the Azure portal under the networking settings of VM.

Go to /usr/local/etc/kafka/server.properties file on the local machine. Uncomment and update advertised listeners. Add Azure VM public IP address in place of your.host.name:

advertised.listeners=PLAINTEXT://your.host.name:9092)


Restart ZooKeeper service on the local machine (in terminal 1).

$ zookeeper-server-start /usr/local/etc/kafka/zookeeper.properties


Restart Kafka broker service on the local machine (in terminal 2).

$ kafka-server-start /usr/local/etc/kafka/server.properties


Restart Kafka producer (in terminal 3), but write events to Kafka topic on Azure VM this time instead of local Kafka topic. Also, use Azure VM Public IP instead of localhost.

$ kafka-console-producer --topic azure-events --bootstrap-server <Azure VM Public IP>:9092


Restart Kafka consumer (in terminal 4), but read events from Kafka topic on Azure VM this time instead of local Kafka topic. Also, use Azure VM Public IP instead of localhost.

$ kafka-console-consumer --topic azure-events --from-beginning --bootstrap-server <Azure VM Public IP>:9092


Make sure ZooKeeper and Kafka broker services are still running on Azure VM as usual. If you are able to produce and consume the events seamlessly, that means the above set-up is successful.

This brings us to the end of this article. While Azure VM with Ubuntu server and local machine with macOS has been considered here, a similar exercise can be tried out with any other Linux flavor on Azure VM and Windows OS on local machine. In that case, the commands will be a little different.

Published at DZone with permission of Praful Khandelwal. See the original article here.

Opinions expressed by DZone contributors are their own.

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!