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));
}
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));
}
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);
}
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"));
}
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;
}
}
Aggregations