Search in sources :

Example 1 with EventDrivenConsumer

use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.

the class MessagingGatewaySupport method registerReplyMessageCorrelatorIfNecessary.

protected void registerReplyMessageCorrelatorIfNecessary() {
    MessageChannel replyChannel = getReplyChannel();
    if (replyChannel != null && this.replyMessageCorrelator == null) {
        boolean shouldStartCorrelator;
        synchronized (this.replyMessageCorrelatorMonitor) {
            if (this.replyMessageCorrelator != null) {
                return;
            }
            AbstractEndpoint correlator;
            BridgeHandler handler = new BridgeHandler();
            if (getBeanFactory() != null) {
                handler.setBeanFactory(getBeanFactory());
            }
            handler.afterPropertiesSet();
            if (replyChannel instanceof SubscribableChannel) {
                correlator = new EventDrivenConsumer((SubscribableChannel) replyChannel, handler);
            } else if (replyChannel instanceof PollableChannel) {
                PollingConsumer endpoint = new PollingConsumer((PollableChannel) replyChannel, handler);
                endpoint.setBeanFactory(getBeanFactory());
                endpoint.setReceiveTimeout(this.replyTimeout);
                endpoint.afterPropertiesSet();
                correlator = endpoint;
            } else if (replyChannel instanceof ReactiveStreamsSubscribableChannel) {
                ReactiveStreamsConsumer endpoint = new ReactiveStreamsConsumer(replyChannel, (Subscriber<Message<?>>) handler);
                endpoint.afterPropertiesSet();
                correlator = endpoint;
            } else {
                throw new MessagingException("Unsupported 'replyChannel' type [" + replyChannel.getClass() + "]." + "SubscribableChannel or PollableChannel type are supported.");
            }
            this.replyMessageCorrelator = correlator;
            shouldStartCorrelator = true;
        }
        if (shouldStartCorrelator && isRunning()) {
            if (isRunning()) {
                this.replyMessageCorrelator.start();
            }
        }
    }
}
Also used : AbstractEndpoint(org.springframework.integration.endpoint.AbstractEndpoint) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) PollingConsumer(org.springframework.integration.endpoint.PollingConsumer) ReactiveStreamsConsumer(org.springframework.integration.endpoint.ReactiveStreamsConsumer) MessageChannel(org.springframework.messaging.MessageChannel) ErrorMessage(org.springframework.messaging.support.ErrorMessage) Message(org.springframework.messaging.Message) BridgeHandler(org.springframework.integration.handler.BridgeHandler) MessagingException(org.springframework.messaging.MessagingException) PollableChannel(org.springframework.messaging.PollableChannel) ReactiveStreamsSubscribableChannel(org.springframework.integration.channel.ReactiveStreamsSubscribableChannel) SubscribableChannel(org.springframework.messaging.SubscribableChannel) ReactiveStreamsSubscribableChannel(org.springframework.integration.channel.ReactiveStreamsSubscribableChannel)

Example 2 with EventDrivenConsumer

use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.

the class AbstractMethodAnnotationPostProcessor method doCreateEndpoint.

protected AbstractEndpoint doCreateEndpoint(MessageHandler handler, MessageChannel inputChannel, List<Annotation> annotations) {
    AbstractEndpoint endpoint;
    if (inputChannel instanceof PollableChannel) {
        PollingConsumer pollingConsumer = new PollingConsumer((PollableChannel) inputChannel, handler);
        configurePollingEndpoint(pollingConsumer, annotations);
        endpoint = pollingConsumer;
    } else {
        Poller[] pollers = MessagingAnnotationUtils.resolveAttribute(annotations, "poller", Poller[].class);
        Assert.state(ObjectUtils.isEmpty(pollers), "A '@Poller' should not be specified for Annotation-based " + "endpoint, since '" + inputChannel + "' is a SubscribableChannel (not pollable).");
        if (inputChannel instanceof Publisher) {
            endpoint = new ReactiveStreamsConsumer(inputChannel, handler);
        } else {
            endpoint = new EventDrivenConsumer((SubscribableChannel) inputChannel, handler);
        }
    }
    return endpoint;
}
Also used : AbstractEndpoint(org.springframework.integration.endpoint.AbstractEndpoint) PollingConsumer(org.springframework.integration.endpoint.PollingConsumer) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) ReactiveStreamsConsumer(org.springframework.integration.endpoint.ReactiveStreamsConsumer) PollableChannel(org.springframework.messaging.PollableChannel) Publisher(org.reactivestreams.Publisher) SubscribableChannel(org.springframework.messaging.SubscribableChannel) Poller(org.springframework.integration.annotation.Poller)

Example 3 with EventDrivenConsumer

use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.

the class MessageFilterTests method filterAcceptsWithChannels.

@Test
public void filterAcceptsWithChannels() {
    DirectChannel inputChannel = new DirectChannel();
    QueueChannel outputChannel = new QueueChannel();
    MessageFilter filter = new MessageFilter(message -> true);
    filter.setOutputChannel(outputChannel);
    EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, filter);
    endpoint.start();
    Message<?> message = new GenericMessage<String>("test");
    assertTrue(inputChannel.send(message));
    Message<?> reply = outputChannel.receive(0);
    assertNotNull(reply);
    assertEquals(message.getPayload(), reply.getPayload());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) QueueChannel(org.springframework.integration.channel.QueueChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) Test(org.junit.Test)

Example 4 with EventDrivenConsumer

use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.

the class FilterAnnotationPostProcessorTests method filterAnnotationWithAdviceCollectionTwice.

@Test
public void filterAnnotationWithAdviceCollectionTwice() {
    TestAdvice advice1 = new TestAdvice();
    TestAdvice advice2 = new TestAdvice();
    context.registerBean("adviceChain1", new TestAdvice[] { advice1, advice2 });
    TestAdvice advice3 = new TestAdvice();
    TestAdvice advice4 = new TestAdvice();
    context.registerBean("adviceChain2", new TestAdvice[] { advice3, advice4 });
    testValidFilter(new TestFilterWithAdviceDiscardWithinTwice());
    EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("testFilter.filter.filter");
    List<?> adviceList = TestUtils.getPropertyValue(endpoint, "handler.adviceChain", List.class);
    assertEquals(4, adviceList.size());
    assertSame(advice1, adviceList.get(0));
    assertSame(advice2, adviceList.get(1));
    assertSame(advice3, adviceList.get(2));
    assertSame(advice4, adviceList.get(3));
    assertTrue(TestUtils.getPropertyValue(endpoint, "handler.postProcessWithinAdvice", Boolean.class));
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) Test(org.junit.Test)

Example 5 with EventDrivenConsumer

use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.

the class FilterAnnotationPostProcessorTests method filterAnnotationWithAdviceDiscardWithin.

@Test
public void filterAnnotationWithAdviceDiscardWithin() {
    TestAdvice advice = new TestAdvice();
    context.registerBean("adviceChain", 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)

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