Search in sources :

Example 51 with EventDrivenConsumer

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));
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) Test(org.junit.Test)

Example 52 with EventDrivenConsumer

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);
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Iterator(java.util.Iterator) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) UUID(java.util.UUID) MessageHeaders(org.springframework.messaging.MessageHeaders) Splitter(org.springframework.integration.annotation.Splitter) Assert.assertThat(org.junit.Assert.assertThat) MessageBuilder(org.springframework.integration.support.MessageBuilder) List(java.util.List) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) Matchers.is(org.hamcrest.Matchers.is) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) DirectChannel(org.springframework.integration.channel.DirectChannel) Collections(java.util.Collections) Before(org.junit.Before) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) DirectChannel(org.springframework.integration.channel.DirectChannel) Test(org.junit.Test)

Example 53 with EventDrivenConsumer

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));
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Iterator(java.util.Iterator) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) UUID(java.util.UUID) MessageHeaders(org.springframework.messaging.MessageHeaders) Splitter(org.springframework.integration.annotation.Splitter) Assert.assertThat(org.junit.Assert.assertThat) MessageBuilder(org.springframework.integration.support.MessageBuilder) List(java.util.List) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) Matchers.is(org.hamcrest.Matchers.is) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) DirectChannel(org.springframework.integration.channel.DirectChannel) Collections(java.util.Collections) Before(org.junit.Before) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) DirectChannel(org.springframework.integration.channel.DirectChannel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 54 with EventDrivenConsumer

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);
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) PublishSubscribeChannel(org.springframework.integration.channel.PublishSubscribeChannel) QueueChannel(org.springframework.integration.channel.QueueChannel) ErrorMessage(org.springframework.messaging.support.ErrorMessage) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) AbstractReplyProducingMessageHandler(org.springframework.integration.handler.AbstractReplyProducingMessageHandler) CountDownLatch(java.util.concurrent.CountDownLatch) TestApplicationContext(org.springframework.integration.test.util.TestUtils.TestApplicationContext) Test(org.junit.Test)

Example 55 with EventDrivenConsumer

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());
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) QueueChannel(org.springframework.integration.channel.QueueChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) ProxyFactory(org.springframework.aop.framework.ProxyFactory) Test(org.junit.Test)

Aggregations

EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)106 Test (org.junit.Test)96 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)29 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)27 DirectChannel (org.springframework.integration.channel.DirectChannel)19 PollableChannel (org.springframework.messaging.PollableChannel)19 GenericMessage (org.springframework.messaging.support.GenericMessage)18 MessageChannel (org.springframework.messaging.MessageChannel)16 QueueChannel (org.springframework.integration.channel.QueueChannel)14 MessageHandler (org.springframework.messaging.MessageHandler)12 List (java.util.List)9 ResequencingMessageHandler (org.springframework.integration.aggregator.ResequencingMessageHandler)9 Message (org.springframework.messaging.Message)8 SmartLifecycle (org.springframework.context.SmartLifecycle)6 JmsOutboundGateway (org.springframework.integration.jms.JmsOutboundGateway)6 MongoDbAvailable (org.springframework.integration.mongodb.rules.MongoDbAvailable)6 SmartLifecycleRoleController (org.springframework.integration.support.SmartLifecycleRoleController)6 MethodInvokingReleaseStrategy (org.springframework.integration.aggregator.MethodInvokingReleaseStrategy)5 ReleaseStrategy (org.springframework.integration.aggregator.ReleaseStrategy)5 AbstractReplyProducingMessageHandler (org.springframework.integration.handler.AbstractReplyProducingMessageHandler)5