Search in sources :

Example 6 with PublishSubscribeChannel

use of org.springframework.integration.channel.PublishSubscribeChannel in project spring-integration by spring-projects.

the class PublishSubscribeChannelParserTests method channelWithErrorHandler.

@Test
public void channelWithErrorHandler() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("publishSubscribeChannelParserTests.xml", this.getClass());
    PublishSubscribeChannel channel = (PublishSubscribeChannel) context.getBean("channelWithErrorHandler");
    DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
    ErrorHandler errorHandler = (ErrorHandler) accessor.getPropertyValue("errorHandler");
    assertNotNull(errorHandler);
    assertEquals(context.getBean("testErrorHandler"), errorHandler);
    context.close();
}
Also used : ErrorHandler(org.springframework.util.ErrorHandler) PublishSubscribeChannel(org.springframework.integration.channel.PublishSubscribeChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 7 with PublishSubscribeChannel

use of org.springframework.integration.channel.PublishSubscribeChannel in project spring-integration by spring-projects.

the class ApplicationContextMessageBusTests method bothConsumersReceivePublishSubscribeMessage.

@Test
public void bothConsumersReceivePublishSubscribeMessage() throws InterruptedException {
    TestApplicationContext context = TestUtils.createTestApplicationContext();
    PublishSubscribeChannel inputChannel = new PublishSubscribeChannel();
    QueueChannel outputChannel1 = new QueueChannel();
    QueueChannel outputChannel2 = new QueueChannel();
    final CountDownLatch latch = new CountDownLatch(2);
    AbstractReplyProducingMessageHandler handler1 = new AbstractReplyProducingMessageHandler() {

        @Override
        public Object handleRequestMessage(Message<?> message) {
            latch.countDown();
            return message;
        }
    };
    AbstractReplyProducingMessageHandler handler2 = new AbstractReplyProducingMessageHandler() {

        @Override
        public Object handleRequestMessage(Message<?> message) {
            latch.countDown();
            return message;
        }
    };
    context.registerChannel("input", inputChannel);
    context.registerChannel("output1", outputChannel1);
    context.registerChannel("output2", outputChannel2);
    handler1.setOutputChannel(outputChannel1);
    handler2.setOutputChannel(outputChannel2);
    EventDrivenConsumer endpoint1 = new EventDrivenConsumer(inputChannel, handler1);
    EventDrivenConsumer endpoint2 = new EventDrivenConsumer(inputChannel, handler2);
    context.registerEndpoint("testEndpoint1", endpoint1);
    context.registerEndpoint("testEndpoint2", endpoint2);
    context.refresh();
    inputChannel.send(new GenericMessage<String>("testing"));
    latch.await(500, TimeUnit.MILLISECONDS);
    assertEquals("both handlers should have been invoked", 0, latch.getCount());
    Message<?> message1 = outputChannel1.receive(500);
    Message<?> message2 = outputChannel2.receive(500);
    context.stop();
    assertNotNull("both handlers should have replied to the message", message1);
    assertNotNull("both handlers should have replied to the message", message2);
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) PublishSubscribeChannel(org.springframework.integration.channel.PublishSubscribeChannel) QueueChannel(org.springframework.integration.channel.QueueChannel) ErrorMessage(org.springframework.messaging.support.ErrorMessage) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) AbstractReplyProducingMessageHandler(org.springframework.integration.handler.AbstractReplyProducingMessageHandler) CountDownLatch(java.util.concurrent.CountDownLatch) TestApplicationContext(org.springframework.integration.test.util.TestUtils.TestApplicationContext) Test(org.junit.Test)

Example 8 with PublishSubscribeChannel

use of org.springframework.integration.channel.PublishSubscribeChannel in project spring-integration by spring-projects.

the class PublishSubscribeChannelParserTests method ignoreFailures.

@Test
public void ignoreFailures() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("publishSubscribeChannelParserTests.xml", this.getClass());
    PublishSubscribeChannel channel = (PublishSubscribeChannel) context.getBean("channelWithIgnoreFailures");
    DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
    BroadcastingDispatcher dispatcher = (BroadcastingDispatcher) accessor.getPropertyValue("dispatcher");
    assertTrue((Boolean) new DirectFieldAccessor(dispatcher).getPropertyValue("ignoreFailures"));
    context.close();
}
Also used : PublishSubscribeChannel(org.springframework.integration.channel.PublishSubscribeChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) BroadcastingDispatcher(org.springframework.integration.dispatcher.BroadcastingDispatcher) Test(org.junit.Test)

Example 9 with PublishSubscribeChannel

use of org.springframework.integration.channel.PublishSubscribeChannel in project spring-integration by spring-projects.

the class PublishSubscribeChannelParserTests method ignoreFailuresWithTaskExecutor.

@Test
public void ignoreFailuresWithTaskExecutor() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("publishSubscribeChannelParserTests.xml", this.getClass());
    PublishSubscribeChannel channel = (PublishSubscribeChannel) context.getBean("channelWithIgnoreFailuresAndTaskExecutor");
    DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
    BroadcastingDispatcher dispatcher = (BroadcastingDispatcher) accessor.getPropertyValue("dispatcher");
    DirectFieldAccessor dispatcherAccessor = new DirectFieldAccessor(dispatcher);
    assertTrue((Boolean) dispatcherAccessor.getPropertyValue("ignoreFailures"));
    Executor executor = (Executor) dispatcherAccessor.getPropertyValue("executor");
    assertNotNull(executor);
    assertEquals(ErrorHandlingTaskExecutor.class, executor.getClass());
    DirectFieldAccessor executorAccessor = new DirectFieldAccessor(executor);
    Executor innerExecutor = (Executor) executorAccessor.getPropertyValue("executor");
    assertEquals(context.getBean("pool"), innerExecutor);
    context.close();
}
Also used : ErrorHandlingTaskExecutor(org.springframework.integration.util.ErrorHandlingTaskExecutor) Executor(java.util.concurrent.Executor) PublishSubscribeChannel(org.springframework.integration.channel.PublishSubscribeChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) BroadcastingDispatcher(org.springframework.integration.dispatcher.BroadcastingDispatcher) Test(org.junit.Test)

Example 10 with PublishSubscribeChannel

use of org.springframework.integration.channel.PublishSubscribeChannel in project spring-integration by spring-projects.

the class PublishSubscribeChannelParserTests method defaultChannel.

@Test
public void defaultChannel() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("publishSubscribeChannelParserTests.xml", this.getClass());
    PublishSubscribeChannel channel = (PublishSubscribeChannel) context.getBean("defaultChannel");
    DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
    BroadcastingDispatcher dispatcher = (BroadcastingDispatcher) accessor.getPropertyValue("dispatcher");
    dispatcher.setApplySequence(true);
    dispatcher.addHandler(message -> {
    });
    dispatcher.dispatch(new GenericMessage<String>("foo"));
    DirectFieldAccessor dispatcherAccessor = new DirectFieldAccessor(dispatcher);
    assertNull(dispatcherAccessor.getPropertyValue("executor"));
    assertFalse((Boolean) dispatcherAccessor.getPropertyValue("ignoreFailures"));
    assertTrue((Boolean) dispatcherAccessor.getPropertyValue("applySequence"));
    Object mbf = context.getBean(IntegrationUtils.INTEGRATION_MESSAGE_BUILDER_FACTORY_BEAN_NAME);
    assertSame(mbf, dispatcherAccessor.getPropertyValue("messageBuilderFactory"));
    context.close();
}
Also used : PublishSubscribeChannel(org.springframework.integration.channel.PublishSubscribeChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) BroadcastingDispatcher(org.springframework.integration.dispatcher.BroadcastingDispatcher) Test(org.junit.Test)

Aggregations

PublishSubscribeChannel (org.springframework.integration.channel.PublishSubscribeChannel)16 Test (org.junit.Test)13 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)7 BroadcastingDispatcher (org.springframework.integration.dispatcher.BroadcastingDispatcher)6 DirectChannel (org.springframework.integration.channel.DirectChannel)5 Executor (java.util.concurrent.Executor)3 ServiceActivatingHandler (org.springframework.integration.handler.ServiceActivatingHandler)3 TestApplicationContext (org.springframework.integration.test.util.TestUtils.TestApplicationContext)3 ErrorHandlingTaskExecutor (org.springframework.integration.util.ErrorHandlingTaskExecutor)3 BeanFactory (org.springframework.beans.factory.BeanFactory)2 AbstractMessageChannel (org.springframework.integration.channel.AbstractMessageChannel)2 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)2 SubscribableChannel (org.springframework.messaging.SubscribableChannel)2 ErrorMessage (org.springframework.messaging.support.ErrorMessage)2 GenericMessage (org.springframework.messaging.support.GenericMessage)2 Set (java.util.Set)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)1