use of org.springframework.integration.support.channel.BeanFactoryChannelResolver in project spring-integration by spring-projects.
the class ChannelAdapterParserTests method methodInvokingConsumer.
@Test
public void methodInvokingConsumer() {
String beanName = "methodInvokingConsumer";
Object channel = this.applicationContext.getBean(beanName);
assertTrue(channel instanceof DirectChannel);
BeanFactoryChannelResolver channelResolver = new BeanFactoryChannelResolver(this.applicationContext);
assertNotNull(channelResolver.resolveDestination(beanName));
Object adapter = this.applicationContext.getBean(beanName + ".adapter");
assertNotNull(adapter);
assertTrue(adapter instanceof EventDrivenConsumer);
TestBean testBean = (TestBean) this.applicationContext.getBean("testBean");
assertNull(testBean.getMessage());
Message<?> message = new GenericMessage<String>("consumer test");
assertTrue(((MessageChannel) channel).send(message));
assertNotNull(testBean.getMessage());
assertEquals("consumer test", testBean.getMessage());
}
use of org.springframework.integration.support.channel.BeanFactoryChannelResolver in project spring-integration by spring-projects.
the class ChannelAdapterParserTests method targetOnly.
@Test
public void targetOnly() {
String beanName = "outboundWithImplicitChannel";
Object channel = this.applicationContext.getBean(beanName);
assertTrue(channel instanceof DirectChannel);
BeanFactoryChannelResolver channelResolver = new BeanFactoryChannelResolver(this.applicationContext);
assertNotNull(channelResolver.resolveDestination(beanName));
Object adapter = this.applicationContext.getBean(beanName + ".adapter");
assertNotNull(adapter);
assertTrue(adapter instanceof EventDrivenConsumer);
assertFalse(((EventDrivenConsumer) adapter).isAutoStartup());
assertEquals(-1, ((EventDrivenConsumer) adapter).getPhase());
TestConsumer consumer = (TestConsumer) this.applicationContext.getBean("consumer");
assertNull(consumer.getLastMessage());
Message<?> message = new GenericMessage<String>("test");
try {
((MessageChannel) channel).send(message);
fail("MessageDispatchingException is expected.");
} catch (Exception e) {
assertThat(e, Matchers.instanceOf(MessageDeliveryException.class));
assertThat(e.getCause(), Matchers.instanceOf(MessageDispatchingException.class));
}
((EventDrivenConsumer) adapter).start();
((MessageChannel) channel).send(message);
assertNotNull(consumer.getLastMessage());
assertEquals(message, consumer.getLastMessage());
}
use of org.springframework.integration.support.channel.BeanFactoryChannelResolver in project spring-integration by spring-projects.
the class MessagePublishingInterceptorTests method setup.
@Before
public void setup() {
beanFactory = new DefaultListableBeanFactory();
channelResolver = new BeanFactoryChannelResolver(beanFactory);
beanFactory.registerSingleton("c", testChannel);
}
use of org.springframework.integration.support.channel.BeanFactoryChannelResolver in project spring-integration by spring-projects.
the class RedisQueueInboundGateway method onInit.
@Override
protected void onInit() throws Exception {
super.onInit();
if (!this.extractPayload) {
Assert.notNull(this.serializer, "'serializer' has to be provided where 'extractPayload == false'.");
}
if (this.taskExecutor == null) {
String beanName = this.getComponentName();
this.taskExecutor = new SimpleAsyncTaskExecutor((beanName == null ? "" : beanName + "-") + this.getComponentType());
}
if (!(this.taskExecutor instanceof ErrorHandlingTaskExecutor) && this.getBeanFactory() != null) {
MessagePublishingErrorHandler errorHandler = new MessagePublishingErrorHandler(new BeanFactoryChannelResolver(getBeanFactory()));
errorHandler.setDefaultErrorChannel(getErrorChannel());
this.taskExecutor = new ErrorHandlingTaskExecutor(this.taskExecutor, errorHandler);
}
}
use of org.springframework.integration.support.channel.BeanFactoryChannelResolver in project spring-integration by spring-projects.
the class UdpUnicastEndToEndTests method launchSender.
public void launchSender(ApplicationContext applicationContext) throws Exception {
DestinationResolver<MessageChannel> channelResolver = new BeanFactoryChannelResolver(applicationContext);
MessageChannel inputChannel = channelResolver.resolveDestination("inputChannel");
if (!readyToReceive.await(30, TimeUnit.SECONDS)) {
fail("Receiver failed to start in 30s");
}
try {
testingIpText = ">>>>>>> Testing IP " + new Date();
inputChannel.send(new GenericMessage<String>(testingIpText));
sentFirst.countDown();
try {
// give some time for console interaction
Thread.sleep(hangAroundFor);
} catch (InterruptedException e) {
e.printStackTrace();
}
} finally {
if (hangAroundFor == 0) {
sentFirst = new CountDownLatch(1);
} else {
okToRun = false;
}
// tell the receiver to we're done
doneProcessing.countDown();
}
assertTrue(firstReceived.await(5, TimeUnit.SECONDS));
assertEquals(testingIpText, new String(finalMessage.getPayload()));
}
Aggregations