Search in sources :

Example 6 with ChannelTopic

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

the class SubscribableRedisChannel method onInit.

@Override
public void onInit() throws Exception {
    if (this.initialized) {
        return;
    }
    super.onInit();
    if (this.maxSubscribers == null) {
        Integer maxSubscribers = getIntegrationProperty(IntegrationProperties.CHANNELS_MAX_BROADCAST_SUBSCRIBERS, Integer.class);
        this.setMaxSubscribers(maxSubscribers);
    }
    if (this.messageConverter == null) {
        this.messageConverter = new SimpleMessageConverter();
    }
    if (this.messageConverter instanceof BeanFactoryAware) {
        ((BeanFactoryAware) this.messageConverter).setBeanFactory(this.getBeanFactory());
    }
    this.container.setConnectionFactory(this.connectionFactory);
    if (!(this.taskExecutor instanceof ErrorHandlingTaskExecutor)) {
        ErrorHandler errorHandler = new MessagePublishingErrorHandler(new BeanFactoryChannelResolver(this.getBeanFactory()));
        this.taskExecutor = new ErrorHandlingTaskExecutor(this.taskExecutor, errorHandler);
    }
    this.container.setTaskExecutor(this.taskExecutor);
    MessageListenerAdapter adapter = new MessageListenerAdapter(new MessageListenerDelegate());
    adapter.setSerializer(this.serializer);
    adapter.afterPropertiesSet();
    this.container.addMessageListener(adapter, new ChannelTopic(this.topicName));
    this.container.afterPropertiesSet();
    this.dispatcher.setBeanFactory(this.getBeanFactory());
    this.initialized = true;
}
Also used : MessageListenerAdapter(org.springframework.data.redis.listener.adapter.MessageListenerAdapter) BeanFactoryAware(org.springframework.beans.factory.BeanFactoryAware) MessagePublishingErrorHandler(org.springframework.integration.channel.MessagePublishingErrorHandler) ErrorHandler(org.springframework.util.ErrorHandler) MessagePublishingErrorHandler(org.springframework.integration.channel.MessagePublishingErrorHandler) ChannelTopic(org.springframework.data.redis.listener.ChannelTopic) BeanFactoryChannelResolver(org.springframework.integration.support.channel.BeanFactoryChannelResolver) SimpleMessageConverter(org.springframework.integration.support.converter.SimpleMessageConverter) ErrorHandlingTaskExecutor(org.springframework.integration.util.ErrorHandlingTaskExecutor)

Aggregations

ChannelTopic (org.springframework.data.redis.listener.ChannelTopic)6 Test (org.junit.Test)3 Topic (org.springframework.data.redis.listener.Topic)3 MessageListenerAdapter (org.springframework.data.redis.listener.adapter.MessageListenerAdapter)3 ArrayList (java.util.ArrayList)2 BeanFactoryAware (org.springframework.beans.factory.BeanFactoryAware)2 MessageListener (org.springframework.data.redis.connection.MessageListener)2 PatternTopic (org.springframework.data.redis.listener.PatternTopic)2 RedisMessageListenerContainer (org.springframework.data.redis.listener.RedisMessageListenerContainer)2 Collection (java.util.Collection)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Message (org.springframework.data.redis.connection.Message)1 RedisConnection (org.springframework.data.redis.connection.RedisConnection)1 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)1 StringRedisSerializer (org.springframework.data.redis.serializer.StringRedisSerializer)1 LiteralExpression (org.springframework.expression.common.LiteralExpression)1 MessagePublishingErrorHandler (org.springframework.integration.channel.MessagePublishingErrorHandler)1 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)1 BeanFactoryChannelResolver (org.springframework.integration.support.channel.BeanFactoryChannelResolver)1