I Create Redis Pub/Sub with single Topic and single listener with Java like thank:
That is my Beans within MvcConfigurer:
@Bean
MessageListenerAdapter messageListener() {
return new MessageListenerAdapter(redisMsgHandler);
}
@Bean
public RedisMessageListenerContainer redisMessageListenerContainer() {
RedisMessageListenerContainer mlc = new RedisMessageListenerContainer();
mlc.setConnectionFactory(lettuceConnectionFactory());
mlc.addMessageListener(messageListener(), topic());
return mlc;
}
@Bean
ChannelTopic topic() {
return new ChannelTopic("pubsub:queue");
}
That's where i'm receiving Message, please not this RedisMsghandler class is used to MvcConfigurer
public class RedisMsgHandler implements MessageListener {
@Override
public void onMessage(Message message, byte[] bytes) {
//impl goes here
}
}
my main goal is to create more than one topic and more than one listener like RedisMsgHandler, please let me know how to do it.
I don't feel comfortable to create lots of classes which are implemented on MessageListener and lots of beans for each Topic