List of usage examples for org.springframework.data.redis.listener ChannelTopic ChannelTopic
public ChannelTopic(String name)
From source file:org.apereo.openlrs.storage.redis.RedisPubSubConfig.java
@Bean RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) { RedisMessageListenerContainer container = new RedisMessageListenerContainer(); container.setConnectionFactory(connectionFactory); container.addMessageListener(listenerAdapter, new ChannelTopic(channelName())); return container; }
From source file:org.apereo.openlrs.RedisElasticsearchConfig.java
@Conditional(RedisEnabledCondition.class) @Bean/*w ww . j av a 2 s . com*/ RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) { RedisMessageListenerContainer container = new RedisMessageListenerContainer(); container.setConnectionFactory(connectionFactory); container.addMessageListener(listenerAdapter, new ChannelTopic(channelName())); return container; }
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 ww . ja v a 2 s . co 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();/*from w w w . jav a2s.co 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.data.redis.listener.SubscriptionConnectionTests.java
@Test public void testRemoveLastListener() throws Exception { // Grab all 8 connections from the pool MessageListener listener = new MessageListenerAdapter(handler); for (int i = 0; i < 8; i++) { RedisMessageListenerContainer container = new RedisMessageListenerContainer(); container.setConnectionFactory(connectionFactory); container.setBeanName("container" + i); container.addMessageListener(listener, Arrays.asList(new ChannelTopic(CHANNEL))); container.setTaskExecutor(new SyncTaskExecutor()); container.setSubscriptionExecutor(new SimpleAsyncTaskExecutor()); container.afterPropertiesSet();//from w ww. j a va 2 s.c o m container.start(); containers.add(container); } // Removing the sole listener from the container should free up a // connection containers.get(0).removeMessageListener(listener); // verify we can now get a connection from the pool RedisConnection connection = connectionFactory.getConnection(); connection.close(); }
From source file:org.springframework.data.redis.listener.SubscriptionConnectionTests.java
@Test public void testStopListening() throws InterruptedException { // Grab all 8 connections from the pool. MessageListener listener = new MessageListenerAdapter(handler); for (int i = 0; i < 8; i++) { RedisMessageListenerContainer container = new RedisMessageListenerContainer(); container.setConnectionFactory(connectionFactory); container.setBeanName("container" + i); container.addMessageListener(listener, Arrays.asList(new ChannelTopic(CHANNEL))); container.setTaskExecutor(new SyncTaskExecutor()); container.setSubscriptionExecutor(new SimpleAsyncTaskExecutor()); container.afterPropertiesSet();//from ww w . j a v a 2 s . c o m container.start(); containers.add(container); } // Unsubscribe all listeners from all topics, freeing up a connection containers.get(0).removeMessageListener(null, Arrays.asList(new Topic[] {})); // verify we can now get a connection from the pool RedisConnection connection = connectionFactory.getConnection(); connection.close(); }
From source file:org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration.java
@Bean public RedisMessageListenerContainer springSessionRedisMessageListenerContainer( RedisOperationsSessionRepository sessionRepository) { RedisMessageListenerContainer container = new RedisMessageListenerContainer(); container.setConnectionFactory(this.redisConnectionFactory); if (this.redisTaskExecutor != null) { container.setTaskExecutor(this.redisTaskExecutor); }//from ww w.j ava2 s. c o m if (this.redisSubscriptionExecutor != null) { container.setSubscriptionExecutor(this.redisSubscriptionExecutor); } container.addMessageListener(sessionRepository, Arrays.asList(new ChannelTopic(sessionRepository.getSessionDeletedChannel()), new ChannelTopic(sessionRepository.getSessionExpiredChannel()))); container.addMessageListener(sessionRepository, Collections .singletonList(new PatternTopic(sessionRepository.getSessionCreatedChannelPrefix() + "*"))); return container; }