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);
}
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();
}
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);
}
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();
}
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;
}
}
Aggregations