Search in sources :

Example 16 with DirectChannel

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

the class MessageFilterTests method filterAcceptsWithChannels.

@Test
public void filterAcceptsWithChannels() {
    DirectChannel inputChannel = new DirectChannel();
    QueueChannel outputChannel = new QueueChannel();
    MessageFilter filter = new MessageFilter(message -> true);
    filter.setOutputChannel(outputChannel);
    EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, filter);
    endpoint.start();
    Message<?> message = new GenericMessage<String>("test");
    assertTrue(inputChannel.send(message));
    Message<?> reply = outputChannel.receive(0);
    assertNotNull(reply);
    assertEquals(message.getPayload(), reply.getPayload());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) QueueChannel(org.springframework.integration.channel.QueueChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) Test(org.junit.Test)

Example 17 with DirectChannel

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

the class GatewayProxyFactoryBeanTests method testProxiedToStringMethod.

@Test
public void testProxiedToStringMethod() throws Exception {
    GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean();
    proxyFactory.setDefaultRequestChannel(new DirectChannel());
    proxyFactory.setServiceInterface(TestService.class);
    proxyFactory.setBeanName("testGateway");
    proxyFactory.setBeanFactory(mock(BeanFactory.class));
    proxyFactory.afterPropertiesSet();
    Object proxy = proxyFactory.getObject();
    String expected = "gateway proxy for";
    assertEquals(expected, proxy.toString().substring(0, expected.length()));
}
Also used : DirectChannel(org.springframework.integration.channel.DirectChannel) BeanFactory(org.springframework.beans.factory.BeanFactory) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 18 with DirectChannel

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

the class CorrelationIdTests method testCorrelationIdPassedIfAvailable.

@Test
public void testCorrelationIdPassedIfAvailable() {
    Object correlationId = "123-ABC";
    Message<String> message = MessageBuilder.withPayload("test").setCorrelationId(correlationId).build();
    DirectChannel inputChannel = new DirectChannel();
    QueueChannel outputChannel = new QueueChannel(1);
    ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(new TestBean(), "upperCase");
    serviceActivator.setOutputChannel(outputChannel);
    EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, serviceActivator);
    endpoint.start();
    assertTrue(inputChannel.send(message));
    Message<?> reply = outputChannel.receive(0);
    assertEquals(correlationId, new IntegrationMessageHeaderAccessor(reply).getCorrelationId());
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) QueueChannel(org.springframework.integration.channel.QueueChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Example 19 with DirectChannel

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

the class AsyncMessagingTemplateTests method asyncSendAndReceiveWithDefaultChannel.

@Test
public void asyncSendAndReceiveWithDefaultChannel() throws Exception {
    DirectChannel channel = new DirectChannel();
    channel.subscribe(new EchoHandler(200));
    AsyncMessagingTemplate template = new AsyncMessagingTemplate();
    template.setDefaultDestination(channel);
    long start = System.currentTimeMillis();
    Future<Message<?>> result = template.asyncSendAndReceive(MessageBuilder.withPayload("test").build());
    assertNotNull(result.get());
    long elapsed = System.currentTimeMillis() - start;
    assertTrue(elapsed >= 200 - safety);
}
Also used : Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) DirectChannel(org.springframework.integration.channel.DirectChannel) Test(org.junit.Test)

Example 20 with DirectChannel

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

the class MessagingAnnotationPostProcessorTests method testMessageEndpointAnnotationInheritedFromInterfaceWithProxy.

@Test
public void testMessageEndpointAnnotationInheritedFromInterfaceWithProxy() {
    TestApplicationContext context = TestUtils.createTestApplicationContext();
    DirectChannel inputChannel = new DirectChannel();
    QueueChannel outputChannel = new QueueChannel();
    context.registerChannel("inputChannel", inputChannel);
    context.registerChannel("outputChannel", outputChannel);
    MessagingAnnotationPostProcessor postProcessor = new MessagingAnnotationPostProcessor();
    postProcessor.setBeanFactory(context.getBeanFactory());
    postProcessor.afterPropertiesSet();
    ProxyFactory proxyFactory = new ProxyFactory(new SimpleAnnotatedEndpointImplementation());
    Object proxy = proxyFactory.getProxy();
    postProcessor.postProcessAfterInitialization(proxy, "proxy");
    context.refresh();
    inputChannel.send(new GenericMessage<String>("ABC"));
    Message<?> message = outputChannel.receive(1000);
    assertEquals("test-ABC", message.getPayload());
    context.stop();
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) ProxyFactory(org.springframework.aop.framework.ProxyFactory) TestApplicationContext(org.springframework.integration.test.util.TestUtils.TestApplicationContext) Test(org.junit.Test)

Aggregations

DirectChannel (org.springframework.integration.channel.DirectChannel)207 Test (org.junit.Test)179 Message (org.springframework.messaging.Message)62 MessageChannel (org.springframework.messaging.MessageChannel)60 QueueChannel (org.springframework.integration.channel.QueueChannel)58 BeanFactory (org.springframework.beans.factory.BeanFactory)45 GenericMessage (org.springframework.messaging.support.GenericMessage)37 MessageHandler (org.springframework.messaging.MessageHandler)32 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)28 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)26 CountDownLatch (java.util.concurrent.CountDownLatch)25 AbstractReplyProducingMessageHandler (org.springframework.integration.handler.AbstractReplyProducingMessageHandler)23 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)22 HashMap (java.util.HashMap)20 BindingProperties (org.springframework.cloud.stream.config.BindingProperties)19 MessagingException (org.springframework.messaging.MessagingException)18 SubscribableChannel (org.springframework.messaging.SubscribableChannel)16 Properties (java.util.Properties)15 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)15 Expression (org.springframework.expression.Expression)14