Quantcast
Channel: Redis Pub/Sub with Java spring - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Redis Pub/Sub with Java spring

$
0
0

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


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images