We have updated the Message Hub samples we provide on Github: https://github.com/ibm-messaging/message-hub-samples.

In this repository, we have examples how to use the 3 APIs Message Hub supports:

  • Kafka: in Java, Node.js
  • MQ Light: in Java, Node.js, Ruby and Python
  • REST: in Node.js

Kafka best practices

We’ve rewritten the Java console sample (now called kafka-java-console-sample) to show the best practices for implementing a fault tolerant Kafka application. It demonstrates how to:

  • Produce messages with broker acknowledgment
  • Consume messages
  • Check topic status: existence, replication
  • Handle faults and retry logic
  • Create and list topics using the Message Hub Admin REST API

Note: This sample is not made to demonstrate maximum throughput but instead has flow control (sends messages 1 by 1 and sleeps) to make the output easily understandable. For maximum throughput and other use cases, consult the Kafka API.

New Node.js Kafka Sample

Also as part of this update, we’ve added a new sample called kafka-nodejs-console-sample to show how to use the Kafka API from Node.js. This sample is using the node-rdkafka client. The project is set up to be able to run both locally and in Bluemix as detailed in this previous post and has the same features than the Java sample. This sample however only works on macOS and Linux as these are the only platforms supported by node-rdkafka.

Next steps

We encourage you to have a look and try these samples on Bluemix. If you have any issues, ask us a question on StackOverflow.com using the message-hub tag. Additionally, let us know if you’d like to see more use cases or languages covered by our samples.

Join The Discussion

Your email address will not be published.