use of org.springframework.integration.channel.DirectChannel in project spring-cloud-stream by spring-cloud.
the class BindingServiceConfiguration method errorBridgeChannel.
@Bean
@ConditionalOnProperty("spring.cloud.stream.bindings." + ERROR_KEY_NAME + ".destination")
public MessageChannel errorBridgeChannel(@Qualifier(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME) PublishSubscribeChannel errorChannel) {
SubscribableChannel errorBridgeChannel = new DirectChannel();
BridgeHandler handler = new BridgeHandler();
handler.setOutputChannel(errorBridgeChannel);
errorChannel.subscribe(handler);
return errorBridgeChannel;
}
use of org.springframework.integration.channel.DirectChannel in project spring-cloud-stream by spring-cloud.
the class MessageChannelToInputFluxParameterAdapterTests method testWrapperFluxSupportsMultipleSubscriptions.
@Test
public void testWrapperFluxSupportsMultipleSubscriptions() throws Exception {
List<String> results = Collections.synchronizedList(new ArrayList<>());
CountDownLatch latch = new CountDownLatch(4);
final MessageChannelToInputFluxParameterAdapter messageChannelToInputFluxParameterAdapter = new MessageChannelToInputFluxParameterAdapter(new CompositeMessageConverter(Collections.singleton(new MappingJackson2MessageConverter())));
final Method processMethod = ReflectionUtils.findMethod(MessageChannelToInputFluxParameterAdapterTests.class, "process", Flux.class);
final DirectChannel adaptedChannel = new DirectChannel();
@SuppressWarnings("unchecked") final Flux<Message<?>> adapterFlux = (Flux<Message<?>>) messageChannelToInputFluxParameterAdapter.adapt(adaptedChannel, new MethodParameter(processMethod, 0));
String uuid1 = UUID.randomUUID().toString();
String uuid2 = UUID.randomUUID().toString();
adapterFlux.map(m -> m.getPayload() + uuid1).subscribe(s -> {
results.add(s);
latch.countDown();
});
adapterFlux.map(m -> m.getPayload() + uuid2).subscribe(s -> {
results.add(s);
latch.countDown();
});
adaptedChannel.send(MessageBuilder.withPayload("A").build());
adaptedChannel.send(MessageBuilder.withPayload("B").build());
assertThat(latch.await(5000, TimeUnit.MILLISECONDS)).isTrue();
assertThat(results).containsExactlyInAnyOrder("A" + uuid1, "B" + uuid1, "A" + uuid2, "B" + uuid2);
}
use of org.springframework.integration.channel.DirectChannel in project spring-cloud-stream by spring-cloud.
the class AggregateApplicationUtils method prepareSharedBindingTargetRegistry.
static void prepareSharedBindingTargetRegistry(SharedBindingTargetRegistry sharedBindingTargetRegistry, LinkedHashMap<Class<?>, String> appsWithNamespace) {
int i = 0;
SubscribableChannel sharedChannel = null;
for (Entry<Class<?>, String> appEntry : appsWithNamespace.entrySet()) {
String namespace = appEntry.getValue();
if (i > 0) {
sharedBindingTargetRegistry.register(namespace + "." + INPUT_BINDING_NAME, sharedChannel);
}
sharedChannel = new DirectChannel();
if (i < appsWithNamespace.size() - 1) {
sharedBindingTargetRegistry.register(namespace + "." + OUTPUT_BINDING_NAME, sharedChannel);
}
i++;
}
}
use of org.springframework.integration.channel.DirectChannel in project spring-cloud-stream by spring-cloud.
the class PollableConsumerTests method testRequeueFromErrorFlow.
@Test
public void testRequeueFromErrorFlow() {
TestChannelBinder binder = createBinder();
MessageConverterConfigurer configurer = this.context.getBean(MessageConverterConfigurer.class);
DefaultPollableMessageSource pollableSource = new DefaultPollableMessageSource(this.messageConverter);
configurer.configurePolledMessageSource(pollableSource, "foo");
AcknowledgmentCallback callback = mock(AcknowledgmentCallback.class);
pollableSource.addInterceptor(new ChannelInterceptor() {
@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
return MessageBuilder.fromMessage(message).setHeader(IntegrationMessageHeaderAccessor.ACKNOWLEDGMENT_CALLBACK, callback).build();
}
});
ExtendedConsumerProperties<Object> properties = new ExtendedConsumerProperties<>(null);
properties.setMaxAttempts(1);
binder.bindPollableConsumer("foo", "bar", pollableSource, properties);
SubscribableChannel errorChannel = new DirectChannel();
errorChannel.subscribe(msg -> {
throw new RequeueCurrentMessageException((Throwable) msg.getPayload());
});
pollableSource.setErrorChannel(errorChannel);
try {
pollableSource.poll(received -> {
throw new RuntimeException("test requeue from error flow");
});
} catch (Exception e) {
// no op
}
verify(callback).acknowledge(Status.REQUEUE);
}
use of org.springframework.integration.channel.DirectChannel in project spring-cloud-stream by spring-cloud.
the class BindingServiceTests method testDefaultGroup.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testDefaultGroup() throws Exception {
BindingServiceProperties properties = new BindingServiceProperties();
Map<String, BindingProperties> bindingProperties = new HashMap<>();
BindingProperties props = new BindingProperties();
props.setDestination("foo");
final String inputChannelName = "input";
bindingProperties.put(inputChannelName, props);
properties.setBindings(bindingProperties);
DefaultBinderFactory binderFactory = createMockBinderFactory();
Binder binder = binderFactory.getBinder("mock", MessageChannel.class);
BindingService service = new BindingService(properties, binderFactory, new ObjectMapper());
MessageChannel inputChannel = new DirectChannel();
Binding<MessageChannel> mockBinding = Mockito.mock(Binding.class);
when(binder.bindConsumer(eq("foo"), isNull(), same(inputChannel), any(ConsumerProperties.class))).thenReturn(mockBinding);
Collection<Binding<MessageChannel>> bindings = service.bindConsumer(inputChannel, inputChannelName);
assertThat(bindings).hasSize(1);
Binding<MessageChannel> binding = bindings.iterator().next();
assertThat(binding).isSameAs(mockBinding);
service.unbindConsumers(inputChannelName);
verify(binder).bindConsumer(eq("foo"), isNull(), same(inputChannel), any(ConsumerProperties.class));
verify(binding).unbind();
binderFactory.destroy();
}
Aggregations