use of org.springframework.data.redis.listener.RedisMessageListenerContainer in project camel by apache.
the class RedisConfiguration method createDefaultListenerContainer.
private RedisMessageListenerContainer createDefaultListenerContainer() {
listenerContainer = new RedisMessageListenerContainer();
managedListenerContainer = true;
listenerContainer.setConnectionFactory(getConnectionFactory());
listenerContainer.afterPropertiesSet();
listenerContainer.start();
return listenerContainer;
}
use of org.springframework.data.redis.listener.RedisMessageListenerContainer in project rdbcache by rdbcache.
the class RedisConfig method container.
@Bean
RedisMessageListenerContainer container() {
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
container.setConnectionFactory(redisConnectionFactory());
container.addMessageListener(listenerAdapter(), new PatternTopic("__key*__:expired"));
return container;
}
use of org.springframework.data.redis.listener.RedisMessageListenerContainer in project tutorials by eugenp.
the class RedisConfig method redisContainer.
@Bean
RedisMessageListenerContainer redisContainer() {
final RedisMessageListenerContainer container = new RedisMessageListenerContainer();
container.setConnectionFactory(jedisConnectionFactory());
container.addMessageListener(messageListener(), topic());
return container;
}
use of org.springframework.data.redis.listener.RedisMessageListenerContainer in project spring-integration by spring-projects.
the class SubscribableRedisChannelTests method dispatcherHasNoSubscribersTest.
@Test
@RedisAvailable
public void dispatcherHasNoSubscribersTest() throws Exception {
RedisConnectionFactory connectionFactory = this.getConnectionFactoryForTest();
SubscribableRedisChannel channel = new SubscribableRedisChannel(connectionFactory, "si.test.channel.no.subs");
channel.setBeanName("dhnsChannel");
channel.setBeanFactory(mock(BeanFactory.class));
channel.afterPropertiesSet();
RedisMessageListenerContainer container = TestUtils.getPropertyValue(channel, "container", RedisMessageListenerContainer.class);
@SuppressWarnings("unchecked") Map<?, Set<MessageListenerAdapter>> channelMapping = (Map<?, Set<MessageListenerAdapter>>) TestUtils.getPropertyValue(container, "channelMapping");
MessageListenerAdapter listener = channelMapping.entrySet().iterator().next().getValue().iterator().next();
Object delegate = TestUtils.getPropertyValue(listener, "delegate");
try {
ReflectionUtils.findMethod(delegate.getClass(), "handleMessage", Object.class).invoke(delegate, "Hello, world!");
fail("Exception expected");
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
assertNotNull(cause);
assertThat(cause.getMessage(), containsString("Dispatcher has no subscribers for redis-channel 'si.test.channel.no.subs' (dhnsChannel)."));
}
}
use of org.springframework.data.redis.listener.RedisMessageListenerContainer in project redisson by redisson.
the class RedissonSubscribeTest method testPatterTopic.
@Test
public void testPatterTopic() throws IOException, InterruptedException {
RedisRunner.RedisProcess instance = new RedisRunner().nosave().randomPort().randomDir().notifyKeyspaceEvents(RedisRunner.KEYSPACE_EVENTS_OPTIONS.K, RedisRunner.KEYSPACE_EVENTS_OPTIONS.g, RedisRunner.KEYSPACE_EVENTS_OPTIONS.E, RedisRunner.KEYSPACE_EVENTS_OPTIONS.$).run();
Config config = new Config();
config.useSingleServer().setAddress(instance.getRedisServerAddressAndPort()).setPingConnectionInterval(0);
RedissonClient redisson = Redisson.create(config);
RedissonConnectionFactory factory = new RedissonConnectionFactory(redisson);
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
container.setConnectionFactory(factory);
AtomicInteger counterTest = new AtomicInteger();
container.addMessageListener(new MessageListener() {
@Override
public void onMessage(Message message, byte[] pattern) {
counterTest.incrementAndGet();
}
}, new PatternTopic("__keyspace@0__:mykey"));
container.addMessageListener(new MessageListener() {
@Override
public void onMessage(Message message, byte[] pattern) {
counterTest.incrementAndGet();
}
}, new PatternTopic("__keyevent@0__:del"));
container.afterPropertiesSet();
container.start();
Assertions.assertThat(container.isRunning()).isTrue();
RedisConnection c = factory.getConnection();
c.set("mykey".getBytes(), "2".getBytes());
c.del("mykey".getBytes());
Awaitility.await().atMost(Duration.FIVE_SECONDS).until(() -> {
return counterTest.get() == 3;
});
container.stop();
redisson.shutdown();
}
Aggregations