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.xmpp.inbound.ChatMessageListeningEndpointTests.java

@Test
public void testExpression() throws Exception {
    TestXMPPConnection testXMPPConnection = new TestXMPPConnection();

    QueueChannel inputChannel = new QueueChannel();

    ChatMessageListeningEndpoint endpoint = new ChatMessageListeningEndpoint(testXMPPConnection);
    SpelExpressionParser parser = new SpelExpressionParser();
    endpoint.setPayloadExpression(parser.parseExpression("#root"));
    endpoint.setOutputChannel(inputChannel);
    endpoint.setBeanFactory(mock(BeanFactory.class));
    endpoint.afterPropertiesSet();/*from   w w  w  .jav  a  2 s. c  o  m*/
    endpoint.start();

    Message smackMessage = new Message();
    smackMessage.setBody("foo");

    XmlPullParser xmlPullParser = PacketParserUtils.newXmppParser(new StringReader(smackMessage.toString()));
    xmlPullParser.next();
    testXMPPConnection.parseAndProcessStanza(xmlPullParser);

    org.springframework.messaging.Message<?> receive = inputChannel.receive(10000);
    assertNotNull(receive);

    Object payload = receive.getPayload();
    assertThat(payload, instanceOf(Message.class));
    assertEquals(smackMessage.getStanzaId(), ((Message) payload).getStanzaId());
    assertEquals(smackMessage.getBody(), ((Message) payload).getBody());

    Log logger = Mockito.spy(TestUtils.getPropertyValue(endpoint, "logger", Log.class));
    given(logger.isInfoEnabled()).willReturn(true);
    final CountDownLatch logLatch = new CountDownLatch(1);
    willAnswer(invocation -> {
        Object result = invocation.callRealMethod();
        logLatch.countDown();
        return result;
    }).given(logger).info(anyString());

    new DirectFieldAccessor(endpoint).setPropertyValue("logger", logger);

    endpoint.setPayloadExpression(null);

    smackMessage = new Message();
    xmlPullParser = PacketParserUtils.newXmppParser(new StringReader(smackMessage.toString()));
    xmlPullParser.next();
    testXMPPConnection.parseAndProcessStanza(xmlPullParser);

    ArgumentCaptor<String> argumentCaptor = ArgumentCaptor.forClass(String.class);

    assertTrue(logLatch.await(10, TimeUnit.SECONDS));

    verify(logger).info(argumentCaptor.capture());

    assertEquals("The XMPP Message [" + smackMessage + "] with empty body is ignored.",
            argumentCaptor.getValue());

    endpoint.stop();
}

From source file:org.springframework.integration.xmpp.inbound.ChatMessageListeningEndpointTests.java

@Test
public void testGcmExtension() throws Exception {
    String data = "{\n" + "      \"to\":\"me\",\n" + "     \"notification\": {\n"
            + "        \"title\": \"Something interesting\",\n" + "        \"text\": \"Here we go\"\n"
            + "           },\n" + "      \"time_to_live\":\"600\"\n" + "      }\n" + "}";
    GcmPacketExtension packetExtension = new GcmPacketExtension(data);
    Message smackMessage = new Message();
    smackMessage.addExtension(packetExtension);

    TestXMPPConnection testXMPPConnection = new TestXMPPConnection();

    QueueChannel inputChannel = new QueueChannel();

    ChatMessageListeningEndpoint endpoint = new ChatMessageListeningEndpoint(testXMPPConnection);
    Expression payloadExpression = new SpelExpressionParser().parseExpression("#extension.json");
    endpoint.setPayloadExpression(payloadExpression);
    endpoint.setOutputChannel(inputChannel);
    endpoint.setBeanFactory(mock(BeanFactory.class));
    endpoint.afterPropertiesSet();//from   www .j  a va  2 s.com
    endpoint.start();

    XmlPullParser xmlPullParser = PacketParserUtils.newXmppParser(new StringReader(smackMessage.toString()));
    xmlPullParser.next();
    testXMPPConnection.parseAndProcessStanza(xmlPullParser);

    org.springframework.messaging.Message<?> receive = inputChannel.receive(10000);
    assertNotNull(receive);

    assertEquals(data, receive.getPayload());

    endpoint.stop();
}

From source file:org.springframework.xd.dirt.integration.bus.rabbit.RabbitMessageBusTests.java

@SuppressWarnings("unchecked")
@Test/*ww w . j a  v  a 2s  . c o  m*/
public void testBatchingAndCompression() throws Exception {
    RabbitTemplate template = new RabbitTemplate(this.rabbitAvailableRule.getResource());
    MessageBus bus = getMessageBus();
    Properties properties = new Properties();
    properties.put("deliveryMode", "NON_PERSISTENT");
    properties.put("batchingEnabled", "true");
    properties.put("batchSize", "2");
    properties.put("batchBufferLimit", "100000");
    properties.put("batchTimeout", "30000");
    properties.put("compress", "true");

    DirectChannel output = new DirectChannel();
    output.setBeanName("batchingProducer");
    bus.bindProducer("batching.0", output, properties);

    while (template.receive("xdbus.batching.0") != null) {
    }

    Log logger = spy(TestUtils.getPropertyValue(bus, "messageBus.compressingPostProcessor.logger", Log.class));
    new DirectFieldAccessor(TestUtils.getPropertyValue(bus, "messageBus.compressingPostProcessor"))
            .setPropertyValue("logger", logger);
    when(logger.isTraceEnabled()).thenReturn(true);

    assertEquals(Deflater.BEST_SPEED,
            TestUtils.getPropertyValue(bus, "messageBus.compressingPostProcessor.level"));

    output.send(new GenericMessage<>("foo".getBytes()));
    output.send(new GenericMessage<>("bar".getBytes()));

    Object out = spyOn("batching.0").receive(false);
    assertThat(out, instanceOf(byte[].class));
    assertEquals("\u0000\u0000\u0000\u0003foo\u0000\u0000\u0000\u0003bar", new String((byte[]) out));

    ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class);
    verify(logger).trace(captor.capture());
    assertThat(captor.getValue().toString(), containsString("Compressed 14 to "));

    QueueChannel input = new QueueChannel();
    input.setBeanName("batchingConsumer");
    bus.bindConsumer("batching.0", input, null);

    output.send(new GenericMessage<>("foo".getBytes()));
    output.send(new GenericMessage<>("bar".getBytes()));

    Message<byte[]> in = (Message<byte[]>) input.receive(10000);
    assertNotNull(in);
    assertEquals("foo", new String(in.getPayload()));
    in = (Message<byte[]>) input.receive(10000);
    assertNotNull(in);
    assertEquals("bar", new String(in.getPayload()));
    assertNull(in.getHeaders().get(AmqpHeaders.DELIVERY_MODE));

    bus.unbindProducers("batching.0");
    bus.unbindConsumers("batching.0");
}