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

The following examples show how to use org.springframework.data.redis.listener.adapter.MessageListenerAdapter. 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: CacheConfig.java    From springboot-plus with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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
Source File: ScheduleConfig.java    From albedo with 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 #3
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 #4
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 #5
Source File: RedisListenerProcessor.java    From faster-framework-project with Apache License 2.0 5 votes vote down vote up
@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 #6
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 #7
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 #8
Source File: RedisListenerConfigure.java    From spring-boot-tutorials with Apache License 2.0 4 votes vote down vote up
@Bean
public MessageListenerAdapter simpleMessageListenerAdapter() {
    return new MessageListenerAdapter(simpleReceiver());
}
 
Example #9
Source File: RedisReceiver.java    From SpringCloud with Apache License 2.0 4 votes vote down vote up
@Bean
MessageListenerAdapter redisListenerAdapter() {
    logger.info("new listener");
    return new MessageListenerAdapter(this);
}
 
Example #10
Source File: RedisTestConfiguration.java    From synapse with Apache License 2.0 4 votes vote down vote up
@Bean
MessageListenerAdapter listenerAdapter(final RedisReceiver receiver) {
    return new MessageListenerAdapter(receiver, "receiveMessage");
}
 
Example #11
Source File: RedisConfig.java    From DataM with Apache License 2.0 4 votes vote down vote up
@Bean
MessageListenerAdapter messageListener() {
    return new MessageListenerAdapter(new RedisInfoSubscriber());
}
 
Example #12
Source File: RedisListenerConfigure.java    From spring-boot-tutorials with Apache License 2.0 4 votes vote down vote up
@Bean
public MessageListenerAdapter objectMessageListenerAdapter() {
    return new MessageListenerAdapter(demoReceiver());
}
 
Example #13
Source File: RedisConfig.java    From SpringBoot-Base-System with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Bean
MessageListenerAdapter listenerAdapter(Receiver receiver) {
	return new MessageListenerAdapter(receiver, "receiveMessage");
}
 
Example #14
Source File: RedisConfig.java    From pro-spring-boot with Apache License 2.0 4 votes vote down vote up
@Bean
MessageListenerAdapter listenerAdapter(Consumer consumer) {
	return new MessageListenerAdapter(consumer, "messageHandler");
}
 
Example #15
Source File: RedisConfiguration.java    From ddd-strategic-design-spring-boot with Apache License 2.0 4 votes vote down vote up
@Bean
MessageListenerAdapter creditApplicationApprovedMessageListener(CreditApplicationApprovedEventReceiver receiver) {
    MessageListenerAdapter messageListenerAdapter = new MessageListenerAdapter(receiver, "receiveMessage");
    messageListenerAdapter.setSerializer(new Jackson2JsonRedisSerializer<CreditApplicationApprovedEvent>(CreditApplicationApprovedEvent.class));
    return messageListenerAdapter;
}
 
Example #16
Source File: RedisConfiguration.java    From ddd-strategic-design-spring-boot with Apache License 2.0 4 votes vote down vote up
@Bean
MessageListenerAdapter creditApplicationDeclinedMessageListener(CreditApplicationDeclinedEventReceiver receiver) {
    MessageListenerAdapter messageListenerAdapter = new MessageListenerAdapter(receiver, "receiveMessage");
    messageListenerAdapter.setSerializer(new Jackson2JsonRedisSerializer<CreditApplicationDeclinedEvent>(CreditApplicationDeclinedEvent.class));
    return messageListenerAdapter;
}
 
Example #17
Source File: RedisConfiguration.java    From ddd-strategic-design-spring-boot with Apache License 2.0 4 votes vote down vote up
@Bean
MessageListenerAdapter customerCreatedMessageListener(CustomerCreatedEventReceiver receiver) {
    MessageListenerAdapter messageListenerAdapter = new MessageListenerAdapter(receiver, "receiveMessage");
    messageListenerAdapter.setSerializer(new Jackson2JsonRedisSerializer<CustomerCreatedEvent>(CustomerCreatedEvent.class));
    return messageListenerAdapter;
}
 
Example #18
Source File: RedisMessageReceiver.java    From onboard with Apache License 2.0 4 votes vote down vote up
@Bean
MessageListenerAdapter listenerAdapter(RedisMessageReceiver receiver) {
    return new MessageListenerAdapter(receiver, "receiveMessage");
}
 
Example #19
Source File: RedisConfig.java    From pro-spring-boot with Apache License 2.0 4 votes vote down vote up
@Bean
MessageListenerAdapter listenerAdapter(Consumer consumer) {
	return new MessageListenerAdapter(consumer, "messageHandler");
}
 
Example #20
Source File: RedisConfig.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
MessageListenerAdapter messageListener() {
    return new MessageListenerAdapter(new RedisMessageSubscriber());
}
 
Example #21
Source File: RedisChannelAutoConfiguration.java    From servicecomb-pack with Apache License 2.0 4 votes vote down vote up
@Bean
public MessageListenerAdapter messageListenerAdapter(
    RedisSagaEventConsumer redisSagaEventConsumer) {
  return new MessageListenerAdapter(redisSagaEventConsumer);
}
 
Example #22
Source File: RedisSubListenerConfig.java    From spring-boot-seckill with GNU General Public License v2.0 4 votes vote down vote up
@Bean
MessageListenerAdapter listenerAdapter(RedisConsumer redisReceiver) {
    return new MessageListenerAdapter(redisReceiver, "receiveMessage");
}
 
Example #23
Source File: redismq.java    From SpringBootLearn with Apache License 2.0 4 votes vote down vote up
/**
 * 绑定消息监听者和接收监听的方法,必须要注入这个监听器,不然会报错
 * @return
 */
@Bean
MessageListenerAdapter listenerAdapter(Receiver receiver) {
    //指定 Receiver为代理接收类,接收消息方法为receiveMessage
    return new MessageListenerAdapter(receiver, "receiveMessage");
}
 
Example #24
Source File: RedisReceiver.java    From JetfireCloud with Apache License 2.0 4 votes vote down vote up
@Bean
MessageListenerAdapter redisListenerAdapter() {
    logger.info("new listener");
    return new MessageListenerAdapter(this);
}
 
Example #25
Source File: CacheConfig.java    From microservice-recruit with Apache License 2.0 4 votes vote down vote up
@Bean
MessageListenerAdapter listenerAdapter(MessageService receiver) {
    return new MessageListenerAdapter(receiver, "receiveMessage");
}
 
Example #26
Source File: MsgRedisApplication.java    From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International 4 votes vote down vote up
@Bean
MessageListenerAdapter listenerAdapter(Receiver receiver) {
    return new MessageListenerAdapter(receiver, "receiveMessage");
}
 
Example #27
Source File: CasbinRedisWatcherAutoConfiguration.java    From casbin-spring-boot-starter with Apache License 2.0 4 votes vote down vote up
/**
 * 消息监听器适配器,绑定消息处理器,利用反射技术调用消息处理器的业务方法
 */
@Bean
@ConditionalOnMissingBean
public MessageListenerAdapter messageListenerAdapter(Watcher receiver) {
    return new MessageListenerAdapter(receiver, "updatePolicy");
}
 
Example #28
Source File: RedisConfiguration.java    From alcor with Apache License 2.0 4 votes vote down vote up
@Bean
MessageListenerAdapter redisListenerInstance() {
    return new MessageListenerAdapter(new RedisListener());
}
 
Example #29
Source File: RedisSubListenerConfig.java    From ext-opensource-netty with Mozilla Public License 2.0 4 votes vote down vote up
@Bean
MessageListenerAdapter listenerAdapter(RedisSubribleLister redisSubribleLister) {
	return new MessageListenerAdapter(redisSubribleLister, "receiveMessage");
}
 
Example #30
Source File: RedisConfig.java    From spring-boot-demo with MIT License 4 votes vote down vote up
@Bean
MessageListenerAdapter messageListener() {
    return new MessageListenerAdapter(new RedisMessageSubscriber());
}