Package org.springframework.integration.channel

Examples of org.springframework.integration.channel.DirectChannel


    MessageBus bus = getMessageBus();
    Properties properties = new Properties();
    properties.put("foo", "bar");
    properties.put("baz", "qux");

    DirectChannel output = new DirectChannel();
    try {
      bus.bindProducer("badprops.0", output, properties);
    }
    catch (IllegalArgumentException e) {
      assertThat(e.getMessage(), allOf(Matchers.containsString(bus.getClass().getSimpleName().replace("Test", "")
View Full Code Here


    Properties properties = new Properties();
    properties.put("partitionKeyExpression", "payload");
    properties.put("partitionSelectorExpression", "hashCode()");
    properties.put("partitionCount", "3");

    DirectChannel output = new DirectChannel();
    output.setBeanName("test.output");
    bus.bindProducer("part.0", output, properties);
    @SuppressWarnings("unchecked")
    List<Binding> bindings = TestUtils.getPropertyValue(bus, "messageBus.bindings", List.class);
    assertEquals(1, bindings.size());
    try {
      AbstractEndpoint endpoint = bindings.get(0).getEndpoint();
      assertThat(getEndpointRouting(endpoint), containsString("part.0-' + headers['partition']"));
    }
    catch (UnsupportedOperationException ignored) {

    }

    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);
View Full Code Here

    Properties properties = new Properties();
    properties.put("partitionKeyExtractorClass", "org.springframework.xd.dirt.integration.bus.PartitionTestSupport");
    properties.put("partitionSelectorClass", "org.springframework.xd.dirt.integration.bus.PartitionTestSupport");
    properties.put("partitionCount", "3");

    DirectChannel output = new DirectChannel();
    output.setBeanName("test.output");
    bus.bindProducer("partJ.0", output, properties);
    @SuppressWarnings("unchecked")
    List<Binding> bindings = TestUtils.getPropertyValue(bus, "messageBus.bindings", List.class);
    assertEquals(1, bindings.size());
    if (usesExplicitRouting()) {
      AbstractEndpoint endpoint = bindings.get(0).getEndpoint();
      assertThat(getEndpointRouting(endpoint), containsString("partJ.0-' + headers['partition']"));
    }

    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);
View Full Code Here

        .setIndex(1)
        .setModuleDefinition(moduleDefinition)
        .build());
    when(module.getComponent(MessageBus.class)).thenReturn(bus);
    when(module.getName()).thenReturn(moduleDefinition.getName());
    DirectChannel output = new DirectChannel();
    MessageChannel proxy = (MessageChannel) new ProxyFactory(output).getProxy();
    when(module.getComponent("output", MessageChannel.class)).thenReturn(proxy);
    plugin.postProcessModule(module);
    List<?> interceptors = TestUtils.getPropertyValue(output, "interceptors.interceptors", List.class);
    assertEquals(0, interceptors.size());
View Full Code Here

  @Test
  public void testConsumerProperties() throws Exception {
    MessageBus bus = getMessageBus();
    Properties properties = new Properties();
    properties.put("maxAttempts", "1"); // disable retry
    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();
    assertThat(endpoint, instanceOf(RedisQueueMessageDrivenEndpoint.class));
    assertSame(DirectChannel.class, TestUtils.getPropertyValue(endpoint, "outputChannel").getClass());
    bus.unbindConsumers("props.0");
    assertEquals(0, bindings.size());

    properties.put("backOffInitialInterval", "2000");
    properties.put("backOffMaxInterval", "20000");
    properties.put("backOffMultiplier", "5.0");
    properties.put("concurrency", "2");
    properties.put("maxAttempts", "23");
    properties.put("partitionIndex", 0);

    bus.bindConsumer("props.0", new DirectChannel(), properties);
    assertEquals(1, bindings.size());
    endpoint = bindings.get(0).getEndpoint();
    verifyConsumer(endpoint);

    try {
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(
        "queue.props.0",
        TestUtils.getPropertyValue(endpoint, "handler.delegate.queueNameExpression", Expression.class).getExpressionString());
    bus.unbindProducers("props.0");
    assertEquals(0, bindings.size());

    Properties properties = new Properties();
    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(
        "'queue.props.0-' + headers['partition']",
        TestUtils.getPropertyValue(endpoint, "handler.delegate.queueNameExpression", Expression.class).getExpressionString());

    try {
      bus.bindPubSubProducer("dummy", null, properties);
      fail("Expected exception");
    }
    catch (IllegalArgumentException e) {
      assertThat(e.getMessage(), allOf(
          containsString("RedisMessageBus 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("RedisMessageBus does not support producer properties: "),
View Full Code Here

    properties.put("backOffMaxInterval", "20000");
    properties.put("backOffMultiplier", "5.0");
    properties.put("concurrency", "2");
    properties.put("maxAttempts", "23");

    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
    assertEquals(
        "queue.props.0.requests",
        TestUtils.getPropertyValue(endpoint, "handler.delegate.queueNameExpression", Expression.class).getExpressionString());

    endpoint = bindings.get(1).getEndpoint(); // consumer
    verifyConsumer(endpoint);

    properties.put("partitionKeyExpression", "'foo'");
    properties.put("partitionKeyExtractorClass", "foo");
    properties.put("partitionSelectorExpression", "0");
    properties.put("partitionSelectorClass", "foo");
    properties.put("partitionCount", "1");
    properties.put("partitionIndex", "0");
    try {
      bus.bindRequestor("dummy", new DirectChannel(), new DirectChannel(), properties);
      fail("Expected exception");
    }
    catch (IllegalArgumentException e) {
      assertThat(e.getMessage(), allOf(
          containsString("RedisMessageBus does not support producer properties: "),
View Full Code Here

    properties.put("backOffMaxInterval", "20000");
    properties.put("backOffMultiplier", "5.0");
    properties.put("concurrency", "2");
    properties.put("maxAttempts", "23");

    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
    assertEquals(
        "headers['replyTo']",
        TestUtils.getPropertyValue(endpoint, "handler.delegate.queueNameExpression", Expression.class).getExpressionString());

    endpoint = bindings.get(0).getEndpoint(); // consumer
    verifyConsumer(endpoint);

    properties.put("partitionKeyExpression", "'foo'");
    properties.put("partitionKeyExtractorClass", "foo");
    properties.put("partitionSelectorExpression", "0");
    properties.put("partitionSelectorClass", "foo");
    properties.put("partitionCount", "1");
    properties.put("partitionIndex", "0");
    try {
      bus.bindReplier("dummy", new DirectChannel(), new DirectChannel(), properties);
      fail("Expected exception");
    }
    catch (IllegalArgumentException e) {
      assertThat(e.getMessage(), allOf(
          containsString("RedisMessageBus does not support consumer properties: "),
View Full Code Here

  }

  private void verifyConsumer(AbstractEndpoint endpoint) {
    assertThat(endpoint.getClass().getName(), containsString("CompositeRedisQueueMessageDrivenEndpoint"));
    assertEquals(2, TestUtils.getPropertyValue(endpoint, "consumers", Collection.class).size());
    DirectChannel channel = TestUtils.getPropertyValue(
        TestUtils.getPropertyValue(endpoint, "consumers", List.class).get(0),
        "outputChannel", DirectChannel.class);
    assertThat(
        channel.getClass().getName(), containsString("RedisMessageBus$")); // retry wrapper
    assertThat(
        TestUtils.getPropertyValue(TestUtils.getPropertyValue(endpoint, "consumers", List.class).get(1),
            "outputChannel").getClass().getName(), containsString("RedisMessageBus$")); // retry wrapper
    RetryTemplate retry = TestUtils.getPropertyValue(channel, "val$retryTemplate", RetryTemplate.class);
    assertEquals(23, TestUtils.getPropertyValue(retry, "retryPolicy.maxAttempts"));
View Full Code Here

  }

  @Test
  public void testRetryFail() {
    MessageBus bus = getMessageBus();
    DirectChannel channel = new DirectChannel();
    bus.bindProducer("retry.0", channel, null);
    Properties props = new Properties();
    props.put("maxAttempts", 2);
    props.put("backOffInitialInterval", 100);
    props.put("backOffMultiplier", "1.0");
    bus.bindConsumer("retry.0", new DirectChannel(), props); // no subscriber
    channel.send(new GenericMessage<String>("foo"));
    RedisTemplate<String, Object> template = createTemplate();
    Object rightPop = template.boundListOps("ERRORS:retry.0").rightPop(5, TimeUnit.SECONDS);
    assertNotNull(rightPop);
    assertThat(new String((byte[]) rightPop), containsString("foo"));
  }
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.