Java Code Examples for org.springframework.data.redis.listener.adapter.MessageListenerAdapter

The following examples show how to use org.springframework.data.redis.listener.adapter.MessageListenerAdapter. 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
MessageListenerAdapter listenerAdapter(final TowLevelCacheManager cacheManager) {
	return new MessageListenerAdapter(new MessageListener() {

		public void onMessage(Message message, byte[] pattern) {
			byte[] bs = message.getChannel();
			try {
				// Sub 一个消息,通知缓存管理器
				String type = new String(bs, "UTF-8");
				cacheManager.receiver(type);
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
				// 不可能出错,忽略
			}

		}

	});
}
 
Example 2
/**
 * 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 3
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 4
@Override
public Object postProcessAfterInitialization(Object bean, final String beanName) {
    Class<?> targetClass = AopUtils.getTargetClass(bean);
    Map<Method, RedisListener> annotatedMethods = MethodIntrospector.selectMethods(targetClass,
            (MethodIntrospector.MetadataLookup<RedisListener>) method -> AnnotatedElementUtils.findMergedAnnotation(method, RedisListener.class));
    annotatedMethods.forEach((method, v) -> {
        MessageListenerAdapter messageListenerAdapter = new MessageListenerAdapter(bean, method.getName());
        messageListenerAdapter.afterPropertiesSet();
        String[] channels = v.value();
        for (String channel : channels) {
            redisMessageListenerContainer.addMessageListener(messageListenerAdapter, channel.contains("*") ? new PatternTopic(channel) : new ChannelTopic(channel));
        }
    });
    return bean;
}
 
Example 5
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 6
Source Project: albedo   Source File: ScheduleConfig.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 绑定消息监听者和接收监听的方法
 *
 * @param scheduleReceiver
 * @return
 */
@Bean
MessageListenerAdapter listenerAdapter(ScheduleReceiver scheduleReceiver) {
	// redisReceiver 消息接收者
	// receiveMessage 消息接收后的方法
	return new MessageListenerAdapter(scheduleReceiver, "receiveMessage");
}
 
Example 7
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 8
Source Project: SpringBootLearn   Source File: redismq.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 绑定消息监听者和接收监听的方法,必须要注入这个监听器,不然会报错
 * @return
 */
@Bean
MessageListenerAdapter listenerAdapter(Receiver receiver) {
    //指定 Receiver为代理接收类,接收消息方法为receiveMessage
    return new MessageListenerAdapter(receiver, "receiveMessage");
}
 
Example 9
Source Project: microservice-recruit   Source File: CacheConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
MessageListenerAdapter listenerAdapter(MessageService receiver) {
    return new MessageListenerAdapter(receiver, "receiveMessage");
}
 
Example 10
Source Project: Milkomeda   Source File: RedisMetalConfig.java    License: MIT License 4 votes vote down vote up
@Bean
public MessageListenerAdapter listenerAdapter(MetalMessageHandler metalMessageHandler) {
    return new MessageListenerAdapter(metalMessageHandler);
}
 
Example 11
Source Project: spring-boot-demo   Source File: RedisConfig.java    License: MIT License 4 votes vote down vote up
@Bean
MessageListenerAdapter messageListener() {
    return new MessageListenerAdapter(new RedisMessageSubscriber());
}
 
Example 12
@Bean
MessageListenerAdapter listenerAdapter(RedisSubribleLister redisSubribleLister) {
	return new MessageListenerAdapter(redisSubribleLister, "receiveMessage");
}
 
Example 13
Source Project: alcor   Source File: RedisConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
MessageListenerAdapter redisListenerInstance() {
    return new MessageListenerAdapter(new RedisListener());
}
 
Example 14
/**
 * 消息监听器适配器,绑定消息处理器,利用反射技术调用消息处理器的业务方法
 */
@Bean
@ConditionalOnMissingBean
public MessageListenerAdapter messageListenerAdapter(Watcher receiver) {
    return new MessageListenerAdapter(receiver, "updatePolicy");
}
 
Example 15
@Bean
MessageListenerAdapter listenerAdapter(Receiver receiver) {
    return new MessageListenerAdapter(receiver, "receiveMessage");
}
 
Example 16
Source Project: microservice-recruit   Source File: CacheConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
MessageListenerAdapter listenerAdapter(MessageService receiver) {
    return new MessageListenerAdapter(receiver, "receiveMessage");
}
 
Example 17
Source Project: JetfireCloud   Source File: RedisReceiver.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
MessageListenerAdapter redisListenerAdapter() {
    logger.info("new listener");
    return new MessageListenerAdapter(this);
}
 
Example 18
@Bean
MessageListenerAdapter listenerAdapter(Receiver receiver) {
	return new MessageListenerAdapter(receiver, "receiveMessage");
}
 
Example 19
@Bean
MessageListenerAdapter listenerAdapter(RedisConsumer redisReceiver) {
    return new MessageListenerAdapter(redisReceiver, "receiveMessage");
}
 
Example 20
@Bean
public MessageListenerAdapter messageListenerAdapter(
    RedisSagaEventConsumer redisSagaEventConsumer) {
  return new MessageListenerAdapter(redisSagaEventConsumer);
}
 
Example 21
Source Project: SpringCloud   Source File: RedisReceiver.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
MessageListenerAdapter redisListenerAdapter() {
    logger.info("new listener");
    return new MessageListenerAdapter(this);
}
 
Example 22
Source Project: synapse   Source File: RedisTestConfiguration.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
MessageListenerAdapter listenerAdapter(final RedisReceiver receiver) {
    return new MessageListenerAdapter(receiver, "receiveMessage");
}
 
Example 23
Source Project: DataM   Source File: RedisConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
MessageListenerAdapter messageListener() {
    return new MessageListenerAdapter(new RedisInfoSubscriber());
}
 
Example 24
@Bean
public MessageListenerAdapter objectMessageListenerAdapter() {
    return new MessageListenerAdapter(demoReceiver());
}
 
Example 25
@Bean
public MessageListenerAdapter simpleMessageListenerAdapter() {
    return new MessageListenerAdapter(simpleReceiver());
}
 
Example 26
Source Project: pro-spring-boot   Source File: RedisConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
MessageListenerAdapter listenerAdapter(Consumer consumer) {
	return new MessageListenerAdapter(consumer, "messageHandler");
}
 
Example 27
@Bean
MessageListenerAdapter creditApplicationApprovedMessageListener(CreditApplicationApprovedEventReceiver receiver) {
    MessageListenerAdapter messageListenerAdapter = new MessageListenerAdapter(receiver, "receiveMessage");
    messageListenerAdapter.setSerializer(new Jackson2JsonRedisSerializer<CreditApplicationApprovedEvent>(CreditApplicationApprovedEvent.class));
    return messageListenerAdapter;
}
 
Example 28
@Bean
MessageListenerAdapter creditApplicationDeclinedMessageListener(CreditApplicationDeclinedEventReceiver receiver) {
    MessageListenerAdapter messageListenerAdapter = new MessageListenerAdapter(receiver, "receiveMessage");
    messageListenerAdapter.setSerializer(new Jackson2JsonRedisSerializer<CreditApplicationDeclinedEvent>(CreditApplicationDeclinedEvent.class));
    return messageListenerAdapter;
}
 
Example 29
@Bean
MessageListenerAdapter customerCreatedMessageListener(CustomerCreatedEventReceiver receiver) {
    MessageListenerAdapter messageListenerAdapter = new MessageListenerAdapter(receiver, "receiveMessage");
    messageListenerAdapter.setSerializer(new Jackson2JsonRedisSerializer<CustomerCreatedEvent>(CustomerCreatedEvent.class));
    return messageListenerAdapter;
}
 
Example 30
Source Project: onboard   Source File: RedisMessageReceiver.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
MessageListenerAdapter listenerAdapter(RedisMessageReceiver receiver) {
    return new MessageListenerAdapter(receiver, "receiveMessage");
}