Search in sources :

Example 6 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)

Example 7 with EventDrivenConsumer

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

the class FilterAnnotationPostProcessorTests method filterAnnotationWithAdviceDiscardWithout.

@Test
public void filterAnnotationWithAdviceDiscardWithout() {
    TestAdvice advice = new TestAdvice();
    context.registerBean("adviceChain", advice);
    testValidFilter(new TestFilterWithAdviceDiscardWithout());
    EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("testFilter.filter.filter");
    assertSame(advice, TestUtils.getPropertyValue(endpoint, "handler.adviceChain", List.class).get(0));
    assertFalse(TestUtils.getPropertyValue(endpoint, "handler.postProcessWithinAdvice", Boolean.class));
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) Test(org.junit.Test)

Example 8 with EventDrivenConsumer

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

the class InnerDefinitionHandlerAwareEndpointParserTests method testSplitterDefinitionSuccess.

private void testSplitterDefinitionSuccess(String configProperty) {
    ApplicationContext ac = this.bootStrap(configProperty);
    EventDrivenConsumer splitter = (EventDrivenConsumer) ac.getBean("testSplitter");
    Assert.assertNotNull(splitter);
    MessageBuilder<String[]> inChannelMessageBuilder = MessageBuilder.withPayload(new String[] { "One", "Two" });
    Message<String[]> inMessage = inChannelMessageBuilder.build();
    MessageChannel inChannel = (MessageChannel) ac.getBean("inChannel");
    inChannel.send(inMessage);
    PollableChannel outChannel = (PollableChannel) ac.getBean("outChannel");
    Assert.assertTrue(outChannel.receive().getPayload() instanceof String);
    outChannel = (PollableChannel) ac.getBean("outChannel");
    Assert.assertTrue(outChannel.receive().getPayload() instanceof String);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) MessageChannel(org.springframework.messaging.MessageChannel) PollableChannel(org.springframework.messaging.PollableChannel)

Example 9 with EventDrivenConsumer

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

the class InnerDefinitionHandlerAwareEndpointParserTests method testRouterDefinitionSuccess.

private void testRouterDefinitionSuccess(String configProperty) {
    ApplicationContext ac = this.bootStrap(configProperty);
    EventDrivenConsumer splitter = (EventDrivenConsumer) ac.getBean("testRouter");
    Assert.assertNotNull(splitter);
    MessageBuilder<String> inChannelMessageBuilder = MessageBuilder.withPayload("1");
    Message<String> inMessage = inChannelMessageBuilder.build();
    DirectChannel inChannel = (DirectChannel) ac.getBean("inChannel");
    inChannel.send(inMessage);
    PollableChannel channel1 = (PollableChannel) ac.getBean("channel1");
    Assert.assertTrue(channel1.receive().getPayload().equals("1"));
    inChannelMessageBuilder = MessageBuilder.withPayload("2");
    inMessage = inChannelMessageBuilder.build();
    inChannel.send(inMessage);
    PollableChannel channel2 = (PollableChannel) ac.getBean("channel2");
    Assert.assertTrue(channel2.receive().getPayload().equals("2"));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) DirectChannel(org.springframework.integration.channel.DirectChannel) PollableChannel(org.springframework.messaging.PollableChannel)

Example 10 with EventDrivenConsumer

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

the class ConsumerEndpointFactoryBean method initializeEndpoint.

@SuppressWarnings("unchecked")
private void initializeEndpoint() throws Exception {
    synchronized (this.initializationMonitor) {
        if (this.initialized) {
            return;
        }
        MessageChannel channel = null;
        if (StringUtils.hasText(this.inputChannelName)) {
            channel = this.channelResolver.resolveDestination(this.inputChannelName);
        }
        if (this.inputChannel != null) {
            channel = this.inputChannel;
        }
        Assert.state(channel != null, "one of inputChannelName or inputChannel is required");
        if (channel instanceof SubscribableChannel) {
            Assert.isNull(this.pollerMetadata, "A poller should not be specified for endpoint '" + this.beanName + "', since '" + channel + "' is a SubscribableChannel (not pollable).");
            this.endpoint = new EventDrivenConsumer((SubscribableChannel) channel, this.handler);
            if (logger.isWarnEnabled() && Boolean.FALSE.equals(this.autoStartup) && channel instanceof FixedSubscriberChannel) {
                logger.warn("'autoStartup=\"false\"' has no effect when using a FixedSubscriberChannel");
            }
        } else if (channel instanceof PollableChannel) {
            PollingConsumer pollingConsumer = new PollingConsumer((PollableChannel) channel, this.handler);
            if (this.pollerMetadata == null) {
                this.pollerMetadata = PollerMetadata.getDefaultPollerMetadata(this.beanFactory);
                Assert.notNull(this.pollerMetadata, "No poller has been defined for endpoint '" + this.beanName + "', and no default poller is available within the context.");
            }
            pollingConsumer.setTaskExecutor(this.pollerMetadata.getTaskExecutor());
            pollingConsumer.setTrigger(this.pollerMetadata.getTrigger());
            pollingConsumer.setAdviceChain(this.pollerMetadata.getAdviceChain());
            pollingConsumer.setMaxMessagesPerPoll(this.pollerMetadata.getMaxMessagesPerPoll());
            pollingConsumer.setErrorHandler(this.pollerMetadata.getErrorHandler());
            pollingConsumer.setReceiveTimeout(this.pollerMetadata.getReceiveTimeout());
            pollingConsumer.setTransactionSynchronizationFactory(this.pollerMetadata.getTransactionSynchronizationFactory());
            pollingConsumer.setBeanClassLoader(this.beanClassLoader);
            pollingConsumer.setBeanFactory(this.beanFactory);
            this.endpoint = pollingConsumer;
        } else {
            this.endpoint = new ReactiveStreamsConsumer(channel, this.handler);
        }
        this.endpoint.setBeanName(this.beanName);
        this.endpoint.setBeanFactory(this.beanFactory);
        if (this.autoStartup != null) {
            this.endpoint.setAutoStartup(this.autoStartup);
        }
        int phase = this.phase;
        if (!this.isPhaseSet && this.endpoint instanceof PollingConsumer) {
            phase = Integer.MAX_VALUE / 2;
        }
        this.endpoint.setPhase(phase);
        this.endpoint.setRole(this.role);
        if (this.taskScheduler != null) {
            this.endpoint.setTaskScheduler(this.taskScheduler);
        }
        this.endpoint.afterPropertiesSet();
        this.initialized = true;
    }
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) PollingConsumer(org.springframework.integration.endpoint.PollingConsumer) ReactiveStreamsConsumer(org.springframework.integration.endpoint.ReactiveStreamsConsumer) MessageChannel(org.springframework.messaging.MessageChannel) PollableChannel(org.springframework.messaging.PollableChannel) SubscribableChannel(org.springframework.messaging.SubscribableChannel) AbstractEndpoint(org.springframework.integration.endpoint.AbstractEndpoint) FixedSubscriberChannel(org.springframework.integration.channel.FixedSubscriberChannel)

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