use of org.springframework.messaging.PollableChannel 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;
}
use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.
the class IntegrationFlowTests method testGatewayFlow.
@Test
public void testGatewayFlow() throws Exception {
PollableChannel replyChannel = new QueueChannel();
Message<String> message = MessageBuilder.withPayload("foo").setReplyChannel(replyChannel).build();
this.gatewayInput.send(message);
Message<?> receive = replyChannel.receive(2000);
assertNotNull(receive);
assertEquals("From Gateway SubFlow: FOO", receive.getPayload());
assertNull(this.gatewayError.receive(1));
message = MessageBuilder.withPayload("bar").setReplyChannel(replyChannel).build();
this.gatewayInput.send(message);
receive = replyChannel.receive(1);
assertNull(receive);
receive = this.gatewayError.receive(2000);
assertNotNull(receive);
assertThat(receive, instanceOf(ErrorMessage.class));
assertThat(receive.getPayload(), instanceOf(MessageRejectedException.class));
assertThat(((Exception) receive.getPayload()).getMessage(), containsString("' rejected Message"));
}
use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.
the class ManualFlowTests method testDynamicAdapterFlow.
@Test
public void testDynamicAdapterFlow() {
this.integrationFlowContext.registration(new MyFlowAdapter()).register();
PollableChannel resultChannel = this.beanFactory.getBean("flowAdapterOutput", PollableChannel.class);
Message<?> receive = resultChannel.receive(1000);
assertNotNull(receive);
assertEquals("flowAdapterMessage", receive.getPayload());
}
use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.
the class ManualFlowTests method testRoleControl.
@Test
public void testRoleControl() {
String testRole = "bridge";
PollableChannel resultChannel = new QueueChannel();
IntegrationFlowRegistration flowRegistration = this.integrationFlowContext.registration(flow -> flow.bridge(e -> e.role(testRole)).channel(resultChannel)).register();
MessagingTemplate messagingTemplate = this.integrationFlowContext.messagingTemplateFor(flowRegistration.getId());
messagingTemplate.send(new GenericMessage<>("test"));
Message<?> receive = resultChannel.receive(1000);
assertNotNull(receive);
assertEquals("test", receive.getPayload());
this.roleController.stopLifecyclesInRole(testRole);
try {
messagingTemplate.send(new GenericMessage<>("test2"));
} catch (Exception e) {
assertThat(e, instanceOf(MessageDeliveryException.class));
assertThat(e.getMessage(), containsString("Dispatcher has no subscribers for channel"));
}
this.roleController.startLifecyclesInRole(testRole);
messagingTemplate.send(new GenericMessage<>("test2"));
receive = resultChannel.receive(1000);
assertNotNull(receive);
assertEquals("test2", receive.getPayload());
flowRegistration.destroy();
assertTrue(this.roleController.getEndpointsRunningStatus(testRole).isEmpty());
}
use of org.springframework.messaging.PollableChannel in project spring-integration by spring-projects.
the class PollingEndpointErrorHandlingTests method checkExceptionPlacedOnErrorChannel.
@SuppressWarnings("rawtypes")
@Test
public void checkExceptionPlacedOnErrorChannel() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("pollingEndpointErrorHandlingTests.xml", this.getClass());
PollableChannel errorChannel = (PollableChannel) context.getBean("errorChannel");
Message errorMessage = errorChannel.receive(5000);
assertNotNull("No error message received", errorMessage);
assertEquals("Message received was not an ErrorMessage", ErrorMessage.class, errorMessage.getClass());
context.close();
}
Aggregations