Elimizde şöyle bir topic olsun
@Beanpublic ChannelTopic channelTopic(){return new ChannelTopic("pubsub:pageupdate");}
Publisher için şöyle yaparız
// Publisher@Service@RequiredArgsConstructorpublic class RedisPublishService {private final ReactiveRedisTemplate reactiveRedisTemplate;private final ChannelTopic channelTopic;public void publish(List<String> updatedPageList){reactiveRedisTemplate.convertAndSend(channelTopic.getTopic(), updatedPageList).block();}}
// Consumer@Slf4jpublic class RedisListenerService implements MessageListener {@Overridepublic void onMessage(Message message, byte[] pattern) {log.info("Consumed on pub sub {}", message);TODO: implement your logic}}@Beanpublic MessageListener messageListener(){return new MessageListenerAdapter(new RedisListenerService());}@Beanpublic RedisMessageListenerContainer redisMessageListenerContainer(){RedisMessageListenerContainer container = new RedisMessageListenerContainer();container.setConnectionFactory(redisConnectionFactory());container.addMessageListener(messageListener(), channelTopic());return container;}
Hiç yorum yok:
Yorum Gönder