Integrating Redis with a Helidon MicroProfile Application for a Publish-Subscribe Usecase

Redis is an open source, in-memory data structure store, used as a database, cache and message broker. In this short post I am sharing a simple application that show cases classic integration of Redis message broker(pub/sub) APIs with a Helidon MicroProfile application for message publish-subscribe use case. You can checkout the source form here: https://github.com/jobinesh/cloud-native-applications/blob/master/helidon-example-mp-redis/README.md

What is the usecase exercised in this example ?
It is simple :) We use the a simple greeting REST API  to exercise the Redis Publish Subscribe feature. When a client updates the greeting message, the Greeting resource implementation will publish the new greeting message to Redis channel topic for use by interested parties(consumers)

Who does what?
Here is quick summary of the classes that you find in the source:

  • Lettuce: This example use Lettuce client library to connect to Redis server. If you are new to Lettuce, take a look at the following resources to get a feel of the offerings:
  • RedisMessageConsumer: This class contains the logic for listening to the Redis channel. This class uses a custom annotation '@Startup' so that it gets instantiated on application start up. The annotation '@Startup' is provided by io.helidon.examples.mp.spi.StartupInitializerExtension class in this project. To learn more about this extension, read section '16.1. Creating an Extension' in https://docs.jboss.org/weld/reference/latest/en-US/html/extend.html
  • RedisMessageProducer: This class contains the logic for publishing messages to the Redis channel. It is used by GreetResource class.
  • GreetResource: This is the REST resource implementation used in this example. When updateGreeting method is called via REST PUT operation, the new greeting sent by client is sent to Redis channel for consumption by the consumers.  See the method updateGreeting() in GreetResource class to learn the usage of RedisMessageProducer class in order to publish message to channel.
  • microprofile-config.properties: This config file holds the Redis configuration used in this example
How to run this example?
All instructions are available here: https://github.com/jobinesh/cloud-native-applications/blob/master/helidon-example-mp-redis/README.md. Have fun !


Comments

  1. Thank you for sharing wonderful information with us to get some idea about it.
    Microservices Online Training
    Microservices Training in Hyderabad

    ReplyDelete
  2. Apparently, this blog is awesome. I like the given information. Keep Updating…
    Linux VPS Hosting

    ReplyDelete
  3. Thanks for such a great article here. I was searching for something like this for quite a long time and at last I’ve found it on your blog Visit Germany VPS Hosting

    ReplyDelete

Post a Comment

Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of my employer.