In this post we will show you a small demo using this Kafka workitem. As usual this demo is based on the jBPM business applications which you can easily generate on start.jbpm.org.
You can find the source of the demo and detailed descriptions on how to set it up and get it up and running on github.
The demo app uses a simple business process that retrieves current weather information from openweathermap.org and sends it to the Kafka workitem so that this info can be sent to a Kafka topic.
The business Spring Boot app uses the Spring-kafka integration and defines a Kafka consumer configuration as well as the Spring WebSocket support to setup a WebSocket config. Kafka messages that are consumed by our business app are then being broadcasted to a websocket endpoint and picked up by our UI (via sockjs and stomp). This way our UI can dynamically update the weather info display without any page refreshes needed.
Here is the definition of the demo business app Kafka consumer. Take a look at its consume method, which simply receives the Kafka message and sends it to a WebSocket endpoint, and here is the JavaScript setup which listens to the same WebSocket endpoint and updates the weather chart once new info is received.
Here is the demo walkthrough video where we explain the demo in detail, show the code, and run the demo.
Hope this demo gives you some ideas on how to create your own cool jBPM Business App using Apache Kafka.
Many thanks to Prasanth for his contribution!