use of org.springframework.integration.channel.AbstractMessageChannel in project spring-cloud-stream by spring-cloud.
the class TestChannelBinderProvisioner method provisionDestination.
private SubscribableChannel provisionDestination(String name, boolean pubSub) {
String destinationName = name + ".destination";
SubscribableChannel destination = this.provisionedDestinations.get(destinationName);
if (destination == null) {
destination = pubSub ? new PublishSubscribeChannel() : new DirectChannel();
((AbstractMessageChannel) destination).setBeanName(destinationName);
((AbstractMessageChannel) destination).setComponentName(destinationName);
this.provisionedDestinations.put(destinationName, destination);
}
return destination;
}
use of org.springframework.integration.channel.AbstractMessageChannel in project spring-cloud-stream by spring-cloud.
the class BinderAwareChannelResolverTests method resolveChannel.
@Test
public void resolveChannel() {
Map<String, Bindable> bindables = context.getBeansOfType(Bindable.class);
assertThat(bindables).hasSize(1);
for (Bindable bindable : bindables.values()) {
// producer
assertEquals(0, bindable.getInputs().size());
// consumer
assertEquals(0, bindable.getOutputs().size());
}
MessageChannel registered = resolver.resolveDestination("foo");
assertEquals(2, ((AbstractMessageChannel) registered).getChannelInterceptors().size());
assertTrue(((AbstractMessageChannel) registered).getChannelInterceptors().get(1) instanceof ImmutableMessageChannelInterceptor);
bindables = context.getBeansOfType(Bindable.class);
assertThat(bindables).hasSize(1);
for (Bindable bindable : bindables.values()) {
// producer
assertEquals(0, bindable.getInputs().size());
// consumer
assertEquals(1, bindable.getOutputs().size());
}
DirectChannel testChannel = new DirectChannel();
testChannel.setComponentName("INPUT");
final CountDownLatch latch = new CountDownLatch(1);
final List<Message<?>> received = new ArrayList<>();
testChannel.subscribe(new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
received.add(message);
latch.countDown();
}
});
this.binder.bindConsumer("foo", null, testChannel, new ConsumerProperties());
assertThat(received).hasSize(0);
registered.send(MessageBuilder.withPayload("hello").build());
try {
assertThat(latch.await(1, TimeUnit.SECONDS)).describedAs("Latch timed out");
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
fail("interrupted while awaiting latch");
}
assertThat(received).hasSize(1);
assertThat(new String((byte[]) received.get(0).getPayload())).isEqualTo("hello");
this.context.close();
for (Bindable bindable : bindables.values()) {
assertEquals(0, bindable.getInputs().size());
// Must not be bound"
assertEquals(0, bindable.getOutputs().size());
}
}
use of org.springframework.integration.channel.AbstractMessageChannel in project spring-cloud-stream by spring-cloud.
the class MessageConverterConfigurer method configureMessageChannel.
/**
* Setup data-type and message converters for the given message channel.
*
* @param channel message channel to set the data-type and message converters
* @param channelName the channel name
* @param inbound inbound (i.e., "input") or outbound channel
*/
private void configureMessageChannel(MessageChannel channel, String channelName, boolean inbound) {
Assert.isAssignable(AbstractMessageChannel.class, channel.getClass());
AbstractMessageChannel messageChannel = (AbstractMessageChannel) channel;
BindingProperties bindingProperties = this.bindingServiceProperties.getBindingProperties(channelName);
String contentType = bindingProperties.getContentType();
ProducerProperties producerProperties = bindingProperties.getProducer();
if (!inbound && producerProperties != null && producerProperties.isPartitioned()) {
messageChannel.addInterceptor(new PartitioningInterceptor(bindingProperties, getPartitionKeyExtractorStrategy(producerProperties), getPartitionSelectorStrategy(producerProperties)));
}
ConsumerProperties consumerProperties = bindingProperties.getConsumer();
if (this.isNativeEncodingNotSet(producerProperties, consumerProperties, inbound)) {
if (inbound) {
messageChannel.addInterceptor(new InboundContentTypeEnhancingInterceptor(contentType));
} else {
messageChannel.addInterceptor(new OutboundContentTypeConvertingInterceptor(contentType, this.compositeMessageConverterFactory.getMessageConverterForAllRegistered()));
}
}
}
use of org.springframework.integration.channel.AbstractMessageChannel in project spring-integration by spring-projects.
the class EnableIntegrationTests method testParentChildAnnotationConfigurationFromAnotherPackage.
@Test
public void testParentChildAnnotationConfigurationFromAnotherPackage() {
AnnotationConfigApplicationContext child = new AnnotationConfigApplicationContext();
child.register(org.springframework.integration.configuration2.ChildConfiguration.class);
child.setParent(this.context);
child.refresh();
AbstractMessageChannel foo = child.getBean("foo", AbstractMessageChannel.class);
ChannelInterceptor baz = child.getBean("baz", ChannelInterceptor.class);
assertTrue(foo.getChannelInterceptors().contains(baz));
assertFalse(this.output.getChannelInterceptors().contains(baz));
child.close();
}
use of org.springframework.integration.channel.AbstractMessageChannel in project spring-integration by spring-projects.
the class ChannelInterceptorTests method afterCompletionWithSendException.
@Test
public void afterCompletionWithSendException() {
final AbstractMessageChannel testChannel = new AbstractMessageChannel() {
@Override
protected boolean doSend(Message<?> message, long timeout) {
throw new RuntimeException("Simulated exception");
}
};
AfterCompletionTestInterceptor interceptor1 = new AfterCompletionTestInterceptor();
AfterCompletionTestInterceptor interceptor2 = new AfterCompletionTestInterceptor();
testChannel.addInterceptor(interceptor1);
testChannel.addInterceptor(interceptor2);
try {
testChannel.send(MessageBuilder.withPayload("test").build());
} catch (Exception ex) {
assertEquals("Simulated exception", ex.getCause().getMessage());
}
assertTrue(interceptor1.wasAfterCompletionInvoked());
assertTrue(interceptor2.wasAfterCompletionInvoked());
}
Aggregations