Search in sources :

Example 6 with RedisMessageListenerContainer

use of org.springframework.data.redis.listener.RedisMessageListenerContainer in project spring-integration by spring-projects.

the class RedisPublishingMessageHandlerTests method testRedisPublishingMessageHandler.

@Test
@RedisAvailable
public void testRedisPublishingMessageHandler() throws Exception {
    int numToTest = 10;
    String topic = "si.test.channel";
    final CountDownLatch latch = new CountDownLatch(numToTest * 2);
    RedisConnectionFactory connectionFactory = this.getConnectionFactoryForTest();
    MessageListenerAdapter listener = new MessageListenerAdapter();
    listener.setDelegate(new Listener(latch));
    listener.setSerializer(new StringRedisSerializer());
    listener.afterPropertiesSet();
    RedisMessageListenerContainer container = new RedisMessageListenerContainer();
    container.setConnectionFactory(connectionFactory);
    container.afterPropertiesSet();
    container.addMessageListener(listener, Collections.<Topic>singletonList(new ChannelTopic(topic)));
    container.start();
    this.awaitContainerSubscribed(container);
    final RedisPublishingMessageHandler handler = new RedisPublishingMessageHandler(connectionFactory);
    handler.setTopicExpression(new LiteralExpression(topic));
    for (int i = 0; i < numToTest; i++) {
        handler.handleMessage(MessageBuilder.withPayload("test-" + i).build());
    }
    for (int i = 0; i < numToTest; i++) {
        handler.handleMessage(MessageBuilder.withPayload(("test-" + i).getBytes()).build());
    }
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    container.stop();
}
Also used : MessageListenerAdapter(org.springframework.data.redis.listener.adapter.MessageListenerAdapter) StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) ChannelTopic(org.springframework.data.redis.listener.ChannelTopic) LiteralExpression(org.springframework.expression.common.LiteralExpression) RedisMessageListenerContainer(org.springframework.data.redis.listener.RedisMessageListenerContainer) CountDownLatch(java.util.concurrent.CountDownLatch) RedisConnectionFactory(org.springframework.data.redis.connection.RedisConnectionFactory) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 7 with RedisMessageListenerContainer

use of org.springframework.data.redis.listener.RedisMessageListenerContainer in project erp-catering by liuyandong33.

the class RedisMessageListenerConfiguration method redisMessageListenerContainer.

@Bean(destroyMethod = "destroy")
public RedisMessageListenerContainer redisMessageListenerContainer() {
    RedisMessageListenerContainer redisMessageListenerContainer = new RedisMessageListenerContainer();
    redisMessageListenerContainer.setConnectionFactory(jedisConnectionFactory);
    return redisMessageListenerContainer;
}
Also used : RedisMessageListenerContainer(org.springframework.data.redis.listener.RedisMessageListenerContainer) Bean(org.springframework.context.annotation.Bean)

Aggregations

RedisMessageListenerContainer (org.springframework.data.redis.listener.RedisMessageListenerContainer)7 Bean (org.springframework.context.annotation.Bean)4 Test (org.junit.Test)2 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)2 PatternTopic (org.springframework.data.redis.listener.PatternTopic)2 MessageListenerAdapter (org.springframework.data.redis.listener.adapter.MessageListenerAdapter)2 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Map (java.util.Map)1 Set (java.util.Set)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 BeanFactory (org.springframework.beans.factory.BeanFactory)1 InitializingBean (org.springframework.beans.factory.InitializingBean)1 ChannelTopic (org.springframework.data.redis.listener.ChannelTopic)1 StringRedisSerializer (org.springframework.data.redis.serializer.StringRedisSerializer)1 LiteralExpression (org.springframework.expression.common.LiteralExpression)1