Notification service(Routing incoming Kafka messages to web socket)
There might be a need of propagating the messages received by an application on a Kafka topic to the clients using Websocket. Since, websockets receive messages without the need of refreshing the page. This use case fits well if we want to enable real time notifications in our application.
- Clone the repo https://github.com/amitdhodi/notification-service.git and download the code locally
- Import the project as Maven project in your IDE
- Download(if not done) and start local Kafka cluster. Reference link to do the same(http://kafka.apache.org/quickstart). Only perform Step 1(Download the code) & 2(Start the server) using the above link.
- Start the application by running NotificationApplication.java
- Application will start on port 8080. Once it is up, browse URL http://localhost:8080
- This would render an empty text area.
- Send message to kafka topic "inbound". Either Kafka Tool can be used (http://www.kafkatool.com/download.html) or command line producer can be used to send the message. The message json format is:
{
"firstName":"foo",
"lastName":"bar"
}
- Once the message is posted successfully, the URL http://localhost:8080 must reflect the json message inside the text area without the need of refreshing the page.
- This shows the real time notifications on browser originated by a kafka message.