Java Code Examples for org.springframework.data.redis.listener.RedisMessageListenerContainer#addMessageListener()

The following examples show how to use org.springframework.data.redis.listener.RedisMessageListenerContainer#addMessageListener() . 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
Source File: RedisHttpSessionConfiguration.java    From spring-session with Apache License 2.0 6 votes vote down vote up
@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 File: RedisConfiguration.java    From alcor with 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
Source File: CasbinRedisWatcherAutoConfiguration.java    From casbin-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * 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 File: RedisConfig.java    From tac with 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 5
Source File: ChoerodonRedisHttpSessionConfiguration.java    From oauth-server with Apache License 2.0 5 votes vote down vote up
@Bean
public RedisMessageListenerContainer redisMessageListenerContainer(RedisConnectionFactory connectionFactory, RedisOperationsSessionRepository messageListener) {
    RedisMessageListenerContainer container = new RedisMessageListenerContainer();
    container.setConnectionFactory(connectionFactory);
    container.addMessageListener(messageListener, Arrays.asList(new PatternTopic("__keyevent@*:del"), new PatternTopic("__keyevent@*:expired")));
    container.addMessageListener(messageListener, Arrays.asList(new PatternTopic(messageListener.getSessionCreatedChannelPrefix() + "*")));
    return container;
}
 
Example 6
Source File: RedisSender.java    From JetfireCloud with 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 7
Source File: RedisSender.java    From SpringCloud with 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 8
Source File: RedisConfig.java    From DataM with 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 9
Source File: RedisListenerConfigure.java    From spring-boot-tutorials with Apache License 2.0 5 votes vote down vote up
@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 10
Source File: RedisListenerConfigure.java    From spring-boot-tutorials with Apache License 2.0 5 votes vote down vote up
@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 11
Source File: RedisConfig.java    From tutorials with 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;
}