Search in sources :

Example 46 with SourcePollingChannelAdapter

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

the class ChannelAdapterParserTests method methodInvokingSourceWithSendTimeout.

@Test
public void methodInvokingSourceWithSendTimeout() throws Exception {
    String beanName = "methodInvokingSourceWithTimeout";
    SourcePollingChannelAdapter adapter = this.applicationContext.getBean(beanName, SourcePollingChannelAdapter.class);
    assertNotNull(adapter);
    long sendTimeout = TestUtils.getPropertyValue(adapter, "messagingTemplate.sendTimeout", Long.class);
    assertEquals(999, sendTimeout);
}
Also used : SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Test(org.junit.Test)

Example 47 with SourcePollingChannelAdapter

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

the class ChannelAdapterParserTests method methodInvokingSource.

@Test
public void methodInvokingSource() {
    String beanName = "methodInvokingSource";
    PollableChannel channel = (PollableChannel) this.applicationContext.getBean("queueChannel");
    TestBean testBean = (TestBean) this.applicationContext.getBean("testBean");
    testBean.store("source test");
    Object adapter = this.applicationContext.getBean(beanName);
    assertNotNull(adapter);
    assertTrue(adapter instanceof SourcePollingChannelAdapter);
    ((SourcePollingChannelAdapter) adapter).start();
    Message<?> message = channel.receive(10000);
    assertNotNull(message);
    assertEquals("source test", testBean.getMessage());
    ((SourcePollingChannelAdapter) adapter).stop();
}
Also used : PollableChannel(org.springframework.messaging.PollableChannel) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Test(org.junit.Test)

Example 48 with SourcePollingChannelAdapter

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

the class ChannelAdapterParserTests method testMessageSourceRef.

@Test
public void testMessageSourceRef() {
    PollableChannel channel = this.applicationContext.getBean("messageSourceRefChannel", PollableChannel.class);
    Message<?> message = channel.receive(5000);
    assertNotNull(message);
    assertEquals("test", message.getPayload());
    MessageSource<?> testMessageSource = this.applicationContext.getBean("testMessageSource", MessageSource.class);
    SourcePollingChannelAdapter adapterWithMessageSourceRef = this.applicationContext.getBean("adapterWithMessageSourceRef", SourcePollingChannelAdapter.class);
    MessageSource<?> source = TestUtils.getPropertyValue(adapterWithMessageSourceRef, "source", MessageSource.class);
    assertSame(testMessageSource, source);
}
Also used : PollableChannel(org.springframework.messaging.PollableChannel) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Test(org.junit.Test)

Example 49 with SourcePollingChannelAdapter

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

the class PollerWithErrorChannelTests method testWithErrorChannelAsHeader.

@Test
public /*
	 * Although adapter configuration specifies header-enricher pointing to the 'eChannel' as errorChannel
	 * the ErrorMessage will still be forwarded to the 'errorChannel' since exception occurs on
	 * receive() and not on send()
	 */
void testWithErrorChannelAsHeader() throws Exception {
    ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml", this.getClass());
    SourcePollingChannelAdapter adapter = ac.getBean("withErrorHeader", SourcePollingChannelAdapter.class);
    SubscribableChannel errorChannel = ac.getBean("errorChannel", SubscribableChannel.class);
    MessageHandler handler = mock(MessageHandler.class);
    errorChannel.subscribe(handler);
    adapter.start();
    Thread.sleep(1000);
    verify(handler, atLeastOnce()).handleMessage(Mockito.any(Message.class));
    adapter.stop();
    ac.close();
}
Also used : MessageHandler(org.springframework.messaging.MessageHandler) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) SubscribableChannel(org.springframework.messaging.SubscribableChannel) Test(org.junit.Test)

Example 50 with SourcePollingChannelAdapter

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

the class SourcePollingChannelAdapterFactoryBean method initializeAdapter.

private void initializeAdapter() {
    synchronized (this.initializationMonitor) {
        if (this.initialized) {
            return;
        }
        Assert.notNull(this.source, "source is required");
        if (StringUtils.hasText(this.outputChannelName)) {
            Assert.isNull(this.outputChannel, "'outputChannelName' and 'outputChannel' are mutually exclusive.");
            this.outputChannel = this.channelResolver.resolveDestination(this.outputChannelName);
        }
        Assert.notNull(this.outputChannel, "outputChannel is required");
        SourcePollingChannelAdapter spca = new SourcePollingChannelAdapter();
        spca.setSource(this.source);
        spca.setOutputChannel(this.outputChannel);
        if (this.pollerMetadata == null) {
            this.pollerMetadata = PollerMetadata.getDefaultPollerMetadata(this.beanFactory);
            Assert.notNull(this.pollerMetadata, "No poller has been defined for channel-adapter '" + this.beanName + "', and no default poller is available within the context.");
        }
        if (this.pollerMetadata.getMaxMessagesPerPoll() == Integer.MIN_VALUE) {
            // the default is 1 since a source might return
            // a non-null and non-interruptible value every time it is invoked
            this.pollerMetadata.setMaxMessagesPerPoll(1);
        }
        spca.setMaxMessagesPerPoll(this.pollerMetadata.getMaxMessagesPerPoll());
        if (this.sendTimeout != null) {
            spca.setSendTimeout(this.sendTimeout);
        }
        spca.setTaskExecutor(this.pollerMetadata.getTaskExecutor());
        spca.setAdviceChain(this.pollerMetadata.getAdviceChain());
        spca.setTrigger(this.pollerMetadata.getTrigger());
        spca.setErrorHandler(this.pollerMetadata.getErrorHandler());
        spca.setBeanClassLoader(this.beanClassLoader);
        spca.setAutoStartup(this.autoStartup);
        spca.setPhase(this.phase);
        spca.setRole(this.role);
        spca.setBeanName(this.beanName);
        spca.setBeanFactory(this.beanFactory);
        spca.setTransactionSynchronizationFactory(this.pollerMetadata.getTransactionSynchronizationFactory());
        spca.afterPropertiesSet();
        this.adapter = spca;
        this.initialized = true;
    }
}
Also used : SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter)

Aggregations

SourcePollingChannelAdapter (org.springframework.integration.endpoint.SourcePollingChannelAdapter)66 Test (org.junit.Test)58 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)29 Message (org.springframework.messaging.Message)15 PollableChannel (org.springframework.messaging.PollableChannel)13 Collection (java.util.Collection)10 ArrayList (java.util.ArrayList)9 QueueChannel (org.springframework.integration.channel.QueueChannel)9 JpaExecutor (org.springframework.integration.jpa.core.JpaExecutor)9 Consumer (org.springframework.integration.jpa.test.Consumer)9 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)8 PeriodicTrigger (org.springframework.scheduling.support.PeriodicTrigger)8 Trigger (org.springframework.scheduling.Trigger)7 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)6 Expression (org.springframework.expression.Expression)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 BeanFactory (org.springframework.beans.factory.BeanFactory)5 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)5 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)5 File (java.io.File)4