0

I am wondering if it is possible to send real time user notifications to an angular client from spring kafka backend, my approach was to send it through the kafka topics instead of using websocket STOMP, and create a topic for each user, and in someway the angular subscribes to the current logged in user topic and listen to their notifications, I tried to look for a kafka client library for the angular client but I didn't find anything useful, my best shot was a library that is 10 years old and I honestly don't trust an out of date library to do the job. Thank you

2 Answers2

1

Kafka isn't a frontend technology such that a client side JS library exists, and doesn't push events.

You can make your kafka consumer application do anything you want, such as send GCM/APNS messages, or forward data to some other system that is responsible for sending such notifications. But "one topic per user" is generally an anti pattern with Kafka since the brokers do have a limit on number of topics they support, but your userbase might grow indefinitely.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • Yes you are right.. I was thinking that the topic per user is not going to be efficient as the database grows.. I mean can you please suggest a better approach.. and about the client side.. I wonder if using a websocket would solve the problem and could the websocket subscribes to the kafka topic or should i add websocket configuration to my backend – Ghassen Jemaî May 21 '23 at 16:20
  • 1
    As mentioned, Kafka isn't a frontend technology. It doesn't offer websockets out of the box – OneCricketeer May 22 '23 at 13:23
  • 1
    yes true, I could finally do that in with SSE since notifications are one way communication, wasn't really necessary for us to integrate websockets since we only needed one way real time communication.. thank you both for the explanation – Ghassen Jemaî May 22 '23 at 13:32
0

We used Server-Sent Events (SSE) for one-way real-time communication between the frontend and backend. SSE allows the backend to send updates or notifications to the frontend without the need for the frontend to explicitly request them. This was suitable for our requirements in providing real-time notifications to the users.

On the other hand, Kafka is employed for real-time communication between microservices within the system. It serves as a message broker, enabling the exchange of messages and updates between different microservices. In our architecture, the Notification microservice is responsible for handling the sending of notifications based on the events or messages received from other microservices via Kafka.

In summary, SSE facilitates real-time communication between the frontend and backend, while Kafka facilitates real-time communication and messaging between microservices. By utilizing both SSE and Kafka, we can ensure efficient and reliable real-time communication at both the frontend-backend and microservice levels in our system.

  • Ghassen Jemaî - Your five answers in May all appear likely to be entirely or partially written by AI (e.g., ChatGPT). Please be aware that [posting AI-generated content is not allowed here](//meta.stackoverflow.com/q/421831). If you used an AI tool to assist with any answer, I would encourage you to delete it. We do hope you'll stick around and be a valuable part of our community by posting *your own* quality content. Thanks! – NotTheDr01ds Jul 13 '23 at 16:52