Java Code Examples for org.springframework.data.redis.listener.RedisMessageListenerContainer

The following examples show how to use org.springframework.data.redis.listener.RedisMessageListenerContainer. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Bean
public RedisMessageListenerContainer springSessionRedisMessageListenerContainer(
		RedisIndexedSessionRepository sessionRepository) {
	RedisMessageListenerContainer container = new RedisMessageListenerContainer();
	container.setConnectionFactory(this.redisConnectionFactory);
	if (this.redisTaskExecutor != null) {
		container.setTaskExecutor(this.redisTaskExecutor);
	}
	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;
}
 
Example 2
Source Project: alcor   Source File: RedisConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
RedisMessageListenerContainer redisContainer() {
    final RedisMessageListenerContainer container = new RedisMessageListenerContainer();
    container.setConnectionFactory(lettuceConnectionFactory());
    container.addMessageListener(redisListenerInstance(), topic());
    return container;
}
 
Example 3
/**
 * redis消息监听器容器
 * 可以添加多个监听不同话题的redis监听器,只需要把消息监听器和相应的消息订阅处理器绑定,该消息监听器
 * 通过反射技术调用消息订阅处理器的相关方法进行一些业务处理
 */
@Bean
@ConditionalOnMissingBean
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
public RedisMessageListenerContainer redisMessageListenerContainer(
        RedisConnectionFactory connectionFactory,
        MessageListenerAdapter listenerAdapter
) {
    RedisMessageListenerContainer container = new RedisMessageListenerContainer();
    container.setConnectionFactory(connectionFactory);
    //订阅CASBIN_POLICY_TOPIC通道
    container.addMessageListener(listenerAdapter, new ChannelTopic(CASBIN_POLICY_TOPIC));
    return container;
}
 
Example 4
Source Project: tac   Source File: RedisBeansConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public RedisMessageListenerContainer redisMessageListenerContainer(JedisConnectionFactory jedisConnectionFactory) {
    RedisMessageListenerContainer container = new RedisMessageListenerContainer();
    container.setConnectionFactory(jedisConnectionFactory);
    // set thread pool
    container.setTaskExecutor(ThreadPoolUtils.createThreadPool(10, "tac-redis-subscribe-pool"));
    return container;
}
 
Example 5
Source Project: tac   Source File: RedisConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public RedisMessageListenerContainer redisMessageListenerContainer(JedisConnectionFactory jedisConnectionFactory,
                                                                   MessageListenerAdapter listenerAdapter) {

    RedisMessageListenerContainer container = new RedisMessageListenerContainer();
    container.setConnectionFactory(jedisConnectionFactory);
    container.addMessageListener(listenerAdapter, new ChannelTopic("topicA"));
    // 设置线程池
    //container.setTaskExecutor(null);
    return container;
}
 
Example 6
@Bean
public RedisMessageListenerContainer redisMessageListenerContainer(RedisConnectionFactory connectionFactory, RedisOperationsSessionRepository messageListener) {
    RedisMessageListenerContainer container = new RedisMessageListenerContainer();
    container.setConnectionFactory(connectionFactory);
    container.addMessageListener(messageListener, Arrays.asList(new PatternTopic("[email protected]*:del"), new PatternTopic("[email protected]*:expired")));
    container.addMessageListener(messageListener, Arrays.asList(new PatternTopic(messageListener.getSessionCreatedChannelPrefix() + "*")));
    return container;
}
 
Example 7
@Bean
public RedisMessageListenerContainer redisContainer(RedisConnectionFactory redisConnectionFactory) {
    RedisMessageListenerContainer container
            = new RedisMessageListenerContainer();
    container.setConnectionFactory(redisConnectionFactory);
    return container;
}
 
Example 8
Source Project: JetfireCloud   Source File: RedisSender.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
RedisMessageListenerContainer redisContainer(RedisConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {
    RedisMessageListenerContainer container = new RedisMessageListenerContainer();
    container.setConnectionFactory(connectionFactory);
    container.addMessageListener(listenerAdapter, new ChannelTopic("chat"));
    logger.info("init container:{}", listenerAdapter);
    return container;
}
 
Example 9
Source Project: SpringCloud   Source File: RedisSender.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
RedisMessageListenerContainer redisContainer(RedisConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {
    RedisMessageListenerContainer container = new RedisMessageListenerContainer();
    container.setConnectionFactory(connectionFactory);
    container.addMessageListener(listenerAdapter, new ChannelTopic("chat"));
    logger.info("init container:{}", listenerAdapter);
    return container;
}
 
Example 10
Source Project: DataM   Source File: RedisConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
RedisMessageListenerContainer redisContainer() {
    RedisMessageListenerContainer container
            = new RedisMessageListenerContainer();
    container.setConnectionFactory(jedisConnFactory());
    container.addMessageListener(messageListener(), topic());
    return container;
}
 
Example 11
@Bean
public RedisMessageListenerContainer objectListenerContainer(RedisConnectionFactory redisConnectionFactory){
    RedisMessageListenerContainer container = new RedisMessageListenerContainer();
    container.setConnectionFactory(redisConnectionFactory);
    List<ChannelTopic> topics = Arrays.asList(new ChannelTopic(PubSubConstant.CHAT_ROOM));
    container.addMessageListener(objectMessageListenerAdapter(), topics);
    return container;
}
 
Example 12
@Bean
public RedisMessageListenerContainer simpleListenerContainer(RedisConnectionFactory redisConnectionFactory){
    RedisMessageListenerContainer container = new RedisMessageListenerContainer();
    container.setConnectionFactory(redisConnectionFactory);
    List<ChannelTopic> topics = Arrays.asList(new ChannelTopic(PubSubConstant.NEWS_CHANNEL));
    container.addMessageListener(simpleMessageListenerAdapter(), topics);
    return container;
}
 
Example 13
@Test // gh-1252
void customRedisMessageListenerContainerConfig() {
	registerAndRefresh(RedisConfig.class, CustomRedisMessageListenerContainerConfig.class);
	Map<String, RedisMessageListenerContainer> beans = this.context
			.getBeansOfType(RedisMessageListenerContainer.class);
	assertThat(beans).hasSize(2);
	assertThat(beans).containsKeys("springSessionRedisMessageListenerContainer", "redisMessageListenerContainer");
}
 
Example 14
Source Project: tutorials   Source File: RedisConfig.java    License: MIT License 5 votes vote down vote up
@Bean
RedisMessageListenerContainer redisContainer() {
    final RedisMessageListenerContainer container = new RedisMessageListenerContainer();
    container.setConnectionFactory(jedisConnectionFactory());
    container.addMessageListener(messageListener(), topic());
    return container;
}
 
Example 15
public RedisMessageListenerContainer getContainer() {
  return this.container;
}
 
Example 16
@Bean
public static RedisListenerProcessor redisListenerProcessor(RedisMessageListenerContainer redisMessageListenerContainer) {
    return new RedisListenerProcessor(redisMessageListenerContainer);
}
 
Example 17
public RedisListenerProcessor(RedisMessageListenerContainer redisMessageListenerContainer) {
    this.redisMessageListenerContainer = redisMessageListenerContainer;
}
 
Example 18
@Bean
RedisMessageListenerContainer redisMessageListenerContainer() {
	return new RedisMessageListenerContainer();
}