Search in sources :

Example 1 with PatternTopic

use of org.springframework.data.redis.listener.PatternTopic in project rdbcache by rdbcache.

the class RedisConfig method container.

@Bean
RedisMessageListenerContainer container() {
    RedisMessageListenerContainer container = new RedisMessageListenerContainer();
    container.setConnectionFactory(redisConnectionFactory());
    container.addMessageListener(listenerAdapter(), new PatternTopic("__key*__:expired"));
    return container;
}
Also used : PatternTopic(org.springframework.data.redis.listener.PatternTopic) RedisMessageListenerContainer(org.springframework.data.redis.listener.RedisMessageListenerContainer) Bean(org.springframework.context.annotation.Bean)

Example 2 with PatternTopic

use of org.springframework.data.redis.listener.PatternTopic in project camel by apache.

the class RedisConsumer method toTopics.

private Collection<Topic> toTopics(String channels) {
    String[] channelsArrays = channels.split(",");
    List<Topic> topics = new ArrayList<>();
    for (String channel : channelsArrays) {
        String name = channel.trim();
        if (Command.PSUBSCRIBE.equals(redisConfiguration.getCommand())) {
            topics.add(new PatternTopic(name));
        } else if (Command.SUBSCRIBE.equals(redisConfiguration.getCommand())) {
            topics.add(new ChannelTopic(name));
        } else {
            throw new IllegalArgumentException("Unsupported Command " + redisConfiguration.getCommand());
        }
    }
    return topics;
}
Also used : ChannelTopic(org.springframework.data.redis.listener.ChannelTopic) PatternTopic(org.springframework.data.redis.listener.PatternTopic) ArrayList(java.util.ArrayList) ChannelTopic(org.springframework.data.redis.listener.ChannelTopic) Topic(org.springframework.data.redis.listener.Topic) PatternTopic(org.springframework.data.redis.listener.PatternTopic)

Example 3 with PatternTopic

use of org.springframework.data.redis.listener.PatternTopic in project spring-session by spring-projects.

the class RedisHttpSessionConfiguration method redisMessageListenerContainer.

@Bean
public RedisMessageListenerContainer redisMessageListenerContainer() {
    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 PatternTopic("__keyevent@*:del"), new PatternTopic("__keyevent@*:expired")));
    container.addMessageListener(sessionRepository(), Collections.singletonList(new PatternTopic(sessionRepository().getSessionCreatedChannelPrefix() + "*")));
    return container;
}
Also used : PatternTopic(org.springframework.data.redis.listener.PatternTopic) RedisMessageListenerContainer(org.springframework.data.redis.listener.RedisMessageListenerContainer) InitializingBean(org.springframework.beans.factory.InitializingBean) Bean(org.springframework.context.annotation.Bean)

Example 4 with PatternTopic

use of org.springframework.data.redis.listener.PatternTopic in project spring-integration by spring-projects.

the class RedisInboundChannelAdapter method onInit.

@Override
protected void onInit() {
    super.onInit();
    boolean hasTopics = false;
    if (this.topics != null) {
        Assert.noNullElements(this.topics, "'topics' may not contain null elements.");
        hasTopics = true;
    }
    boolean hasPatterns = false;
    if (this.topicPatterns != null) {
        Assert.noNullElements(this.topicPatterns, "'topicPatterns' may not contain null elements.");
        hasPatterns = true;
    }
    Assert.state(hasTopics || hasPatterns, "at least one topic or topic pattern is required for subscription.");
    if (this.messageConverter instanceof BeanFactoryAware) {
        ((BeanFactoryAware) this.messageConverter).setBeanFactory(this.getBeanFactory());
    }
    MessageListenerDelegate delegate = new MessageListenerDelegate();
    MessageListenerAdapter adapter = new MessageListenerAdapter(delegate);
    adapter.setSerializer(this.serializer);
    List<Topic> topicList = new ArrayList<Topic>();
    if (hasTopics) {
        for (String topic : this.topics) {
            topicList.add(new ChannelTopic(topic));
        }
    }
    if (hasPatterns) {
        for (String pattern : this.topicPatterns) {
            topicList.add(new PatternTopic(pattern));
        }
    }
    adapter.afterPropertiesSet();
    this.container.addMessageListener(adapter, topicList);
    this.container.afterPropertiesSet();
}
Also used : MessageListenerAdapter(org.springframework.data.redis.listener.adapter.MessageListenerAdapter) BeanFactoryAware(org.springframework.beans.factory.BeanFactoryAware) ChannelTopic(org.springframework.data.redis.listener.ChannelTopic) PatternTopic(org.springframework.data.redis.listener.PatternTopic) ArrayList(java.util.ArrayList) Topic(org.springframework.data.redis.listener.Topic) PatternTopic(org.springframework.data.redis.listener.PatternTopic) ChannelTopic(org.springframework.data.redis.listener.ChannelTopic)

Aggregations

PatternTopic (org.springframework.data.redis.listener.PatternTopic)4 ArrayList (java.util.ArrayList)2 Bean (org.springframework.context.annotation.Bean)2 ChannelTopic (org.springframework.data.redis.listener.ChannelTopic)2 RedisMessageListenerContainer (org.springframework.data.redis.listener.RedisMessageListenerContainer)2 Topic (org.springframework.data.redis.listener.Topic)2 BeanFactoryAware (org.springframework.beans.factory.BeanFactoryAware)1 InitializingBean (org.springframework.beans.factory.InitializingBean)1 MessageListenerAdapter (org.springframework.data.redis.listener.adapter.MessageListenerAdapter)1