Search in sources :

Example 11 with PollableChannel

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;
}
Also used : AbstractEndpoint(org.springframework.integration.endpoint.AbstractEndpoint) PollingConsumer(org.springframework.integration.endpoint.PollingConsumer) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) ReactiveStreamsConsumer(org.springframework.integration.endpoint.ReactiveStreamsConsumer) PollableChannel(org.springframework.messaging.PollableChannel) Publisher(org.reactivestreams.Publisher) SubscribableChannel(org.springframework.messaging.SubscribableChannel) Poller(org.springframework.integration.annotation.Poller)

Example 12 with PollableChannel

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"));
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) PollableChannel(org.springframework.messaging.PollableChannel) Matchers.containsString(org.hamcrest.Matchers.containsString) ErrorMessage(org.springframework.messaging.support.ErrorMessage) MessageRejectedException(org.springframework.integration.MessageRejectedException) Test(org.junit.Test)

Example 13 with PollableChannel

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());
}
Also used : PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 14 with PollableChannel

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());
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) Arrays(java.util.Arrays) Date(java.util.Date) IntegrationFlow(org.springframework.integration.dsl.IntegrationFlow) Autowired(org.springframework.beans.factory.annotation.Autowired) IntegrationFlowAdapter(org.springframework.integration.dsl.IntegrationFlowAdapter) MessagingTemplate(org.springframework.integration.core.MessagingTemplate) Assert.assertThat(org.junit.Assert.assertThat) MessageProducerSupport(org.springframework.integration.endpoint.MessageProducerSupport) Assert.fail(org.junit.Assert.fail) PollableChannel(org.springframework.messaging.PollableChannel) SpringRunner(org.springframework.test.context.junit4.SpringRunner) SmartLifecycleRoleController(org.springframework.integration.support.SmartLifecycleRoleController) MessageProducerSpec(org.springframework.integration.dsl.MessageProducerSpec) EnableIntegration(org.springframework.integration.config.EnableIntegration) MessageProducer(org.springframework.integration.core.MessageProducer) MessageChannel(org.springframework.messaging.MessageChannel) IntegrationFlowRegistration(org.springframework.integration.dsl.context.IntegrationFlowContext.IntegrationFlowRegistration) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Objects(java.util.Objects) Configuration(org.springframework.context.annotation.Configuration) IntegrationFlowDefinition(org.springframework.integration.dsl.IntegrationFlowDefinition) MessageHandler(org.springframework.messaging.MessageHandler) Assert.assertFalse(org.junit.Assert.assertFalse) DisposableBean(org.springframework.beans.factory.DisposableBean) Matchers.containsString(org.hamcrest.Matchers.containsString) QueueChannel(org.springframework.integration.channel.QueueChannel) MessagingException(org.springframework.messaging.MessagingException) BeanCreationNotAllowedException(org.springframework.beans.factory.BeanCreationNotAllowedException) RunWith(org.junit.runner.RunWith) AbstractReplyProducingMessageHandler(org.springframework.integration.handler.AbstractReplyProducingMessageHandler) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IntegrationFlowContext(org.springframework.integration.dsl.context.IntegrationFlowContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) MessageChannels(org.springframework.integration.dsl.MessageChannels) Scope(org.springframework.context.annotation.Scope) Assert.assertSame(org.junit.Assert.assertSame) IntegrationFlows(org.springframework.integration.dsl.IntegrationFlows) Message(org.springframework.messaging.Message) ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException) Flux(reactor.core.publisher.Flux) Assert.assertNull(org.junit.Assert.assertNull) BeanFactory(org.springframework.beans.factory.BeanFactory) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Bean(org.springframework.context.annotation.Bean) GenericMessage(org.springframework.messaging.support.GenericMessage) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) Assert.assertEquals(org.junit.Assert.assertEquals) StandardIntegrationFlow(org.springframework.integration.dsl.StandardIntegrationFlow) MessagingTemplate(org.springframework.integration.core.MessagingTemplate) QueueChannel(org.springframework.integration.channel.QueueChannel) PollableChannel(org.springframework.messaging.PollableChannel) IntegrationFlowRegistration(org.springframework.integration.dsl.context.IntegrationFlowContext.IntegrationFlowRegistration) Matchers.containsString(org.hamcrest.Matchers.containsString) MessagingException(org.springframework.messaging.MessagingException) BeanCreationNotAllowedException(org.springframework.beans.factory.BeanCreationNotAllowedException) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException) Test(org.junit.Test)

Example 15 with PollableChannel

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();
}
Also used : Message(org.springframework.messaging.Message) ErrorMessage(org.springframework.messaging.support.ErrorMessage) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Aggregations

PollableChannel (org.springframework.messaging.PollableChannel)210 Test (org.junit.Test)190 MessageChannel (org.springframework.messaging.MessageChannel)89 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)82 QueueChannel (org.springframework.integration.channel.QueueChannel)52 GenericMessage (org.springframework.messaging.support.GenericMessage)52 Message (org.springframework.messaging.Message)40 BeanFactory (org.springframework.beans.factory.BeanFactory)25 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)20 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)19 MessagingException (org.springframework.messaging.MessagingException)16 SourcePollingChannelAdapter (org.springframework.integration.endpoint.SourcePollingChannelAdapter)13 MessagingTemplate (org.springframework.integration.core.MessagingTemplate)12 ErrorMessage (org.springframework.messaging.support.ErrorMessage)12 Document (org.w3c.dom.Document)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)11 Matchers.containsString (org.hamcrest.Matchers.containsString)11 Date (java.util.Date)10 ArrayList (java.util.ArrayList)9 MessageHistory (org.springframework.integration.history.MessageHistory)9