use of org.springframework.integration.channel.DirectChannel in project camel by apache.
the class CamelSourceAdapterTest method testSendingOneWayMessage.
@Test
public void testSendingOneWayMessage() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
DirectChannel channelA = getMandatoryBean(DirectChannel.class, "channelA");
channelA.subscribe(new MessageHandler() {
public void handleMessage(Message<?> message) {
latch.countDown();
assertEquals("We should get the message from channelA", message.getPayload(), "Willem");
}
});
template.sendBody("direct:OneWay", "Willem");
assertTrue(latch.await(1, TimeUnit.SECONDS));
}
use of org.springframework.integration.channel.DirectChannel in project spring-integration by spring-projects.
the class DelayHandlerTests method errorChannelNameHeaderAndHandlerThrowsExceptionWithDelay.
@Test
public void errorChannelNameHeaderAndHandlerThrowsExceptionWithDelay() throws Exception {
String errorChannelName = "customErrorChannel";
StaticApplicationContext context = new StaticApplicationContext();
context.registerSingleton(errorChannelName, DirectChannel.class);
context.registerSingleton(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME, DirectChannel.class);
context.refresh();
DirectChannel customErrorChannel = (DirectChannel) context.getBean(errorChannelName);
MessagePublishingErrorHandler errorHandler = new MessagePublishingErrorHandler();
errorHandler.setBeanFactory(context);
taskScheduler.setErrorHandler(errorHandler);
this.setDelayExpression();
this.startDelayerHandler();
output.unsubscribe(resultHandler);
customErrorChannel.subscribe(resultHandler);
output.subscribe(message -> {
throw new UnsupportedOperationException("intentional test failure");
});
Message<?> message = MessageBuilder.withPayload("test").setHeader("delay", "10").setErrorChannelName(errorChannelName).build();
input.send(message);
waitForLatch(10000);
Message<?> errorMessage = resultHandler.lastMessage;
assertEquals(MessageDeliveryException.class, errorMessage.getPayload().getClass());
MessageDeliveryException exceptionPayload = (MessageDeliveryException) errorMessage.getPayload();
assertSame(message.getPayload(), exceptionPayload.getFailedMessage().getPayload());
assertEquals(UnsupportedOperationException.class, exceptionPayload.getCause().getClass());
assertNotSame(Thread.currentThread(), resultHandler.lastThread);
}
use of org.springframework.integration.channel.DirectChannel in project spring-integration by spring-projects.
the class DelayHandlerTests method defaultErrorChannelAndHandlerThrowsExceptionWithDelay.
@Test
public void defaultErrorChannelAndHandlerThrowsExceptionWithDelay() throws Exception {
StaticApplicationContext context = new StaticApplicationContext();
context.registerSingleton(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME, DirectChannel.class);
context.refresh();
DirectChannel defaultErrorChannel = (DirectChannel) context.getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME);
MessagePublishingErrorHandler errorHandler = new MessagePublishingErrorHandler();
errorHandler.setBeanFactory(context);
taskScheduler.setErrorHandler(errorHandler);
this.setDelayExpression();
this.startDelayerHandler();
output.unsubscribe(resultHandler);
defaultErrorChannel.subscribe(resultHandler);
output.subscribe(message -> {
throw new UnsupportedOperationException("intentional test failure");
});
Message<?> message = MessageBuilder.withPayload("test").setHeader("delay", "10").build();
input.send(message);
waitForLatch(10000);
Message<?> errorMessage = resultHandler.lastMessage;
assertEquals(MessageDeliveryException.class, errorMessage.getPayload().getClass());
MessageDeliveryException exceptionPayload = (MessageDeliveryException) errorMessage.getPayload();
assertSame(message.getPayload(), exceptionPayload.getFailedMessage().getPayload());
assertEquals(UnsupportedOperationException.class, exceptionPayload.getCause().getClass());
assertNotSame(Thread.currentThread(), resultHandler.lastThread);
}
use of org.springframework.integration.channel.DirectChannel in project spring-integration by spring-projects.
the class MessagingGatewayTests method validateErrorChannelWithSuccessfulReply.
// should not fail but it does now
@Test
public void validateErrorChannelWithSuccessfulReply() {
TestUtils.TestApplicationContext testApplicationContext = TestUtils.createTestApplicationContext();
testApplicationContext.refresh();
DirectChannel reqChannel = new DirectChannel();
reqChannel.subscribe(message -> {
throw new RuntimeException("ooops");
});
PublishSubscribeChannel errorChannel = new PublishSubscribeChannel();
ServiceActivatingHandler handler = new ServiceActivatingHandler(new MyOneWayErrorService());
handler.setBeanFactory(testApplicationContext);
handler.afterPropertiesSet();
errorChannel.subscribe(handler);
this.messagingGateway = new MessagingGatewaySupport() {
};
this.messagingGateway.setRequestChannel(reqChannel);
this.messagingGateway.setErrorChannel(errorChannel);
this.messagingGateway.setReplyChannel(null);
this.messagingGateway.setBeanFactory(mock(BeanFactory.class));
this.messagingGateway.afterPropertiesSet();
this.messagingGateway.start();
this.messagingGateway.send("hello");
testApplicationContext.close();
}
use of org.springframework.integration.channel.DirectChannel in project spring-integration by spring-projects.
the class MessageHistoryIntegrationTests method testMessageHistoryWithHistoryPerformance.
@Test
@Ignore
public void testMessageHistoryWithHistoryPerformance() {
ConfigurableApplicationContext acWithHistory = new ClassPathXmlApplicationContext("perfWithMessageHistory.xml", MessageHistoryIntegrationTests.class);
ConfigurableApplicationContext acWithoutHistory = new ClassPathXmlApplicationContext("perfWithoutMessageHistory.xml", MessageHistoryIntegrationTests.class);
SampleGateway gatewayHistory = acWithHistory.getBean("sampleGateway", SampleGateway.class);
DirectChannel endOfThePipeChannelHistory = acWithHistory.getBean("endOfThePipeChannel", DirectChannel.class);
endOfThePipeChannelHistory.subscribe(message -> {
MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel();
replyChannel.send(message);
});
SampleGateway gateway = acWithoutHistory.getBean("sampleGateway", SampleGateway.class);
DirectChannel endOfThePipeChannel = acWithoutHistory.getBean("endOfThePipeChannel", DirectChannel.class);
endOfThePipeChannel.subscribe(message -> {
MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel();
replyChannel.send(message);
});
StopWatch stopWatch = new StopWatch();
stopWatch.start();
for (int i = 0; i < 10000; i++) {
gatewayHistory.echo("hello");
}
stopWatch.stop();
logger.info("Elapsed time with history 10000 calls: " + stopWatch.getTotalTimeSeconds());
stopWatch = new StopWatch();
stopWatch.start();
for (int i = 0; i < 10000; i++) {
gateway.echo("hello");
}
stopWatch.stop();
logger.info("Elapsed time without history 10000 calls: " + stopWatch.getTotalTimeSeconds());
acWithHistory.close();
acWithoutHistory.close();
}
Aggregations