Apache Kafka Broadcasting Pub/Sub Pattern with Mule4 Part3

Rachana M
3 min readOct 18, 2022

--

<SimplePubSubPattern><CompetingPattern>

In Broadcasting pattern, a producer produces message to topic and any number of consumers can consume the message.

Why Do we need Broadcasting pub/sub pattern?

For example, we placed an order in an online app, we will immediately receive order confirmed message, but at the backend our order is published to topic which will be consumed by the dealer/seller and other sources inside the network of app to track the ordered items. Hence Broadcasting of message (i,e. order) is happening in this scenario.

Uses Case for Demo (Video) Broadcasting Pattern

Broadcasting pattern

Here Producer produces message to topic, and it's consumed by both ConsumerA and ConsumerB

Demo To create Free Kafka with Confluent Cloud

please follow the steps in Video if you don’t have Kafka in handy for demo, where you can create Kafka topic with Confluent. Based on the link I have created Kafka cloud account for bootstrap server, username and password for my publish and consume connectors.

Anypoint Studio Flow

Studio flow for Broadcasting Pattern

point to remember in while achieving the above pattern, both Message listeners should have different Consumer Configuration but should listen to same topic.

(1) Configure message to publish to kafka

message to publish

(2) Configuration to Publish Message to Kafka

topic Name: topic_1

Publish Kafka Configuration

Consumer-A flow

(3a) Once Message is published Successfully, we can Consume the Message as below

topic: topic_1

Message Listener Configuration in Consumer-A flow

(3b) After Listening from Message Listener, we can consume as below.

Consume payload in Consumer-A flow

Consumer-B flow

(4a) Once Message is published Successfully, we can Consume the Message as below

topic: topic_1

Message Listener Configuration in Consumer-B flow

(4b) After Listening from Message Listener, we can consume as below.

Consume payload in Consumer-B flow

Logger to log in console

logger in Flow

Response After consumed

Response

Youtube Links:

Demo on Apache Kafka Pub/Sub Broadcasting pattern with Mule4

Demo To create Free Kafka with Confluent Cloud

clonfluentPage for more information

For the above example please refer my git Repo

git repo: racs07/demo-kafka (github.com)

git-clone: https://github.com/racs07/demo-kafka.git

--

--

Rachana M

3x Certified MuleSoft Developer | MCD, MCPA,MCIA | Mulesoft Mentor| New to Blogs writing