use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.
the class ScatterGatherHandler method doInit.
@Override
protected void doInit() {
if (this.gatherChannel == null) {
this.gatherChannel = new FixedSubscriberChannel(this.gatherer);
} else {
if (this.gatherChannel instanceof SubscribableChannel) {
this.gatherEndpoint = new EventDrivenConsumer((SubscribableChannel) this.gatherChannel, this.gatherer);
} else if (this.gatherChannel instanceof PollableChannel) {
this.gatherEndpoint = new PollingConsumer((PollableChannel) this.gatherChannel, this.gatherer);
((PollingConsumer) this.gatherEndpoint).setReceiveTimeout(this.gatherTimeout);
} else {
throw new MessagingException("Unsupported 'replyChannel' type [" + this.gatherChannel.getClass() + "]." + "SubscribableChannel or PollableChannel type are supported.");
}
this.gatherEndpoint.setBeanFactory(this.getBeanFactory());
this.gatherEndpoint.afterPropertiesSet();
}
((MessageProducer) this.gatherer).setOutputChannel(new FixedSubscriberChannel(message -> {
MessageHeaders headers = message.getHeaders();
if (headers.containsKey(GATHER_RESULT_CHANNEL)) {
Object gatherResultChannel = headers.get(GATHER_RESULT_CHANNEL);
if (gatherResultChannel instanceof MessageChannel) {
messagingTemplate.send((MessageChannel) gatherResultChannel, message);
} else if (gatherResultChannel instanceof String) {
messagingTemplate.send((String) gatherResultChannel, message);
}
} else {
throw new MessageDeliveryException(message, "The 'gatherResultChannel' header is required to delivery gather result.");
}
}));
this.replyChannelRegistry = getBeanFactory().getBean(IntegrationContextUtils.INTEGRATION_HEADER_CHANNEL_REGISTRY_BEAN_NAME, HeaderChannelRegistry.class);
}
use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.
the class DirectChannelTests method testChannelCreationWithBeanDefinitionOverrideTrue.
// See INT-2434
@Test
public void testChannelCreationWithBeanDefinitionOverrideTrue() throws Exception {
ClassPathXmlApplicationContext parentContext = new ClassPathXmlApplicationContext("parent-config.xml", this.getClass());
MessageChannel parentChannelA = parentContext.getBean("parentChannelA", MessageChannel.class);
MessageChannel parentChannelB = parentContext.getBean("parentChannelB", MessageChannel.class);
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
context.setAllowBeanDefinitionOverriding(false);
context.setConfigLocations(new String[] { "classpath:org/springframework/integration/channel/channel-override-config.xml" });
context.setParent(parentContext);
Method method = ReflectionUtils.findMethod(ClassPathXmlApplicationContext.class, "obtainFreshBeanFactory");
method.setAccessible(true);
method.invoke(context);
assertFalse(context.containsBean("channelA"));
assertFalse(context.containsBean("channelB"));
assertTrue(context.containsBean("channelC"));
assertTrue(context.containsBean("channelD"));
context.refresh();
PublishSubscribeChannel channelEarly = context.getBean("channelEarly", PublishSubscribeChannel.class);
assertTrue(context.containsBean("channelA"));
assertTrue(context.containsBean("channelB"));
assertTrue(context.containsBean("channelC"));
assertTrue(context.containsBean("channelD"));
EventDrivenConsumer consumerA = context.getBean("serviceA", EventDrivenConsumer.class);
assertEquals(context.getBean("channelA"), TestUtils.getPropertyValue(consumerA, "inputChannel"));
assertEquals(context.getBean("channelB"), TestUtils.getPropertyValue(consumerA, "handler.outputChannel"));
EventDrivenConsumer consumerB = context.getBean("serviceB", EventDrivenConsumer.class);
assertEquals(context.getBean("channelB"), TestUtils.getPropertyValue(consumerB, "inputChannel"));
assertEquals(context.getBean("channelC"), TestUtils.getPropertyValue(consumerB, "handler.outputChannel"));
EventDrivenConsumer consumerC = context.getBean("serviceC", EventDrivenConsumer.class);
assertEquals(context.getBean("channelC"), TestUtils.getPropertyValue(consumerC, "inputChannel"));
assertEquals(context.getBean("channelD"), TestUtils.getPropertyValue(consumerC, "handler.outputChannel"));
EventDrivenConsumer consumerD = context.getBean("serviceD", EventDrivenConsumer.class);
assertEquals(parentChannelA, TestUtils.getPropertyValue(consumerD, "inputChannel"));
assertEquals(parentChannelB, TestUtils.getPropertyValue(consumerD, "handler.outputChannel"));
EventDrivenConsumer consumerE = context.getBean("serviceE", EventDrivenConsumer.class);
assertEquals(parentChannelB, TestUtils.getPropertyValue(consumerE, "inputChannel"));
EventDrivenConsumer consumerF = context.getBean("serviceF", EventDrivenConsumer.class);
assertEquals(channelEarly, TestUtils.getPropertyValue(consumerF, "inputChannel"));
}
use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.
the class AggregatorParserTests method testAggregatorWithPojoReleaseStrategy.
@Test
@SuppressWarnings("unchecked")
public void testAggregatorWithPojoReleaseStrategy() {
MessageChannel input = this.context.getBean("aggregatorWithPojoReleaseStrategyInput", MessageChannel.class);
EventDrivenConsumer endpoint = this.context.getBean("aggregatorWithPojoReleaseStrategy", EventDrivenConsumer.class);
ReleaseStrategy releaseStrategy = TestUtils.getPropertyValue(endpoint, "handler.releaseStrategy", ReleaseStrategy.class);
Assert.assertTrue(releaseStrategy instanceof MethodInvokingReleaseStrategy);
MessagingMethodInvokerHelper<Long> methodInvokerHelper = TestUtils.getPropertyValue(releaseStrategy, "adapter.delegate", MessagingMethodInvokerHelper.class);
Object handlerMethods = TestUtils.getPropertyValue(methodInvokerHelper, "handlerMethods");
assertNull(handlerMethods);
Object handlerMethod = TestUtils.getPropertyValue(methodInvokerHelper, "handlerMethod");
assertTrue(handlerMethod.toString().contains("checkCompleteness"));
input.send(createMessage(1L, "correlationId", 4, 0, null));
input.send(createMessage(2L, "correlationId", 4, 1, null));
input.send(createMessage(3L, "correlationId", 4, 2, null));
PollableChannel outputChannel = (PollableChannel) context.getBean("outputChannel");
Message<?> reply = outputChannel.receive(0);
Assert.assertNull(reply);
input.send(createMessage(5L, "correlationId", 4, 3, null));
reply = outputChannel.receive(0);
Assert.assertNotNull(reply);
assertEquals(11L, reply.getPayload());
}
use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.
the class AggregatorParserTests method testPropertyAssignment.
@Test
public void testPropertyAssignment() throws Exception {
EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("completelyDefinedAggregator");
ReleaseStrategy releaseStrategy = (ReleaseStrategy) context.getBean("releaseStrategy");
CorrelationStrategy correlationStrategy = (CorrelationStrategy) context.getBean("correlationStrategy");
MessageChannel outputChannel = (MessageChannel) context.getBean("outputChannel");
MessageChannel discardChannel = (MessageChannel) context.getBean("discardChannel");
Object consumer = new DirectFieldAccessor(endpoint).getPropertyValue("handler");
assertThat(consumer, is(instanceOf(AggregatingMessageHandler.class)));
DirectFieldAccessor accessor = new DirectFieldAccessor(consumer);
Object handlerMethods = new DirectFieldAccessor(new DirectFieldAccessor(new DirectFieldAccessor(accessor.getPropertyValue("outputProcessor")).getPropertyValue("processor")).getPropertyValue("delegate")).getPropertyValue("handlerMethods");
assertNull(handlerMethods);
Object handlerMethod = new DirectFieldAccessor(new DirectFieldAccessor(new DirectFieldAccessor(accessor.getPropertyValue("outputProcessor")).getPropertyValue("processor")).getPropertyValue("delegate")).getPropertyValue("handlerMethod");
assertTrue(handlerMethod.toString().contains("createSingleMessageFromGroup"));
assertEquals("The AggregatorEndpoint is not injected with the appropriate ReleaseStrategy instance", releaseStrategy, accessor.getPropertyValue("releaseStrategy"));
assertEquals("The AggregatorEndpoint is not injected with the appropriate CorrelationStrategy instance", correlationStrategy, accessor.getPropertyValue("correlationStrategy"));
assertEquals("The AggregatorEndpoint is not injected with the appropriate output channel", outputChannel, accessor.getPropertyValue("outputChannel"));
assertEquals("The AggregatorEndpoint is not injected with the appropriate discard channel", discardChannel, accessor.getPropertyValue("discardChannel"));
assertEquals("The AggregatorEndpoint is not set with the appropriate timeout value", 86420000L, TestUtils.getPropertyValue(consumer, "messagingTemplate.sendTimeout"));
assertEquals("The AggregatorEndpoint is not configured with the appropriate 'send partial results on timeout' flag", true, accessor.getPropertyValue("sendPartialResultOnExpiry"));
assertFalse(TestUtils.getPropertyValue(consumer, "expireGroupsUponTimeout", Boolean.class));
assertTrue(TestUtils.getPropertyValue(consumer, "expireGroupsUponCompletion", Boolean.class));
assertEquals(123L, TestUtils.getPropertyValue(consumer, "minimumTimeoutForEmptyGroups"));
assertEquals("456", TestUtils.getPropertyValue(consumer, "groupTimeoutExpression", Expression.class).getExpressionString());
assertSame(this.context.getBean(LockRegistry.class), TestUtils.getPropertyValue(consumer, "lockRegistry"));
assertSame(this.context.getBean("scheduler"), TestUtils.getPropertyValue(consumer, "taskScheduler"));
assertSame(this.context.getBean("store"), TestUtils.getPropertyValue(consumer, "messageStore"));
assertEquals(5, TestUtils.getPropertyValue(consumer, "order"));
assertNotNull(TestUtils.getPropertyValue(consumer, "forceReleaseAdviceChain"));
}
use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.
the class ChannelAdapterParserTests method methodInvokingConsumer.
@Test
public void methodInvokingConsumer() {
String beanName = "methodInvokingConsumer";
Object channel = this.applicationContext.getBean(beanName);
assertTrue(channel instanceof DirectChannel);
BeanFactoryChannelResolver channelResolver = new BeanFactoryChannelResolver(this.applicationContext);
assertNotNull(channelResolver.resolveDestination(beanName));
Object adapter = this.applicationContext.getBean(beanName + ".adapter");
assertNotNull(adapter);
assertTrue(adapter instanceof EventDrivenConsumer);
TestBean testBean = (TestBean) this.applicationContext.getBean("testBean");
assertNull(testBean.getMessage());
Message<?> message = new GenericMessage<String>("consumer test");
assertTrue(((MessageChannel) channel).send(message));
assertNotNull(testBean.getMessage());
assertEquals("consumer test", testBean.getMessage());
}
Aggregations