コード例 #1
0
  private SimpleMessageListenerContainer verifyContainer(AbstractEndpoint endpoint) {
    SimpleMessageListenerContainer container;
    Advice retry;
    container =
        TestUtils.getPropertyValue(
            endpoint, "messageListenerContainer", SimpleMessageListenerContainer.class);
    assertEquals(AcknowledgeMode.NONE, container.getAcknowledgeMode());
    assertThat(container.getQueueNames()[0], startsWith("foo.props.0"));
    assertFalse(TestUtils.getPropertyValue(container, "transactional", Boolean.class));
    assertEquals(2, TestUtils.getPropertyValue(container, "concurrentConsumers"));
    assertEquals(3, TestUtils.getPropertyValue(container, "maxConcurrentConsumers"));
    assertFalse(TestUtils.getPropertyValue(container, "defaultRequeueRejected", Boolean.class));
    assertEquals(20, TestUtils.getPropertyValue(container, "prefetchCount"));
    assertEquals(10, TestUtils.getPropertyValue(container, "txSize"));
    retry = TestUtils.getPropertyValue(container, "adviceChain", Advice[].class)[0];
    assertEquals(23, TestUtils.getPropertyValue(retry, "retryOperations.retryPolicy.maxAttempts"));
    assertEquals(
        2000L, TestUtils.getPropertyValue(retry, "retryOperations.backOffPolicy.initialInterval"));
    assertEquals(
        20000L, TestUtils.getPropertyValue(retry, "retryOperations.backOffPolicy.maxInterval"));
    assertEquals(
        5.0, TestUtils.getPropertyValue(retry, "retryOperations.backOffPolicy.multiplier"));

    List<?> requestMatchers =
        TestUtils.getPropertyValue(
            endpoint, "headerMapper.requestHeaderMatcher.strategies", List.class);
    assertEquals(1, requestMatchers.size());
    assertEquals(
        "foo",
        TestUtils.getPropertyValue(requestMatchers.get(0), "patterns", Collection.class)
            .iterator()
            .next());

    return container;
  }
コード例 #2
0
 @Test
 public void testParseWithQueueNames() throws Exception {
   SimpleMessageListenerContainer container =
       beanFactory.getBean("container1", SimpleMessageListenerContainer.class);
   assertEquals(AcknowledgeMode.MANUAL, container.getAcknowledgeMode());
   assertEquals(beanFactory.getBean(ConnectionFactory.class), container.getConnectionFactory());
   assertEquals(MessageListenerAdapter.class, container.getMessageListener().getClass());
   DirectFieldAccessor listenerAccessor = new DirectFieldAccessor(container.getMessageListener());
   assertEquals(
       beanFactory.getBean(TestBean.class), listenerAccessor.getPropertyValue("delegate"));
   assertEquals("handle", listenerAccessor.getPropertyValue("defaultListenerMethod"));
   Queue queue = beanFactory.getBean("bar", Queue.class);
   assertEquals(
       "[foo, " + queue.getName() + "]", Arrays.asList(container.getQueueNames()).toString());
   assertEquals(5, ReflectionTestUtils.getField(container, "concurrentConsumers"));
   assertEquals(6, ReflectionTestUtils.getField(container, "maxConcurrentConsumers"));
   assertEquals(1234L, ReflectionTestUtils.getField(container, "startConsumerMinInterval"));
   assertEquals(2345L, ReflectionTestUtils.getField(container, "stopConsumerMinInterval"));
   assertEquals(12, ReflectionTestUtils.getField(container, "consecutiveActiveTrigger"));
   assertEquals(34, ReflectionTestUtils.getField(container, "consecutiveIdleTrigger"));
   assertEquals(9876L, ReflectionTestUtils.getField(container, "receiveTimeout"));
   Map<?, ?> consumerArgs = TestUtils.getPropertyValue(container, "consumerArgs", Map.class);
   assertEquals(1, consumerArgs.size());
   Object xPriority = consumerArgs.get("x-priority");
   assertNotNull(xPriority);
   assertEquals(10, xPriority);
   assertEquals(
       Long.valueOf(5555),
       TestUtils.getPropertyValue(container, "recoveryBackOff.interval", Long.class));
   assertFalse(TestUtils.getPropertyValue(container, "exclusive", Boolean.class));
   assertFalse(TestUtils.getPropertyValue(container, "missingQueuesFatal", Boolean.class));
   assertTrue(TestUtils.getPropertyValue(container, "autoDeclare", Boolean.class));
   assertEquals(5, TestUtils.getPropertyValue(container, "declarationRetries"));
   assertEquals(1000L, TestUtils.getPropertyValue(container, "failedDeclarationRetryInterval"));
   assertEquals(30000L, TestUtils.getPropertyValue(container, "retryDeclarationInterval"));
   assertEquals(
       beanFactory.getBean("tagger"),
       TestUtils.getPropertyValue(container, "consumerTagStrategy"));
   Collection<?> group = beanFactory.getBean("containerGroup", Collection.class);
   assertEquals(3, group.size());
   assertThat(
       group,
       Matchers.contains(
           beanFactory.getBean("container1"),
           beanFactory.getBean("testListener1"),
           beanFactory.getBean("testListener2")));
   assertEquals(1235L, ReflectionTestUtils.getField(container, "idleEventInterval"));
   assertEquals("container1", container.getListenerId());
 }
 @Test
 public void testParseWithQueueNames() throws Exception {
   SimpleMessageListenerContainer container =
       this.context.getBean("testListener", SimpleMessageListenerContainer.class);
   assertEquals(AcknowledgeMode.MANUAL, container.getAcknowledgeMode());
   assertEquals(this.context.getBean(ConnectionFactory.class), container.getConnectionFactory());
   assertEquals(MessageListenerAdapter.class, container.getMessageListener().getClass());
   DirectFieldAccessor listenerAccessor = new DirectFieldAccessor(container.getMessageListener());
   assertEquals(
       this.context.getBean(TestBean.class), listenerAccessor.getPropertyValue("delegate"));
   assertEquals("handle", listenerAccessor.getPropertyValue("defaultListenerMethod"));
   Queue queue = this.context.getBean("bar", Queue.class);
   assertEquals(
       "[foo, " + queue.getName() + "]", Arrays.asList(container.getQueueNames()).toString());
 }
コード例 #4
0
  @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();
    container = verifyContainer(endpoint);

    assertEquals("foo.props.0", container.getQueueNames()[0]);

    try {
      bus.bindPubSubConsumer("dummy", null, properties);
      fail("Expected exception");
    } catch (IllegalArgumentException e) {
      assertThat(
          e.getMessage(),
          allOf(
              containsString("RabbitMessageBus does not support consumer properties: "),
              containsString("partitionIndex"),
              containsString("concurrency"),
              containsString(" for dummy.")));
    }
    try {
      bus.bindConsumer("queue:dummy", null, properties);
      fail("Expected exception");
    } catch (IllegalArgumentException e) {
      assertEquals(
          "RabbitMessageBus does not support consumer property: partitionIndex for queue:dummy.",
          e.getMessage());
    }

    bus.unbindConsumers("props.0");
    assertEquals(0, bindingsNow.size());
  }