use of org.springframework.integration.endpoint.PollingConsumer in project spring-integration by spring-projects.
the class ApplicationContextMessageBusTests method exactlyOneConsumerReceivesPointToPointMessage.
@Test
public void exactlyOneConsumerReceivesPointToPointMessage() {
TestApplicationContext context = TestUtils.createTestApplicationContext();
QueueChannel inputChannel = new QueueChannel();
QueueChannel outputChannel1 = new QueueChannel();
QueueChannel outputChannel2 = new QueueChannel();
AbstractReplyProducingMessageHandler handler1 = new AbstractReplyProducingMessageHandler() {
@Override
public Object handleRequestMessage(Message<?> message) {
return message;
}
};
AbstractReplyProducingMessageHandler handler2 = new AbstractReplyProducingMessageHandler() {
@Override
public Object handleRequestMessage(Message<?> message) {
return message;
}
};
context.registerChannel("input", inputChannel);
context.registerChannel("output1", outputChannel1);
context.registerChannel("output2", outputChannel2);
handler1.setOutputChannel(outputChannel1);
handler2.setOutputChannel(outputChannel2);
PollingConsumer endpoint1 = new PollingConsumer(inputChannel, handler1);
endpoint1.setBeanFactory(mock(BeanFactory.class));
PollingConsumer endpoint2 = new PollingConsumer(inputChannel, handler2);
endpoint2.setBeanFactory(mock(BeanFactory.class));
context.registerEndpoint("testEndpoint1", endpoint1);
context.registerEndpoint("testEndpoint2", endpoint2);
context.refresh();
inputChannel.send(new GenericMessage<String>("testing"));
Message<?> message1 = outputChannel1.receive(10000);
Message<?> message2 = outputChannel2.receive(0);
context.stop();
assertTrue("exactly one message should be null", message1 == null ^ message2 == null);
}
use of org.springframework.integration.endpoint.PollingConsumer in project spring-integration by spring-projects.
the class ApplicationContextMessageBusTests method endpointRegistrationWithInputChannelReference.
@Test
public void endpointRegistrationWithInputChannelReference() {
TestApplicationContext context = TestUtils.createTestApplicationContext();
QueueChannel sourceChannel = new QueueChannel();
QueueChannel targetChannel = new QueueChannel();
context.registerChannel("sourceChannel", sourceChannel);
context.registerChannel("targetChannel", targetChannel);
Message<String> message = MessageBuilder.withPayload("test").setReplyChannelName("targetChannel").build();
sourceChannel.send(message);
AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() {
@Override
public Object handleRequestMessage(Message<?> message) {
return message;
}
};
handler.setBeanFactory(context);
handler.afterPropertiesSet();
PollingConsumer endpoint = new PollingConsumer(sourceChannel, handler);
endpoint.setBeanFactory(mock(BeanFactory.class));
context.registerEndpoint("testEndpoint", endpoint);
context.refresh();
Message<?> result = targetChannel.receive(10000);
assertEquals("test", result.getPayload());
context.stop();
}
use of org.springframework.integration.endpoint.PollingConsumer in project spring-integration by spring-projects.
the class ChannelInterceptorTests method testPollingConsumerWithExecutorInterceptor.
@Test
public void testPollingConsumerWithExecutorInterceptor() throws InterruptedException {
TestUtils.TestApplicationContext testApplicationContext = TestUtils.createTestApplicationContext();
QueueChannel channel = new QueueChannel();
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(2);
final List<Message<?>> messages = new ArrayList<>();
PollingConsumer consumer = new PollingConsumer(channel, message -> {
messages.add(message);
latch1.countDown();
latch2.countDown();
});
testApplicationContext.registerBean("consumer", consumer);
testApplicationContext.refresh();
channel.send(new GenericMessage<>("foo"));
assertTrue(latch1.await(10, TimeUnit.SECONDS));
channel.addInterceptor(new TestExecutorInterceptor());
channel.send(new GenericMessage<>("foo"));
assertTrue(latch2.await(10, TimeUnit.SECONDS));
assertEquals(2, messages.size());
assertEquals("foo", messages.get(0).getPayload());
assertEquals("FOO", messages.get(1).getPayload());
testApplicationContext.close();
}
use of org.springframework.integration.endpoint.PollingConsumer in project spring-integration by spring-projects.
the class JmsOutboundGatewayParserTests method testDefault.
@Test
public void testDefault() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmsOutboundGatewayWithConverter.xml", this.getClass());
PollingConsumer endpoint = (PollingConsumer) context.getBean("jmsGateway");
DirectFieldAccessor accessor = new DirectFieldAccessor(endpoint);
JmsOutboundGateway gateway = (JmsOutboundGateway) accessor.getPropertyValue("handler");
accessor = new DirectFieldAccessor(gateway);
MessageConverter converter = (MessageConverter) accessor.getPropertyValue("messageConverter");
assertTrue("Wrong message converter", converter instanceof StubMessageConverter);
context.close();
}
use of org.springframework.integration.endpoint.PollingConsumer in project spring-integration by spring-projects.
the class MailOutboundChannelAdapterParserTests method adapterWithPollableChannel.
@Test
public void adapterWithPollableChannel() {
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("mailOutboundChannelAdapterParserTests.xml", this.getClass());
PollingConsumer pc = context.getBean("adapterWithPollableChannel", PollingConsumer.class);
QueueChannel pollableChannel = TestUtils.getPropertyValue(pc, "inputChannel", QueueChannel.class);
assertEquals("pollableChannel", pollableChannel.getComponentName());
context.close();
}
Aggregations