Example usage for org.springframework.integration.redis.inbound RedisInboundChannelAdapter afterPropertiesSet

List of usage examples for org.springframework.integration.redis.inbound RedisInboundChannelAdapter afterPropertiesSet

Introduction

In this page you can find the example usage for org.springframework.integration.redis.inbound RedisInboundChannelAdapter afterPropertiesSet.

Prototype

@Override
    public final void afterPropertiesSet() 

Source Link

Usage

From source file:org.springframework.integration.redis.inbound.RedisInboundChannelAdapterTests.java

private void testRedisInboundChannelAdapterGuts(int iteration) throws Exception {
    int numToTest = 10;
    String redisChannelName = "testRedisInboundChannelAdapterChannel";
    QueueChannel channel = new QueueChannel();

    JedisConnectionFactory connectionFactory = new JedisConnectionFactory();
    connectionFactory.setPort(7379);//from w w w .  j  a  v  a2s .c o  m
    connectionFactory.afterPropertiesSet();

    RedisInboundChannelAdapter adapter = new RedisInboundChannelAdapter(connectionFactory);
    adapter.setTopics("testRedisInboundChannelAdapterChannel");
    adapter.setOutputChannel(channel);
    adapter.afterPropertiesSet();
    adapter.start();

    RedisMessageListenerContainer container = waitUntilSubscribed(adapter);

    StringRedisTemplate redisTemplate = new StringRedisTemplate(connectionFactory);
    redisTemplate.afterPropertiesSet();
    for (int i = 0; i < numToTest; i++) {
        String message = "test-" + i + " iteration " + iteration;
        redisTemplate.convertAndSend(redisChannelName, message);
        logger.debug("Sent " + message);
    }
    int counter = 0;
    for (int i = 0; i < numToTest; i++) {
        Message<?> message = channel.receive(5000);
        if (message == null) {
            throw new RuntimeException("Failed to receive message # " + i + " iteration " + iteration);
        }
        assertNotNull(message);
        assertTrue(message.getPayload().toString().startsWith("test-"));
        counter++;
    }
    assertEquals(numToTest, counter);
    adapter.stop();
    container.stop();
    connectionFactory.destroy();
}

From source file:org.springframework.integration.x.redis.RedisChannelRegistry.java

@Override
public void tap(String tapModule, final String name, MessageChannel channel) {
    RedisInboundChannelAdapter adapter = new RedisInboundChannelAdapter(
            this.redisTemplate.getConnectionFactory());
    adapter.setTopics("topic." + name);
    adapter.setOutputChannel(channel);//from   w w w.j  a v a2s. c om
    adapter.setBeanName("tap." + name);
    adapter.setComponentName(tapModule + "." + "tapAdapter");
    adapter.afterPropertiesSet();
    this.lifecycleBeans.add(adapter);
    adapter.start();
}