Zuda Pradana Putra
1 min readJul 1, 2024

1. Production Message:

First, the message data (ChatMessage) will be sent to the Kafka topic (public-chats) using KafkaProducerServices.

The sendMessage method in KafkaProducerServices will send the message to Kafka.

2. Message Consume:

Once a message is sent to Kafka, KafkaConsumerServices will listen to the same topic (public-chats) and consume the incoming message.

Received messages are logged, added to the in-memory message list (chatMessages), and sent to WebSocket clients subscribed to /topic/public.

3. API to Retrieve Messages:

The /api/chat API endpoint will call the getChatMessages method of KafkaConsumerServices to retrieve the list of messages stored in memory.

These messages will then be returned as API responses.

With this explanation, you have an idea of ​​how messages are sent and received using Kafka, how messages are stored in temporary memory, and why this approach is chosen for simple projects. In production, it is common to use databases to store messages to ensure data persists and can be managed properly.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Zuda Pradana Putra
Zuda Pradana Putra

No responses yet

Write a response