The publish/subscribe messaging pattern
Redis also includes an implementation of the publish/subscribe messaging pattern. This section demonstrates how we can use Spring Data Redis for the purpose of sending and receiving messages. As an example, we will modify the CRUD application that stores the contact information as JSON to send notifications when a new contact is added, contact information is updated, and a contact is deleted.
We can implement this requirement by performing the following steps:
Create message listeners that process the received messages.
Configure the application context of our application.
Send messages by using the
RedisTemplate
class.
This section also describes how we can ensure that our implementation is working correctly.
Creating message listeners
There are two ways to create message listeners by using Spring Data Redis: we can implement the MessageListener
interface or we can create a POJO message listener and use the MessageListenerAdapter
class to delegate messages...