Package org.springframework.integration.channel

Examples of org.springframework.integration.channel.QueueChannel


  protected Map<String, String> onDemandProperties() {
    return Collections.emptyMap();
  }

  protected void verifyOnDemandQueues(MessageChannel y3, MessageChannel z3) {
    QueueChannel y3q = (QueueChannel) y3;
    assertEquals(1, y3q.getQueueSize());
    QueueChannel z3q = (QueueChannel) z3;
    assertEquals(1, z3q.getQueueSize());
    final Message<?> yMessage = y3q.receive(2000);
    final Message<?> zMessage = z3q.receive(2000);
    assertEquals("y", yMessage.getPayload());
    assertEquals("z", zMessage.getPayload());
  }
View Full Code Here


    MessageChannel y3 = singleNodeApplication.pluginContext().getBean("topic:y", MessageChannel.class);
    MessageChannel z3 = singleNodeApplication.pluginContext().getBean("topic:z", MessageChannel.class);
    assertNotNull(y3);
    assertNotNull(z3);

    QueueChannel consumer = new QueueChannel();
    bus.bindPubSubConsumer("topic:y", consumer, null);
    bus.bindPubSubConsumer("topic:z", consumer, null);
    testChannel.send(MessageBuilder.withPayload("y").build());
    Thread.sleep(2000);
    testChannel.send(MessageBuilder.withPayload("z").build());
    Thread.sleep(2000);
    assertEquals("y", consumer.receive(2000).getPayload());
    assertEquals("z", consumer.receive(2000).getPayload());
    assertEquals(0, consumer.getQueueSize());

    verifyDynamicProperties(bus, "topic");

    bus.unbindProducer("topic:x", testChannel);
    bus.unbindConsumers("topic:x");
View Full Code Here

    }
    return (Table) commandResult.getResult();
  }

  private void bindJobTap(String jobName) {
    MessageChannel alreadyBound = jobTapChannels.putIfAbsent(jobName, new QueueChannel());
    if (alreadyBound == null) {
      getMessageBus().bindPubSubConsumer("tap:job:" + jobName, jobTapChannels.get(jobName), null);
    }
  }
View Full Code Here

  @Test
  public void testSendAndReceive() throws Exception {
    MessageBus messageBus = getMessageBus();
    DirectChannel moduleOutputChannel = new DirectChannel();
    QueueChannel moduleInputChannel = new QueueChannel();
    messageBus.bindProducer("foo.0", moduleOutputChannel, null);
    messageBus.bindConsumer("foo.0", moduleInputChannel, null);
    Message<?> message = MessageBuilder.withPayload("foo").setHeader(MessageHeaders.CONTENT_TYPE, "foo/bar").build();
    // Let the consumer actually bind to the producer before sending a msg
    busBindUnbindLatency();
    moduleOutputChannel.send(message);
    Message<?> inbound = moduleInputChannel.receive(5000);
    assertNotNull(inbound);
    assertEquals("foo", inbound.getPayload());
    assertNull(inbound.getHeaders().get(MessageBusSupport.ORIGINAL_CONTENT_TYPE_HEADER));
    assertEquals("foo/bar", inbound.getHeaders().get(MessageHeaders.CONTENT_TYPE));
    messageBus.unbindProducers("foo.0");
View Full Code Here

  @Test
  public void testSendAndReceiveNoOriginalContentType() throws Exception {
    MessageBus messageBus = getMessageBus();
    DirectChannel moduleOutputChannel = new DirectChannel();
    QueueChannel moduleInputChannel = new QueueChannel();
    messageBus.bindProducer("bar.0", moduleOutputChannel, null);
    messageBus.bindConsumer("bar.0", moduleInputChannel, null);
    busBindUnbindLatency();

    Message<?> message = MessageBuilder.withPayload("foo").build();
    moduleOutputChannel.send(message);
    Message<?> inbound = moduleInputChannel.receive(5000);
    assertNotNull(inbound);
    assertEquals("foo", inbound.getPayload());
    assertNull(inbound.getHeaders().get(MessageBusSupport.ORIGINAL_CONTENT_TYPE_HEADER));
    assertNull(inbound.getHeaders().get(MessageHeaders.CONTENT_TYPE));
    messageBus.unbindProducers("bar.0");
View Full Code Here

  public void testSendAndReceivePubSub() throws Exception {
    MessageBus messageBus = getMessageBus();
    DirectChannel moduleOutputChannel = new DirectChannel();
    // Test pub/sub by emulating how StreamPlugin handles taps
    DirectChannel tapChannel = new DirectChannel();
    QueueChannel moduleInputChannel = new QueueChannel();
    QueueChannel module2InputChannel = new QueueChannel();
    QueueChannel module3InputChannel = new QueueChannel();
    messageBus.bindProducer("baz.0", moduleOutputChannel, null);
    messageBus.bindConsumer("baz.0", moduleInputChannel, null);
    moduleOutputChannel.addInterceptor(new WireTap(tapChannel));
    messageBus.bindPubSubProducer("tap:baz.http", tapChannel, null);
    // A new module is using the tap as an input channel
    messageBus.bindPubSubConsumer("tap:baz.http", module2InputChannel, null);
    // Another new module is using tap as an input channel
    messageBus.bindPubSubConsumer("tap:baz.http", module3InputChannel, null);
    Message<?> message = MessageBuilder.withPayload("foo").setHeader(MessageHeaders.CONTENT_TYPE, "foo/bar").build();
    boolean success = false;
    boolean retried = false;
    while (!success) {
      moduleOutputChannel.send(message);
      Message<?> inbound = moduleInputChannel.receive(5000);
      assertNotNull(inbound);
      assertEquals("foo", inbound.getPayload());
      assertNull(inbound.getHeaders().get(MessageBusSupport.ORIGINAL_CONTENT_TYPE_HEADER));
      assertEquals("foo/bar", inbound.getHeaders().get(MessageHeaders.CONTENT_TYPE));
      Message<?> tapped1 = module2InputChannel.receive(5000);
      Message<?> tapped2 = module3InputChannel.receive(5000);
      if (tapped1 == null || tapped2 == null) {
        // listener may not have started
        assertFalse("Failed to receive tap after retry", retried);
        retried = true;
        continue;
      }
      success = true;
      assertEquals("foo", tapped1.getPayload());
      assertNull(tapped1.getHeaders().get(MessageBusSupport.ORIGINAL_CONTENT_TYPE_HEADER));
      assertEquals("foo/bar", tapped1.getHeaders().get(MessageHeaders.CONTENT_TYPE));
      assertEquals("foo", tapped2.getPayload());
      assertNull(tapped2.getHeaders().get(MessageBusSupport.ORIGINAL_CONTENT_TYPE_HEADER));
      assertEquals("foo/bar", tapped2.getHeaders().get(MessageHeaders.CONTENT_TYPE));
    }
    // delete one tap stream is deleted
    messageBus.unbindConsumer("tap:baz.http", module3InputChannel);
    Message<?> message2 = MessageBuilder.withPayload("bar").setHeader(MessageHeaders.CONTENT_TYPE, "foo/bar").build();
    moduleOutputChannel.send(message2);

    // other tap still receives messages
    Message<?> tapped = module2InputChannel.receive(5000);
    assertNotNull(tapped);

    // Removed tap does not
    assertNull(module3InputChannel.receive(1000));

    // when other tap stream is deleted
    messageBus.unbindConsumer("tap:baz.http", module2InputChannel);
    // Clean up as StreamPlugin would
    messageBus.unbindConsumer("baz.0", moduleInputChannel);
View Full Code Here

  public void createInboundPubSubBeforeOutboundPubSub() throws Exception {
    MessageBus messageBus = getMessageBus();
    DirectChannel moduleOutputChannel = new DirectChannel();
    // Test pub/sub by emulating how StreamPlugin handles taps
    DirectChannel tapChannel = new DirectChannel();
    QueueChannel moduleInputChannel = new QueueChannel();
    QueueChannel module2InputChannel = new QueueChannel();
    QueueChannel module3InputChannel = new QueueChannel();
    // Create the tap first
    messageBus.bindPubSubConsumer("tap:baz.http", module2InputChannel, null);

    // Then create the stream
    messageBus.bindProducer("baz.0", moduleOutputChannel, null);
    messageBus.bindConsumer("baz.0", moduleInputChannel, null);
    moduleOutputChannel.addInterceptor(new WireTap(tapChannel));
    messageBus.bindPubSubProducer("tap:baz.http", tapChannel, null);

    // Another new module is using tap as an input channel
    messageBus.bindPubSubConsumer("tap:baz.http", module3InputChannel, null);
    Message<?> message = MessageBuilder.withPayload("foo").setHeader(MessageHeaders.CONTENT_TYPE, "foo/bar").build();
    boolean success = false;
    boolean retried = false;
    while (!success) {
      moduleOutputChannel.send(message);
      Message<?> inbound = moduleInputChannel.receive(5000);
      assertNotNull(inbound);
      assertEquals("foo", inbound.getPayload());
      assertNull(inbound.getHeaders().get(MessageBusSupport.ORIGINAL_CONTENT_TYPE_HEADER));
      assertEquals("foo/bar", inbound.getHeaders().get(MessageHeaders.CONTENT_TYPE));
      Message<?> tapped1 = module2InputChannel.receive(5000);
      Message<?> tapped2 = module3InputChannel.receive(5000);
      if (tapped1 == null || tapped2 == null) {
        // listener may not have started
        assertFalse("Failed to receive tap after retry", retried);
        retried = true;
        continue;
      }
      success = true;
      assertEquals("foo", tapped1.getPayload());
      assertNull(tapped1.getHeaders().get(MessageBusSupport.ORIGINAL_CONTENT_TYPE_HEADER));
      assertEquals("foo/bar", tapped1.getHeaders().get(MessageHeaders.CONTENT_TYPE));
      assertEquals("foo", tapped2.getPayload());
      assertNull(tapped2.getHeaders().get(MessageBusSupport.ORIGINAL_CONTENT_TYPE_HEADER));
      assertEquals("foo/bar", tapped2.getHeaders().get(MessageHeaders.CONTENT_TYPE));
    }
    // delete one tap stream is deleted
    messageBus.unbindConsumer("tap:baz.http", module3InputChannel);
    Message<?> message2 = MessageBuilder.withPayload("bar").setHeader(MessageHeaders.CONTENT_TYPE, "foo/bar").build();
    moduleOutputChannel.send(message2);

    // other tap still receives messages
    Message<?> tapped = module2InputChannel.receive(5000);
    assertNotNull(tapped);

    // Removed tap does not
    assertNull(module3InputChannel.receive(1000));

    // when other tap stream is deleted
    messageBus.unbindConsumer("tap:baz.http", module2InputChannel);
    // Clean up as StreamPlugin would
    messageBus.unbindConsumer("baz.0", moduleInputChannel);
View Full Code Here

    }

    properties.clear();
    properties.put("concurrency", "2");
    properties.put("partitionIndex", "0");
    QueueChannel input0 = new QueueChannel();
    input0.setBeanName("test.input0S");
    bus.bindConsumer("part.0", input0, properties);
    properties.put("partitionIndex", "1");
    QueueChannel input1 = new QueueChannel();
    input1.setBeanName("test.input1S");
    bus.bindConsumer("part.0", input1, properties);
    properties.put("partitionIndex", "2");
    QueueChannel input2 = new QueueChannel();
    input2.setBeanName("test.input2S");
    bus.bindConsumer("part.0", input2, properties);

    Message<Integer> message2 = MessageBuilder.withPayload(2)
        .setHeader(IntegrationMessageHeaderAccessor.CORRELATION_ID, "foo")
        .setHeader(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER, 42)
        .setHeader(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE, 43)
        .setHeader("xdReplyChannel", "bar")
        .build();
    output.send(message2);
    output.send(new GenericMessage<Integer>(1));
    output.send(new GenericMessage<Integer>(0));

    Message<?> receive0 = input0.receive(1000);
    assertNotNull(receive0);
    Message<?> receive1 = input1.receive(1000);
    assertNotNull(receive1);
    Message<?> receive2 = input2.receive(1000);
    assertNotNull(receive2);

    Matcher<Message<?>> fooMatcher = new CustomMatcher<Message<?>>("the message with 'foo' as its correlationId") {

      @Override
View Full Code Here

    }

    properties.clear();
    properties.put("concurrency", "2");
    properties.put("partitionIndex", "0");
    QueueChannel input0 = new QueueChannel();
    input0.setBeanName("test.input0J");
    bus.bindConsumer("partJ.0", input0, properties);
    properties.put("partitionIndex", "1");
    QueueChannel input1 = new QueueChannel();
    input1.setBeanName("test.input1J");
    bus.bindConsumer("partJ.0", input1, properties);
    properties.put("partitionIndex", "2");
    QueueChannel input2 = new QueueChannel();
    input2.setBeanName("test.input2J");
    bus.bindConsumer("partJ.0", input2, properties);

    output.send(new GenericMessage<Integer>(2));
    output.send(new GenericMessage<Integer>(1));
    output.send(new GenericMessage<Integer>(0));

    Message<?> receive0 = input0.receive(1000);
    assertNotNull(receive0);
    Message<?> receive1 = input1.receive(1000);
    assertNotNull(receive1);
    Message<?> receive2 = input2.receive(1000);
    assertNotNull(receive2);

    if (usesExplicitRouting()) {
      assertEquals(0, receive0.getPayload());
      assertEquals(1, receive1.getPayload());
View Full Code Here

        .andExpect(jsonPath("$[0].message", Matchers.is("Could not find jobExecution with id 99999")));
  }

  @Test
  public void testSuccessfulJobLaunch() throws Exception {
    QueueChannel channel = new QueueChannel();
    messageBus.bindConsumer("job:joblaunch", channel, null);
    mockMvc.perform(
        post("/jobs/definitions").param("name", "joblaunch").param("definition", JOB_DEFINITION).accept(
            MediaType.APPLICATION_JSON)).andExpect(status().isCreated());
    mockMvc.perform(
        post("/jobs/executions").param("jobname", "joblaunch").accept(MediaType.APPLICATION_JSON)).andExpect(
        status().isCreated());
    assertNotNull(channel.receive(3000));
  }
View Full Code Here

TOP

Related Classes of org.springframework.integration.channel.QueueChannel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.