Example usage for org.springframework.integration.channel QueueChannel QueueChannel

List of usage examples for org.springframework.integration.channel QueueChannel QueueChannel

Introduction

In this page you can find the example usage for org.springframework.integration.channel QueueChannel QueueChannel.

Prototype

public QueueChannel() 

Source Link

Document

Create a channel with "unbounded" queue capacity.

Usage

From source file:org.springframework.integration.configuration.EnableIntegrationTests.java

@Test
public void testSourcePollingChannelAdapterOutputChannelLateBinding() {
    QueueChannel testChannel = new QueueChannel();
    ConfigurableListableBeanFactory beanFactory = (ConfigurableListableBeanFactory) this.context
            .getAutowireCapableBeanFactory();
    beanFactory.registerSingleton("lateBindingChannel", testChannel);
    beanFactory.initializeBean(testChannel, "lateBindingChannel");

    this.autoCreatedChannelMessageSourceAdapter.start();
    Message<?> receive = testChannel.receive(10000);
    assertNotNull(receive);// w w w .  j  a  v  a 2 s. c o m
    assertEquals("bar", receive.getPayload());
    this.autoCreatedChannelMessageSourceAdapter.stop();
}

From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java

@Test
public void testDirectFlow() {
    assertTrue(this.beanFactory.containsBean("filter"));
    assertTrue(this.beanFactory.containsBean("filter.handler"));
    QueueChannel replyChannel = new QueueChannel();
    Message<String> message = MessageBuilder.withPayload("100").setReplyChannel(replyChannel).build();
    try {/*from w  w w .j ava 2s.co m*/
        this.inputChannel.send(message);
        fail("Expected MessageDispatchingException");
    } catch (Exception e) {
        assertThat(e, instanceOf(MessageDeliveryException.class));
        assertThat(e.getCause(), instanceOf(MessageDispatchingException.class));
        assertThat(e.getMessage(), containsString("Dispatcher has no subscribers"));
    }
    this.controlBus.send("@payloadSerializingTransformer.start()");

    final AtomicBoolean used = new AtomicBoolean();

    this.foo.subscribe(m -> used.set(true));

    this.inputChannel.send(message);
    Message<?> reply = replyChannel.receive(5000);
    assertNotNull(reply);
    assertEquals(200, reply.getPayload());

    Message<?> successMessage = this.successChannel.receive(5000);
    assertNotNull(successMessage);
    assertEquals(100, successMessage.getPayload());

    assertTrue(used.get());
}

From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java

@Test
public void testMethodInvokingMessageHandler() {
    QueueChannel replyChannel = new QueueChannel();
    Message<?> message = MessageBuilder.withPayload("world")
            .setHeader(MessageHeaders.REPLY_CHANNEL, replyChannel).build();
    this.methodInvokingInput.send(message);
    Message<?> receive = replyChannel.receive(5000);
    assertNotNull(receive);/*from   w  w  w . java 2s.  co  m*/
    assertEquals("Hello World and world", receive.getPayload());
}

From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java

@Test
public void testLambdas() {
    QueueChannel replyChannel = new QueueChannel();
    Message<?> message = MessageBuilder.withPayload("World")
            .setHeader(MessageHeaders.REPLY_CHANNEL, replyChannel).build();
    this.lamdasInput.send(message);
    Message<?> receive = replyChannel.receive(5000);
    assertNotNull(receive);//from  w ww . j  av a  2s  . c o m
    assertEquals("Hello World", receive.getPayload());

    message = MessageBuilder.withPayload("Spring").setHeader(MessageHeaders.REPLY_CHANNEL, replyChannel)
            .build();

    this.lamdasInput.send(message);
    assertNull(replyChannel.receive(10));

}

From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java

@Test
public void testContentEnricher() {
    QueueChannel replyChannel = new QueueChannel();
    Message<?> message = MessageBuilder.withPayload(new TestPojo("Bar"))
            .setHeader(MessageHeaders.REPLY_CHANNEL, replyChannel).build();
    this.enricherInput.send(message);
    Message<?> receive = replyChannel.receive(5000);
    assertNotNull(receive);//from   ww  w.j  a v a  2s . c  o m
    assertEquals("Bar Bar", receive.getHeaders().get("foo"));
    Object payload = receive.getPayload();
    assertThat(payload, instanceOf(TestPojo.class));
    TestPojo result = (TestPojo) payload;
    assertEquals("Bar Bar", result.getName());
    assertNotNull(result.getDate());
    assertThat(new Date(), Matchers.greaterThanOrEqualTo(result.getDate()));
}

From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java

@Test
public void testContentEnricher2() {
    QueueChannel replyChannel = new QueueChannel();
    Message<?> message = MessageBuilder.withPayload(new TestPojo("Bar"))
            .setHeader(MessageHeaders.REPLY_CHANNEL, replyChannel).build();
    this.enricherInput2.send(message);
    Message<?> receive = replyChannel.receive(5000);
    assertNotNull(receive);//  w ww.ja va  2  s.co m
    assertNull(receive.getHeaders().get("foo"));
    Object payload = receive.getPayload();
    assertThat(payload, instanceOf(TestPojo.class));
    TestPojo result = (TestPojo) payload;
    assertEquals("Bar Bar", result.getName());
    assertNotNull(result.getDate());
    assertThat(new Date(), Matchers.greaterThanOrEqualTo(result.getDate()));
}

From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java

@Test
public void testContentEnricher3() {
    QueueChannel replyChannel = new QueueChannel();
    Message<?> message = MessageBuilder.withPayload(new TestPojo("Bar"))
            .setHeader(MessageHeaders.REPLY_CHANNEL, replyChannel).build();
    this.enricherInput3.send(message);
    Message<?> receive = replyChannel.receive(5000);
    assertNotNull(receive);/*from www.j ava 2 s  .  com*/
    assertEquals("Bar Bar", receive.getHeaders().get("foo"));
    Object payload = receive.getPayload();
    assertThat(payload, instanceOf(TestPojo.class));
    TestPojo result = (TestPojo) payload;
    assertEquals("Bar", result.getName());
    assertNull(result.getDate());
}

From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java

@Test
public void testSplitterResequencer() {
    QueueChannel replyChannel = new QueueChannel();

    this.splitInput
            .send(MessageBuilder.withPayload("").setReplyChannel(replyChannel).setHeader("foo", "bar").build());

    for (int i = 0; i < 12; i++) {
        Message<?> receive = replyChannel.receive(2000);
        assertNotNull(receive);/*  ww w .j av a2  s . co m*/
        assertFalse(receive.getHeaders().containsKey("foo"));
        assertTrue(receive.getHeaders().containsKey("FOO"));
        assertEquals("BAR", receive.getHeaders().get("FOO"));
        assertEquals(i + 1, receive.getPayload());
    }
}

From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java

@Test
public void testSplitterAggregator() {
    List<Character> payload = Arrays.asList('a', 'b', 'c', 'd', 'e');

    QueueChannel replyChannel = new QueueChannel();
    this.splitAggregateInput.send(MessageBuilder.withPayload(payload).setReplyChannel(replyChannel).build());

    Message<?> receive = replyChannel.receive(2000);
    assertNotNull(receive);/*from  w w w.j av  a2  s.c  o m*/
    assertThat(receive.getPayload(), instanceOf(List.class));
    @SuppressWarnings("unchecked")
    List<Object> result = (List<Object>) receive.getPayload();
    for (int i = 0; i < payload.size(); i++) {
        assertEquals(payload.get(i), result.get(i));
    }
}

From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java

@Test
public void testHeaderEnricher() {
    QueueChannel replyChannel = new QueueChannel();

    Message<String> message = MessageBuilder
            .withPayload("<root><elementOne>1</elementOne><elementTwo>2</elementTwo></root>")
            .setReplyChannel(replyChannel).build();

    try {//from  w  w  w.  ja  v a2s  .  co  m
        this.xpathHeaderEnricherInput.send(message);
        fail("Expected MessageDispatchingException");
    } catch (Exception e) {
        assertThat(e, instanceOf(MessageDeliveryException.class));
        assertThat(e.getCause(), instanceOf(MessageDispatchingException.class));
        assertThat(e.getMessage(), containsString("Dispatcher has no subscribers"));
    }

    this.controlBus.send("@xpathHeaderEnricher.start()");
    this.xpathHeaderEnricherInput.send(message);

    Message<?> result = replyChannel.receive(2000);
    assertNotNull(result);
    MessageHeaders headers = result.getHeaders();
    assertEquals("1", headers.get("one"));
    assertEquals("2", headers.get("two"));
    assertThat(headers.getReplyChannel(), instanceOf(String.class));
}