Search in sources :

Example 11 with PollingConsumer

use of org.springframework.integration.endpoint.PollingConsumer in project spring-integration by spring-projects.

the class ApplicationContextMessageBusTests method consumerSubscribedToErrorChannel.

@Test
public void consumerSubscribedToErrorChannel() throws InterruptedException {
    TestApplicationContext context = TestUtils.createTestApplicationContext();
    QueueChannel errorChannel = new QueueChannel();
    context.registerChannel(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME, errorChannel);
    final CountDownLatch latch = new CountDownLatch(1);
    AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() {

        @Override
        public Object handleRequestMessage(Message<?> message) {
            latch.countDown();
            return null;
        }
    };
    PollingConsumer endpoint = new PollingConsumer(errorChannel, handler);
    endpoint.setBeanFactory(mock(BeanFactory.class));
    context.registerEndpoint("testEndpoint", endpoint);
    context.refresh();
    errorChannel.send(new ErrorMessage(new RuntimeException("test-exception")));
    latch.await(1000, TimeUnit.MILLISECONDS);
    assertEquals("handler should have received error message", 0, latch.getCount());
    context.stop();
}
Also used : PollingConsumer(org.springframework.integration.endpoint.PollingConsumer) QueueChannel(org.springframework.integration.channel.QueueChannel) ErrorMessage(org.springframework.messaging.support.ErrorMessage) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) BeanFactory(org.springframework.beans.factory.BeanFactory) AbstractReplyProducingMessageHandler(org.springframework.integration.handler.AbstractReplyProducingMessageHandler) CountDownLatch(java.util.concurrent.CountDownLatch) ErrorMessage(org.springframework.messaging.support.ErrorMessage) TestApplicationContext(org.springframework.integration.test.util.TestUtils.TestApplicationContext) Test(org.junit.Test)

Example 12 with PollingConsumer

use of org.springframework.integration.endpoint.PollingConsumer in project spring-integration by spring-projects.

the class ByteStreamWritingMessageHandlerTests method initialize.

@Before
public void initialize() {
    stream = new ByteArrayOutputStream();
    handler = new ByteStreamWritingMessageHandler(stream);
    this.channel = new QueueChannel(10);
    this.endpoint = new PollingConsumer(channel, handler);
    scheduler = new ThreadPoolTaskScheduler();
    this.endpoint.setTaskScheduler(scheduler);
    scheduler.afterPropertiesSet();
    trigger.reset();
    endpoint.setTrigger(trigger);
    endpoint.setBeanFactory(mock(BeanFactory.class));
}
Also used : PollingConsumer(org.springframework.integration.endpoint.PollingConsumer) QueueChannel(org.springframework.integration.channel.QueueChannel) BeanFactory(org.springframework.beans.factory.BeanFactory) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) Before(org.junit.Before)

Example 13 with PollingConsumer

use of org.springframework.integration.endpoint.PollingConsumer in project spring-integration by spring-projects.

the class CharacterStreamWritingMessageHandlerTests method initialize.

@Before
public void initialize() {
    writer = new StringWriter();
    handler = new CharacterStreamWritingMessageHandler(writer);
    this.channel = new QueueChannel(10);
    trigger.reset();
    this.endpoint = new PollingConsumer(channel, handler);
    scheduler = new ThreadPoolTaskScheduler();
    this.endpoint.setTaskScheduler(scheduler);
    scheduler.afterPropertiesSet();
    trigger.reset();
    endpoint.setTrigger(trigger);
    endpoint.setBeanFactory(mock(BeanFactory.class));
}
Also used : PollingConsumer(org.springframework.integration.endpoint.PollingConsumer) StringWriter(java.io.StringWriter) QueueChannel(org.springframework.integration.channel.QueueChannel) BeanFactory(org.springframework.beans.factory.BeanFactory) ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) Before(org.junit.Before)

Example 14 with PollingConsumer

use of org.springframework.integration.endpoint.PollingConsumer in project spring-integration by spring-projects.

the class JdbcOutboundGatewayParserTests method testMaxMessagesPerPollIsSet.

@Test
public void testMaxMessagesPerPollIsSet() {
    setUp("JdbcOutboundGatewayWithPoller2Test-context.xml", this.getClass());
    PollingConsumer pollingConsumer = this.context.getBean(PollingConsumer.class);
    DirectFieldAccessor accessor = new DirectFieldAccessor(pollingConsumer);
    Object source = accessor.getPropertyValue("handler");
    accessor = new DirectFieldAccessor(source);
    // JdbcPollingChannelAdapter
    source = accessor.getPropertyValue("poller");
    accessor = new DirectFieldAccessor(source);
    Integer maxRowsPerPoll = (Integer) accessor.getPropertyValue("maxRowsPerPoll");
    assertEquals("maxRowsPerPoll should default to 10", Integer.valueOf(10), maxRowsPerPoll);
}
Also used : PollingConsumer(org.springframework.integration.endpoint.PollingConsumer) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 15 with PollingConsumer

use of org.springframework.integration.endpoint.PollingConsumer in project spring-integration by spring-projects.

the class JdbcOutboundGatewayParserTests method testReplyTimeoutIsSet.

@Test
public void testReplyTimeoutIsSet() {
    setUp("JdbcOutboundGatewayWithPollerTest-context.xml", getClass());
    PollingConsumer outboundGateway = this.context.getBean("jdbcOutboundGateway", PollingConsumer.class);
    DirectFieldAccessor accessor = new DirectFieldAccessor(outboundGateway);
    Object source = accessor.getPropertyValue("handler");
    accessor = new DirectFieldAccessor(source);
    source = accessor.getPropertyValue("messagingTemplate");
    MessagingTemplate messagingTemplate = (MessagingTemplate) source;
    accessor = new DirectFieldAccessor(messagingTemplate);
    Long sendTimeout = (Long) accessor.getPropertyValue("sendTimeout");
    assertEquals("Wrong sendTimeout", Long.valueOf(444L), sendTimeout);
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) PollingConsumer(org.springframework.integration.endpoint.PollingConsumer) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Aggregations

PollingConsumer (org.springframework.integration.endpoint.PollingConsumer)25 Test (org.junit.Test)17 QueueChannel (org.springframework.integration.channel.QueueChannel)12 Message (org.springframework.messaging.Message)9 BeanFactory (org.springframework.beans.factory.BeanFactory)7 GenericMessage (org.springframework.messaging.support.GenericMessage)7 AbstractReplyProducingMessageHandler (org.springframework.integration.handler.AbstractReplyProducingMessageHandler)6 MessageChannel (org.springframework.messaging.MessageChannel)6 PollableChannel (org.springframework.messaging.PollableChannel)6 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)5 ErrorMessage (org.springframework.messaging.support.ErrorMessage)5 AbstractEndpoint (org.springframework.integration.endpoint.AbstractEndpoint)4 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)4 TestApplicationContext (org.springframework.integration.test.util.TestUtils.TestApplicationContext)4 SubscribableChannel (org.springframework.messaging.SubscribableChannel)4 ReactiveStreamsConsumer (org.springframework.integration.endpoint.ReactiveStreamsConsumer)3 MessagingException (org.springframework.messaging.MessagingException)3 PeriodicTrigger (org.springframework.scheduling.support.PeriodicTrigger)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2