On one of these hot summer days, I wanted to test a Kafka service provided from the Cloud in my Java app. So, I wrote a small application in Java that creates a topic, then produces and consumes the exemplary messages.
I described my experiences and I shared the application’s code on Github — check it out: https://github.com/blumareks/BluemixTestDashboard/tree/master/GetStartedJavaMessageHub
As the result of working app you can observe how fast the application works locally or on the cloud. The example response when hitting the address:
{service: 'message-hub', operations: [
{type: 'create topic', response_time: 121, response_code: 200, desc: {'Admin REST response': 'no response - the topic has been already created'}},
{type: 'produce message', response_time: 1, response_code: 200, desc: {'Message created': 'Message produced, offset: 523'}},
{type: 'consume message', response_time: 2064, response_code: 200, desc: {'Message consumed': 'Message consumed: ConsumerRecord(topic = test-java-messagehub-topic, partition = 0, offset = 523, CreateTime = 1499458409907, serialized key size = 3, serialized value size = 25, headers = RecordHeaders(headers = [], isReadOnly = false), key = key, value = This is a test message #2)'}}
], response_code: 200, desc:'operations implemented CrPCo/CrPCoD'}
The main takeaways of this project:
- Kafka is a great way to get the open-source message oriented middleware;
- Leveraging the cloud — ie. Kafka as a service — to simplify and speed up the deployment of the applications with message oriented middleware;
- I am connecting to IBM Message Hub from IBM Liberty Java EE server;
- my choice of IBM flavor of both Kafka and the cloud works — i.e. IBM Message Hub and IBM Bluemix — since I will consume these services together with cognitive services (Watson AI services). This correlates tothe message about Lightbend and IBM creating the strong partnership in June: Announcement on Lightbend.
The process of testing the application is very simple. First, you need to fork the application from its repository on github (the link above).
Second, you need to build the application using Maven — mvn clean install
—the process is described in the detail on the readme page of the github repo.
Then, you’ll need to deploy it on a cloud (I am using IBM Bluemix, and you can visit Bluemix to get a free 30-day account). With the account, I can push the Java application to the cloud using the terminal command: cf push
And finally, I need to create and bind the Message-Hub service to the application and restage the cloud app. After that step, you can hit the address on the cloud and test the app.
I am interested in learning on how you used my code. Subscribe to my tweets: Marek Sadowski and say hello!