Search in sources :

Example 16 with QueueChannel

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

the class CollectionAndArrayTests method setWithRequestReplyHandler.

@Test
public void setWithRequestReplyHandler() {
    MessageHandler handler = new AbstractReplyProducingMessageHandler() {

        @Override
        protected Object handleRequestMessage(Message<?> requestMessage) {
            return new HashSet<String>(Arrays.asList(new String[] { "foo", "bar" }));
        }
    };
    QueueChannel channel = new QueueChannel();
    Message<?> message = MessageBuilder.withPayload("test").setReplyChannel(channel).build();
    handler.handleMessage(message);
    Message<?> reply1 = channel.receive(0);
    Message<?> reply2 = channel.receive(0);
    assertNotNull(reply1);
    assertNull(reply2);
    assertThat(reply1.getPayload(), is(instanceOf(Set.class)));
    assertEquals(2, ((Set<?>) reply1.getPayload()).size());
}
Also used : MessageHandler(org.springframework.messaging.MessageHandler) Message(org.springframework.messaging.Message) QueueChannel(org.springframework.integration.channel.QueueChannel) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with QueueChannel

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

the class CollectionAndArrayTests method arrayWithRequestReplyHandler.

@Test
public void arrayWithRequestReplyHandler() {
    MessageHandler handler = new AbstractReplyProducingMessageHandler() {

        @Override
        protected Object handleRequestMessage(Message<?> requestMessage) {
            return new String[] { "foo", "bar" };
        }
    };
    QueueChannel channel = new QueueChannel();
    Message<?> message = MessageBuilder.withPayload("test").setReplyChannel(channel).build();
    handler.handleMessage(message);
    Message<?> reply1 = channel.receive(0);
    Message<?> reply2 = channel.receive(0);
    assertNotNull(reply1);
    assertNull(reply2);
    assertTrue(reply1.getPayload().getClass().isArray());
    assertEquals(2, ((String[]) reply1.getPayload()).length);
}
Also used : MessageHandler(org.springframework.messaging.MessageHandler) Message(org.springframework.messaging.Message) QueueChannel(org.springframework.integration.channel.QueueChannel) Test(org.junit.Test)

Example 18 with QueueChannel

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

the class DelayHandlerTests method testRescheduleAndHandleAtTheSameTime.

// INT-3560
@Test
public /*
	 It's difficult to test it from real ctx, because any async process from 'inbound-channel-adapter'
	 can't achieve the DelayHandler before the main thread emits 'ContextRefreshedEvent'.
	 */
void testRescheduleAndHandleAtTheSameTime() throws Exception {
    QueueChannel results = new QueueChannel();
    delayHandler.setOutputChannel(results);
    this.delayHandler.setDefaultDelay(100);
    startDelayerHandler();
    this.input.send(new GenericMessage<>("foo"));
    this.delayHandler.reschedulePersistedMessages();
    Message<?> message = results.receive(10000);
    assertNotNull(message);
    message = results.receive(500);
    assertNull(message);
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Test(org.junit.Test)

Example 19 with QueueChannel

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

the class HeaderAnnotationTransformerTests method headerAnnotationWithPrefixedHeader.

// INT-1082
@Test
public void headerAnnotationWithPrefixedHeader() {
    Object target = new TestTransformer();
    MethodInvokingTransformer transformer = new MethodInvokingTransformer(target, "appendCorrelationId");
    MessageTransformingHandler handler = new MessageTransformingHandler(transformer);
    handler.setBeanFactory(mock(BeanFactory.class));
    handler.afterPropertiesSet();
    QueueChannel outputChannel = new QueueChannel();
    handler.setOutputChannel(outputChannel);
    handler.handleMessage(MessageBuilder.withPayload("test").setCorrelationId("abc").build());
    Message<?> result = outputChannel.receive(0);
    assertNotNull(result);
    assertEquals("testabc", result.getPayload());
    assertEquals("abc", new IntegrationMessageHeaderAccessor(result).getCorrelationId());
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) MessageTransformingHandler(org.springframework.integration.transformer.MessageTransformingHandler) QueueChannel(org.springframework.integration.channel.QueueChannel) BeanFactory(org.springframework.beans.factory.BeanFactory) MethodInvokingTransformer(org.springframework.integration.transformer.MethodInvokingTransformer) Test(org.junit.Test)

Example 20 with QueueChannel

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

the class HeaderAnnotationTransformerTests method headerAnnotationWithUnprefixedHeader.

@Test
public void headerAnnotationWithUnprefixedHeader() {
    Object target = new TestTransformer();
    MethodInvokingTransformer transformer = new MethodInvokingTransformer(target, "appendFoo");
    MessageTransformingHandler handler = new MessageTransformingHandler(transformer);
    handler.setBeanFactory(mock(BeanFactory.class));
    handler.afterPropertiesSet();
    QueueChannel outputChannel = new QueueChannel();
    handler.setOutputChannel(outputChannel);
    handler.handleMessage(MessageBuilder.withPayload("test").setHeader("foo", "bar").build());
    Message<?> result = outputChannel.receive(0);
    assertNotNull(result);
    assertEquals("testbar", result.getPayload());
    assertEquals("bar", result.getHeaders().get("foo"));
}
Also used : MessageTransformingHandler(org.springframework.integration.transformer.MessageTransformingHandler) QueueChannel(org.springframework.integration.channel.QueueChannel) BeanFactory(org.springframework.beans.factory.BeanFactory) MethodInvokingTransformer(org.springframework.integration.transformer.MethodInvokingTransformer) Test(org.junit.Test)

Aggregations

QueueChannel (org.springframework.integration.channel.QueueChannel)709 Test (org.junit.Test)669 GenericMessage (org.springframework.messaging.support.GenericMessage)186 Message (org.springframework.messaging.Message)173 BeanFactory (org.springframework.beans.factory.BeanFactory)162 MessageChannel (org.springframework.messaging.MessageChannel)100 Matchers.containsString (org.hamcrest.Matchers.containsString)66 CountDownLatch (java.util.concurrent.CountDownLatch)59 DirectChannel (org.springframework.integration.channel.DirectChannel)57 ArrayList (java.util.ArrayList)55 PollableChannel (org.springframework.messaging.PollableChannel)55 MessagingException (org.springframework.messaging.MessagingException)53 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)51 AtomicReference (java.util.concurrent.atomic.AtomicReference)47 Socket (java.net.Socket)44 ErrorMessage (org.springframework.messaging.support.ErrorMessage)42 ServerSocket (java.net.ServerSocket)41 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)39 IOException (java.io.IOException)35 IntegrationMessageHeaderAccessor (org.springframework.integration.IntegrationMessageHeaderAccessor)35