use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.
the class FilterAnnotationPostProcessorTests method filterAnnotationWithAdviceCollection.
@Test
public void filterAnnotationWithAdviceCollection() {
TestAdvice advice = new TestAdvice();
context.registerBean("adviceChain", Arrays.asList(new TestAdvice[] { advice }));
testValidFilter(new TestFilterWithAdviceDiscardWithin());
EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("testFilter.filter.filter");
assertSame(advice, TestUtils.getPropertyValue(endpoint, "handler.adviceChain", List.class).get(0));
assertTrue(TestUtils.getPropertyValue(endpoint, "handler.postProcessWithinAdvice", Boolean.class));
}
use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.
the class StreamingSplitterTests method splitToIterator_allMessagesContainSequenceNumber.
@Test
public void splitToIterator_allMessagesContainSequenceNumber() throws Exception {
final int messageQuantity = 5;
MethodInvokingSplitter splitter = new MethodInvokingSplitter(new IteratorTestBean(messageQuantity));
DirectChannel replyChannel = new DirectChannel();
splitter.setOutputChannel(replyChannel);
new EventDrivenConsumer(replyChannel, message -> assertThat("Failure with msg: " + message, message.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER, Integer.class), is(Integer.valueOf((String) message.getPayload())))).start();
splitter.handleMessage(message);
}
use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.
the class StreamingSplitterTests method splitWithMassiveReplyMessages_allMessagesSent.
@Test
public void splitWithMassiveReplyMessages_allMessagesSent() throws Exception {
final int messageQuantity = 100000;
MethodInvokingSplitter splitter = new MethodInvokingSplitter(new IteratorTestBean(messageQuantity));
DirectChannel replyChannel = new DirectChannel();
splitter.setOutputChannel(replyChannel);
final AtomicInteger receivedMessageCounter = new AtomicInteger(0);
new EventDrivenConsumer(replyChannel, message -> {
assertThat("Failure with msg: " + message, message.getPayload(), is(notNullValue()));
receivedMessageCounter.incrementAndGet();
}).start();
splitter.handleMessage(message);
assertThat(receivedMessageCounter.get(), is(messageQuantity));
}
use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.
the class ApplicationContextMessageBusTests method bothConsumersReceivePublishSubscribeMessage.
@Test
public void bothConsumersReceivePublishSubscribeMessage() throws InterruptedException {
TestApplicationContext context = TestUtils.createTestApplicationContext();
PublishSubscribeChannel inputChannel = new PublishSubscribeChannel();
QueueChannel outputChannel1 = new QueueChannel();
QueueChannel outputChannel2 = new QueueChannel();
final CountDownLatch latch = new CountDownLatch(2);
AbstractReplyProducingMessageHandler handler1 = new AbstractReplyProducingMessageHandler() {
@Override
public Object handleRequestMessage(Message<?> message) {
latch.countDown();
return message;
}
};
AbstractReplyProducingMessageHandler handler2 = new AbstractReplyProducingMessageHandler() {
@Override
public Object handleRequestMessage(Message<?> message) {
latch.countDown();
return message;
}
};
context.registerChannel("input", inputChannel);
context.registerChannel("output1", outputChannel1);
context.registerChannel("output2", outputChannel2);
handler1.setOutputChannel(outputChannel1);
handler2.setOutputChannel(outputChannel2);
EventDrivenConsumer endpoint1 = new EventDrivenConsumer(inputChannel, handler1);
EventDrivenConsumer endpoint2 = new EventDrivenConsumer(inputChannel, handler2);
context.registerEndpoint("testEndpoint1", endpoint1);
context.registerEndpoint("testEndpoint2", endpoint2);
context.refresh();
inputChannel.send(new GenericMessage<String>("testing"));
latch.await(500, TimeUnit.MILLISECONDS);
assertEquals("both handlers should have been invoked", 0, latch.getCount());
Message<?> message1 = outputChannel1.receive(500);
Message<?> message2 = outputChannel2.receive(500);
context.stop();
assertNotNull("both handlers should have replied to the message", message1);
assertNotNull("both handlers should have replied to the message", message2);
}
use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.
the class MethodInvokingMessageGroupProcessorTests method jdkProxy.
@Test
public void jdkProxy() {
DirectChannel input = new DirectChannel();
QueueChannel output = new QueueChannel();
GreetingService testBean = new GreetingBean();
ProxyFactory proxyFactory = new ProxyFactory(testBean);
proxyFactory.setProxyTargetClass(true);
testBean = (GreetingService) proxyFactory.getProxy();
MethodInvokingMessageGroupProcessor aggregator = new MethodInvokingMessageGroupProcessor(testBean);
AggregatingMessageHandler handler = new AggregatingMessageHandler(aggregator);
handler.setReleaseStrategy(new MessageCountReleaseStrategy());
handler.setOutputChannel(output);
EventDrivenConsumer endpoint = new EventDrivenConsumer(input, handler);
endpoint.start();
Message<?> message = MessageBuilder.withPayload("proxy").setCorrelationId("abc").build();
input.send(message);
assertEquals("hello proxy", output.receive(0).getPayload());
}
Aggregations