Package org.springframework.integration.channel

Examples of org.springframework.integration.channel.DirectChannel


*
*/
public class SingleNodeNamedQueueSource extends AbstractSingleNodeNamedChannelSource {

  public SingleNodeNamedQueueSource(MessageBus messageBus, String sharedChannelName) {
    super(messageBus, new DirectChannel(), sharedChannelName);
  }
View Full Code Here


    Map<String, List<KafkaStream<Integer, byte[]>>> consumerMap = connector.createMessageStreams(
        topicCountMap, keyDecoder, valueDecoder);

    final KafkaStream<Integer, byte[]> stream = consumerMap.get(topic).iterator().next();

    final DirectChannel bridge = new DirectChannel();
    ReceivingHandler rh = new ReceivingHandler(connector);
    rh.setOutputChannel(moduleInputChannel);
    EventDrivenConsumer edc = new EventDrivenConsumer(bridge, rh);
    edc.setBeanName("inbound." + name);

    Binding consumerBinding = Binding.forConsumer(name, edc, moduleInputChannel, accessor);
    addBinding(consumerBinding);
    consumerBinding.start();


    executor.submit(new Runnable() {

      @Override
      public void run() {
        ConsumerIterator<Integer, byte[]> it = stream.iterator();
        while (it.hasNext()) {
          byte[] msg = it.next().message();
          bridge.send(MessageBuilder.withPayload(msg).build());
        }
      }

    });
  }
View Full Code Here

  }

  @Test
  public void testSendAndReceiveBad() throws Exception {
    MessageBus messageBus = getMessageBus();
    DirectChannel moduleOutputChannel = new DirectChannel();
    DirectChannel moduleInputChannel = new DirectChannel();
    messageBus.bindProducer("bad.0", moduleOutputChannel, null);
    messageBus.bindConsumer("bad.0", moduleInputChannel, null);
    Message<?> message = MessageBuilder.withPayload("bad").setHeader(MessageHeaders.CONTENT_TYPE, "foo/bar").build();
    final CountDownLatch latch = new CountDownLatch(3);
    moduleInputChannel.subscribe(new MessageHandler() {

      @Override
      public void handleMessage(Message<?> message) throws MessagingException {
        latch.countDown();
        throw new RuntimeException("bad");
View Full Code Here

  @Test
  public void testConsumerProperties() throws Exception {
    MessageBus bus = getMessageBus();
    Properties properties = new Properties();
    properties.put("transacted", "true"); // test transacted with defaults; not allowed with ackmode NONE
    bus.bindConsumer("props.0", new DirectChannel(), properties);
    @SuppressWarnings("unchecked")
    List<Binding> bindings = TestUtils.getPropertyValue(bus, "messageBus.bindings", List.class);
    assertEquals(1, bindings.size());
    AbstractEndpoint endpoint = bindings.get(0).getEndpoint();
    SimpleMessageListenerContainer container = TestUtils.getPropertyValue(endpoint, "messageListenerContainer",
        SimpleMessageListenerContainer.class);
    assertEquals(AcknowledgeMode.AUTO, container.getAcknowledgeMode());
    assertEquals("xdbus.props.0", container.getQueueNames()[0]);
    assertTrue(TestUtils.getPropertyValue(container, "transactional", Boolean.class));
    assertEquals(1, TestUtils.getPropertyValue(container, "concurrentConsumers"));
    assertNull(TestUtils.getPropertyValue(container, "maxConcurrentConsumers"));
    assertTrue(TestUtils.getPropertyValue(container, "defaultRequeueRejected", Boolean.class));
    assertEquals(1, TestUtils.getPropertyValue(container, "prefetchCount"));
    assertEquals(1, TestUtils.getPropertyValue(container, "txSize"));
    Advice retry = TestUtils.getPropertyValue(container, "adviceChain", Advice[].class)[0];
    assertEquals(3, TestUtils.getPropertyValue(retry, "retryOperations.retryPolicy.maxAttempts"));
    assertEquals(1000L, TestUtils.getPropertyValue(retry, "retryOperations.backOffPolicy.initialInterval"));
    assertEquals(10000L, TestUtils.getPropertyValue(retry, "retryOperations.backOffPolicy.maxInterval"));
    assertEquals(2.0, TestUtils.getPropertyValue(retry, "retryOperations.backOffPolicy.multiplier"));
    bus.unbindConsumers("props.0");
    assertEquals(0, bindings.size());

    properties = new Properties();
    properties.put("ackMode", "NONE");
    properties.put("backOffInitialInterval", "2000");
    properties.put("backOffMaxInterval", "20000");
    properties.put("backOffMultiplier", "5.0");
    properties.put("concurrency", "2");
    properties.put("maxAttempts", "23");
    properties.put("maxConcurrency", "3");
    properties.put("prefix", "foo.");
    properties.put("prefetch", "20");
    properties.put("requestHeaderPatterns", "foo");
    properties.put("requeue", "false");
    properties.put("txSize", "10");
    properties.put("partitionIndex", 0);
    bus.bindConsumer("props.0", new DirectChannel(), properties);

    @SuppressWarnings("unchecked")
    List<Binding> bindingsNow = TestUtils.getPropertyValue(bus, "messageBus.bindings", List.class);
    assertEquals(1, bindingsNow.size());
    endpoint = bindingsNow.get(0).getEndpoint();
View Full Code Here

  }

  @Test
  public void testProducerProperties() throws Exception {
    MessageBus bus = getMessageBus();
    bus.bindProducer("props.0", new DirectChannel(), null);
    @SuppressWarnings("unchecked")
    List<Binding> bindings = TestUtils.getPropertyValue(bus, "messageBus.bindings", List.class);
    assertEquals(1, bindings.size());
    AbstractEndpoint endpoint = bindings.get(0).getEndpoint();
    assertEquals("xdbus.props.0", TestUtils.getPropertyValue(endpoint, "handler.delegate.routingKey"));
    MessageDeliveryMode mode = TestUtils.getPropertyValue(endpoint, "handler.delegate.defaultDeliveryMode",
        MessageDeliveryMode.class);
    assertEquals(MessageDeliveryMode.PERSISTENT, mode);
    List<?> requestHeaders = TestUtils.getPropertyValue(endpoint,
        "handler.delegate.headerMapper.requestHeaderMatcher.strategies", List.class);
    assertEquals(2, requestHeaders.size());
    bus.unbindProducers("props.0");
    assertEquals(0, bindings.size());

    Properties properties = new Properties();
    properties.put("prefix", "foo.");
    properties.put("deliveryMode", "NON_PERSISTENT");
    properties.put("requestHeaderPatterns", "foo");
    properties.put("partitionKeyExpression", "'foo'");
    properties.put("partitionKeyExtractorClass", "foo");
    properties.put("partitionSelectorExpression", "0");
    properties.put("partitionSelectorClass", "foo");
    properties.put("partitionCount", "1");

    bus.bindProducer("props.0", new DirectChannel(), properties);
    assertEquals(1, bindings.size());
    endpoint = bindings.get(0).getEndpoint();
    assertEquals(
        "'foo.props.0-' + headers['partition']",
        TestUtils.getPropertyValue(endpoint, "handler.delegate.routingKeyExpression", SpelExpression.class).getExpressionString());
    mode = TestUtils.getPropertyValue(endpoint, "handler.delegate.defaultDeliveryMode",
        MessageDeliveryMode.class);
    assertEquals(MessageDeliveryMode.NON_PERSISTENT, mode);
    verifyFooRequestProducer(endpoint);

    try {
      bus.bindPubSubProducer("dummy", new DirectChannel(), properties);
      fail("Expected exception");
    }
    catch (IllegalArgumentException e) {
      assertThat(e.getMessage(), allOf(
          containsString("RabbitMessageBus does not support producer properties: "),
          containsString("partitionCount"),
          containsString("partitionSelectorExpression"),
          containsString("partitionKeyExtractorClass"),
          containsString("partitionKeyExpression"),
          containsString("partitionSelectorClass")));
      assertThat(e.getMessage(), containsString("for dummy."));
    }
    try {
      bus.bindProducer("queue:dummy", new DirectChannel(), properties);
      fail("Expected exception");
    }
    catch (IllegalArgumentException e) {
      assertThat(e.getMessage(), allOf(
          containsString("RabbitMessageBus does not support producer properties: "),
View Full Code Here

    properties.put("prefix", "foo.");
    properties.put("prefetch", "20");
    properties.put("requeue", "false");
    properties.put("txSize", "10");

    bus.bindRequestor("props.0", new DirectChannel(), new DirectChannel(), properties);
    @SuppressWarnings("unchecked")
    List<Binding> bindings = TestUtils.getPropertyValue(bus, "messageBus.bindings", List.class);

    assertEquals(2, bindings.size());
    AbstractEndpoint endpoint = bindings.get(0).getEndpoint(); // producer
View Full Code Here

    properties.put("prefix", "foo.");
    properties.put("prefetch", "20");
    properties.put("requeue", "false");
    properties.put("txSize", "10");

    bus.bindReplier("props.0", new DirectChannel(), new DirectChannel(), properties);
    @SuppressWarnings("unchecked")
    List<Binding> bindings = TestUtils.getPropertyValue(bus, "messageBus.bindings", List.class);

    assertEquals(2, bindings.size());
    AbstractEndpoint endpoint = bindings.get(1).getEndpoint(); // producer
View Full Code Here

    Properties properties = new Properties();
    properties.put("prefix", "xdbustest.");
    properties.put("autoBindDLQ", "true");
    properties.put("maxAttempts", "1"); // disable retry
    properties.put("requeue", "false");
    DirectChannel moduleInputChannel = new DirectChannel();
    moduleInputChannel.setBeanName("dlqTest");
    moduleInputChannel.subscribe(new MessageHandler() {

      @Override
      public void handleMessage(Message<?> message) throws MessagingException {
        throw new RuntimeException("foo");
      }
View Full Code Here

    }
    assertFalse(singleNodeApplication.pluginContext().containsBean("queue:y"));
    assertFalse(singleNodeApplication.pluginContext().containsBean("queue:z"));


    DirectChannel testChannel = new DirectChannel();
    bus.bindProducer("queue:x", testChannel, null);
    testChannel.send(MessageBuilder.withPayload("y").build());
    Thread.sleep(2000);

    singleNodeApplication.pluginContext().getBean("queue:y", MessageChannel.class);
    assertFalse(singleNodeApplication.pluginContext().containsBean("queue:z"));

    testChannel.send(MessageBuilder.withPayload("z").build());
    Thread.sleep(2000);
    MessageChannel y3 = singleNodeApplication.pluginContext().getBean("queue:y", MessageChannel.class);
    MessageChannel z3 = singleNodeApplication.pluginContext().getBean("queue:z", MessageChannel.class);
    assertNotNull(y3);
    assertNotNull(z3);
View Full Code Here

    }
    assertFalse(singleNodeApplication.pluginContext().containsBean("topic:y"));
    assertFalse(singleNodeApplication.pluginContext().containsBean("topic:z"));


    DirectChannel testChannel = new DirectChannel();
    bus.bindPubSubProducer("topic:x", testChannel, null);
    testChannel.send(MessageBuilder.withPayload("y").build());
    Thread.sleep(2000);

    singleNodeApplication.pluginContext().getBean("topic:y", MessageChannel.class);
    assertFalse(singleNodeApplication.pluginContext().containsBean("topic:z"));

    testChannel.send(MessageBuilder.withPayload("z").build());
    Thread.sleep(2000);
    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());
View Full Code Here

TOP

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

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.