List of usage examples for org.springframework.data.redis.listener RedisMessageListenerContainer stop
public void stop()
From source file:com.miko.demo.mongo.service.RedisPublishSubscribeTest.java
@Test public void testPubSubWithConversion() { RedisConnection redis = connectionFactory.getConnection(); RedisMessageListenerContainer listeners = new RedisMessageListenerContainer(); listeners.setConnectionFactory(connectionFactory); MessageListenerAdapter listener = new MessageListenerAdapter(new BeanMessageListener()); listener.setSerializer(new BeanMessageSerializer()); listener.afterPropertiesSet();//from w w w.j a v a2s. c o m listeners.addMessageListener(listener, new ChannelTopic(DUMP_CHANNEL)); listeners.afterPropertiesSet(); listeners.start(); try { redis.publish(DUMP_CHANNEL.getBytes(), "Hello World!".getBytes()); } finally { redis.close(); listeners.stop(); } }
From source file:org.springframework.data.redis.listener.SubscriptionConnectionTests.java
@Test public void testStopMessageListenerContainers() throws Exception { // Grab all 8 connections from the pool. They should be released on // container stop for (int i = 0; i < 8; i++) { RedisMessageListenerContainer container = new RedisMessageListenerContainer(); container.setConnectionFactory(connectionFactory); container.setBeanName("container" + i); container.addMessageListener(new MessageListenerAdapter(handler), Arrays.asList(new ChannelTopic(CHANNEL))); container.setTaskExecutor(new SyncTaskExecutor()); container.setSubscriptionExecutor(new SimpleAsyncTaskExecutor()); container.afterPropertiesSet();/*ww w. j a v a 2s . c o m*/ container.start(); if (connectionFactory instanceof JedisConnectionFactory) { // Need to sleep shortly as jedis cannot deal propery with multiple repsonses within one connection // @see https://github.com/xetorthio/jedis/issues/186 Thread.sleep(100); } container.stop(); containers.add(container); } // verify we can now get a connection from the pool RedisConnection connection = connectionFactory.getConnection(); connection.close(); }
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 a 2 s . c om 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(); }