Search in sources :

Example 1 with DirectWithAttributesChannel

use of org.springframework.cloud.stream.messaging.DirectWithAttributesChannel in project spring-cloud-stream by spring-cloud.

the class MessageChannelConfigurerTests method testChannelTypes.

@Test
public void testChannelTypes() throws Exception {
    DirectWithAttributesChannel inputChannel = (DirectWithAttributesChannel) this.testSink.input();
    DirectWithAttributesChannel outputChannel = (DirectWithAttributesChannel) this.testSource.output();
    assertThat(inputChannel.getAttribute("type")).isEqualTo(Sink.INPUT);
    assertThat(outputChannel.getAttribute("type")).isEqualTo(Source.OUTPUT);
}
Also used : DirectWithAttributesChannel(org.springframework.cloud.stream.messaging.DirectWithAttributesChannel) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with DirectWithAttributesChannel

use of org.springframework.cloud.stream.messaging.DirectWithAttributesChannel in project spring-cloud-stream by spring-cloud.

the class SubscribableChannelBindingTargetFactory method createOutput.

@Override
public SubscribableChannel createOutput(String name) {
    SubscribableChannel subscribableChannel = null;
    if (context != null && context.containsBean(name)) {
        try {
            subscribableChannel = context.getBean(name, SubscribableChannel.class);
        } catch (BeanCreationException e) {
        // ignore
        }
    }
    if (subscribableChannel == null) {
        DirectWithAttributesChannel channel = new DirectWithAttributesChannel();
        channel.setComponentName(name);
        if (context != null && !context.containsBean(name)) {
            context.registerBean(name, DirectWithAttributesChannel.class, () -> channel);
        }
        subscribableChannel = channel;
    }
    if (subscribableChannel instanceof DirectWithAttributesChannel) {
        ((DirectWithAttributesChannel) subscribableChannel).setAttribute("type", "output");
        this.messageChannelConfigurer.configureOutputChannel(subscribableChannel, name);
    }
    return subscribableChannel;
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) DirectWithAttributesChannel(org.springframework.cloud.stream.messaging.DirectWithAttributesChannel) SubscribableChannel(org.springframework.messaging.SubscribableChannel)

Example 3 with DirectWithAttributesChannel

use of org.springframework.cloud.stream.messaging.DirectWithAttributesChannel in project spring-cloud-stream by spring-cloud.

the class SubscribableChannelBindingTargetFactory method createInput.

@Override
public SubscribableChannel createInput(String name) {
    SubscribableChannel subscribableChannel = null;
    if (context != null && context.containsBean(name)) {
        try {
            subscribableChannel = context.getBean(name, SubscribableChannel.class);
        } catch (BeanCreationException e) {
        // ignore
        /*
				 * Since we still support annotation-based programming model, this exception happens
				 * because of proxies related to @Input @Output
				 */
        }
    }
    if (subscribableChannel == null) {
        DirectWithAttributesChannel channel = new DirectWithAttributesChannel();
        channel.setComponentName(name);
        if (context != null && !context.containsBean(name)) {
            context.registerBean(name, DirectWithAttributesChannel.class, () -> channel);
        }
        subscribableChannel = channel;
    }
    if (subscribableChannel instanceof DirectWithAttributesChannel) {
        ((DirectWithAttributesChannel) subscribableChannel).setAttribute("type", "input");
        this.messageChannelConfigurer.configureInputChannel(subscribableChannel, name);
    }
    return subscribableChannel;
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) DirectWithAttributesChannel(org.springframework.cloud.stream.messaging.DirectWithAttributesChannel) SubscribableChannel(org.springframework.messaging.SubscribableChannel)

Example 4 with DirectWithAttributesChannel

use of org.springframework.cloud.stream.messaging.DirectWithAttributesChannel in project spring-cloud-stream by spring-cloud.

the class PartitionedConsumerTest method testBindingPartitionedConsumer.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testBindingPartitionedConsumer() {
    Binder binder = this.binderFactory.getBinder(null, MessageChannel.class);
    ArgumentCaptor<ConsumerProperties> argumentCaptor = ArgumentCaptor.forClass(ConsumerProperties.class);
    ArgumentCaptor<DirectWithAttributesChannel> directWithAttributesChannelArgumentCaptor = ArgumentCaptor.forClass(DirectWithAttributesChannel.class);
    verify(binder).bindConsumer(eq("partIn"), isNull(), directWithAttributesChannelArgumentCaptor.capture(), argumentCaptor.capture());
    assertThat(directWithAttributesChannelArgumentCaptor.getValue().getBeanName()).isEqualTo("sink-in-0");
    assertThat(argumentCaptor.getValue().getInstanceIndex()).isEqualTo(0);
    assertThat(argumentCaptor.getValue().getInstanceCount()).isEqualTo(2);
    verifyNoMoreInteractions(binder);
}
Also used : Binder(org.springframework.cloud.stream.binder.Binder) DirectWithAttributesChannel(org.springframework.cloud.stream.messaging.DirectWithAttributesChannel) ConsumerProperties(org.springframework.cloud.stream.binder.ConsumerProperties) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with DirectWithAttributesChannel

use of org.springframework.cloud.stream.messaging.DirectWithAttributesChannel 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

DirectWithAttributesChannel (org.springframework.cloud.stream.messaging.DirectWithAttributesChannel)6 Test (org.junit.Test)2 BeanCreationException (org.springframework.beans.factory.BeanCreationException)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Binder (org.springframework.cloud.stream.binder.Binder)2 SubscribableChannel (org.springframework.messaging.SubscribableChannel)2 Type (java.lang.reflect.Type)1 Function (java.util.function.Function)1 FunctionRegistration (org.springframework.cloud.function.context.FunctionRegistration)1 BinderFactory (org.springframework.cloud.stream.binder.BinderFactory)1 ConsumerProperties (org.springframework.cloud.stream.binder.ConsumerProperties)1 DefaultPartitioningInterceptor (org.springframework.cloud.stream.binding.DefaultPartitioningInterceptor)1 BindingProperties (org.springframework.cloud.stream.config.BindingProperties)1 ResolvableType (org.springframework.core.ResolvableType)1 AbstractMessageChannel (org.springframework.integration.channel.AbstractMessageChannel)1 MessageChannel (org.springframework.messaging.MessageChannel)1 MimeType (org.springframework.util.MimeType)1