Search in sources :

Example 6 with BeanFactoryChannelResolver

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());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) DirectChannel(org.springframework.integration.channel.DirectChannel) BeanFactoryChannelResolver(org.springframework.integration.support.channel.BeanFactoryChannelResolver) Test(org.junit.Test)

Example 7 with BeanFactoryChannelResolver

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());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) MessageChannel(org.springframework.messaging.MessageChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) BeanFactoryChannelResolver(org.springframework.integration.support.channel.BeanFactoryChannelResolver) DestinationResolutionException(org.springframework.messaging.core.DestinationResolutionException) MessageDispatchingException(org.springframework.integration.MessageDispatchingException) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException) BeanDefinitionParsingException(org.springframework.beans.factory.parsing.BeanDefinitionParsingException) Test(org.junit.Test)

Example 8 with BeanFactoryChannelResolver

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);
}
Also used : DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) BeanFactoryChannelResolver(org.springframework.integration.support.channel.BeanFactoryChannelResolver) Before(org.junit.Before)

Example 9 with BeanFactoryChannelResolver

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);
    }
}
Also used : MessagePublishingErrorHandler(org.springframework.integration.channel.MessagePublishingErrorHandler) SimpleAsyncTaskExecutor(org.springframework.core.task.SimpleAsyncTaskExecutor) BeanFactoryChannelResolver(org.springframework.integration.support.channel.BeanFactoryChannelResolver) ErrorHandlingTaskExecutor(org.springframework.integration.util.ErrorHandlingTaskExecutor)

Example 10 with BeanFactoryChannelResolver

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()));
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) BeanFactoryChannelResolver(org.springframework.integration.support.channel.BeanFactoryChannelResolver) CountDownLatch(java.util.concurrent.CountDownLatch) Date(java.util.Date)

Aggregations

BeanFactoryChannelResolver (org.springframework.integration.support.channel.BeanFactoryChannelResolver)25 Test (org.junit.Test)11 MessageChannel (org.springframework.messaging.MessageChannel)7 ErrorHandlingTaskExecutor (org.springframework.integration.util.ErrorHandlingTaskExecutor)6 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)5 MessagePublishingErrorHandler (org.springframework.integration.channel.MessagePublishingErrorHandler)5 GenericMessage (org.springframework.messaging.support.GenericMessage)5 DirectChannel (org.springframework.integration.channel.DirectChannel)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 BeanFactory (org.springframework.beans.factory.BeanFactory)3 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)3 DestinationResolutionException (org.springframework.messaging.core.DestinationResolutionException)3 Date (java.util.Date)2 MimeMessage (javax.mail.internet.MimeMessage)2 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)2 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)2 SimpleAsyncTaskExecutor (org.springframework.core.task.SimpleAsyncTaskExecutor)2 Message (org.springframework.messaging.Message)2 MessagingException (org.springframework.messaging.MessagingException)2 PollableChannel (org.springframework.messaging.PollableChannel)2