org.springframework.data.redis.listener.PatternTopic Java Examples
The following examples show how to use
org.springframework.data.redis.listener.PatternTopic.
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 |
@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: RedisChatMessageListener.java From spring-redis-websocket with Apache License 2.0 | 5 votes |
public Mono<Void> subscribeMessageChannelAndPublishOnWebSocket() { return reactiveStringRedisTemplate.listenTo(new PatternTopic(MESSAGE_TOPIC)) .map(ReactiveSubscription.Message::getMessage) .flatMap(message -> ObjectStringConverter.stringToObject(message, ChatMessage.class)) .filter(chatMessage -> !chatMessage.getMessage().isEmpty()) .flatMap(chatWebSocketHandler::sendMessage) .then(); }
Example #3
Source File: ChoerodonRedisHttpSessionConfiguration.java From oauth-server with Apache License 2.0 | 5 votes |
@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 #4
Source File: RedisListenerProcessor.java From faster-framework-project with Apache License 2.0 | 5 votes |
@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 File: TokenRepositoryImpl.java From authlib-agent with MIT License | 5 votes |
@PostConstruct private void registerExpiredEventListener() { expiredListener = new MessageListener() { @Override public void onMessage(Message message, byte[] pattern) { byte[] body = message.getBody(); if (body == null) { return; } String key; try { key = new String(message.getBody(), "UTF-8"); } catch (UnsupportedEncodingException e) { LOGGER.debug(() -> "failed to decode message body: " + bytesToHex(body), e); return; } if (!key.startsWith(PREFIX_EXPIRE)) { return; } String accessToken = key.substring(PREFIX_EXPIRE.length()); template.delete(keyAccessToken(accessToken)); Map<String, String> values = hashOps.entries(keyAccessToken(accessToken)); if (values != null && !values.isEmpty()) { setOps.remove(keyClientToken(values.get(KEY_CLIENT_TOKEN)), accessToken); setOps.remove(keyAccount(values.get(KEY_OWNER)), accessToken); } } }; container.addMessageListener(expiredListener, new PatternTopic("__keyevent@*__:expired")); }