Search in sources :

Example 1 with DefaultPartitioningInterceptor

use of org.springframework.cloud.stream.binding.DefaultPartitioningInterceptor in project spring-cloud-stream by spring-cloud.

the class StreamBridge method resolveDestination.

@SuppressWarnings({ "unchecked" })
synchronized MessageChannel resolveDestination(String destinationName, ProducerProperties producerProperties, String binderName) {
    MessageChannel messageChannel = this.channelCache.get(destinationName);
    if (messageChannel == null && this.applicationContext.containsBean(destinationName)) {
        messageChannel = this.applicationContext.getBean(destinationName, MessageChannel.class);
    }
    if (messageChannel == null) {
        messageChannel = new DirectWithAttributesChannel();
        if (this.destinationBindingCallback != null) {
            Object extendedProducerProperties = this.bindingService.getExtendedProducerProperties(messageChannel, destinationName);
            this.destinationBindingCallback.configure(destinationName, messageChannel, producerProperties, extendedProducerProperties);
        }
        Binder binder = null;
        if (StringUtils.hasText(binderName)) {
            BinderFactory binderFactory = this.applicationContext.getBean(BinderFactory.class);
            binder = binderFactory.getBinder(binderName, messageChannel.getClass());
        }
        if (producerProperties != null && producerProperties.isPartitioned()) {
            BindingProperties bindingProperties = this.bindingServiceProperties.getBindingProperties(destinationName);
            ((AbstractMessageChannel) messageChannel).addInterceptor(new DefaultPartitioningInterceptor(bindingProperties, this.applicationContext.getBeanFactory()));
        }
        this.addInterceptors((AbstractMessageChannel) messageChannel, destinationName);
        this.bindingService.bindProducer(messageChannel, destinationName, false, binder);
        this.channelCache.put(destinationName, messageChannel);
    }
    return messageChannel;
}
Also used : Binder(org.springframework.cloud.stream.binder.Binder) BinderFactory(org.springframework.cloud.stream.binder.BinderFactory) DefaultPartitioningInterceptor(org.springframework.cloud.stream.binding.DefaultPartitioningInterceptor) AbstractMessageChannel(org.springframework.integration.channel.AbstractMessageChannel) MessageChannel(org.springframework.messaging.MessageChannel) AbstractMessageChannel(org.springframework.integration.channel.AbstractMessageChannel) BindingProperties(org.springframework.cloud.stream.config.BindingProperties) DirectWithAttributesChannel(org.springframework.cloud.stream.messaging.DirectWithAttributesChannel)

Aggregations

Binder (org.springframework.cloud.stream.binder.Binder)1 BinderFactory (org.springframework.cloud.stream.binder.BinderFactory)1 DefaultPartitioningInterceptor (org.springframework.cloud.stream.binding.DefaultPartitioningInterceptor)1 BindingProperties (org.springframework.cloud.stream.config.BindingProperties)1 DirectWithAttributesChannel (org.springframework.cloud.stream.messaging.DirectWithAttributesChannel)1 AbstractMessageChannel (org.springframework.integration.channel.AbstractMessageChannel)1 MessageChannel (org.springframework.messaging.MessageChannel)1