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);
}
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;
}
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;
}
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);
}
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;
}
Aggregations