@Test
  public void testContainerConfiguration() throws Exception {
    Map<String, DefaultMessageListenerContainer> containers =
        context.getBeansOfType(DefaultMessageListenerContainer.class);
    ConnectionFactory defaultConnectionFactory =
        context.getBean(DEFAULT_CONNECTION_FACTORY, ConnectionFactory.class);
    ConnectionFactory explicitConnectionFactory =
        context.getBean(EXPLICIT_CONNECTION_FACTORY, ConnectionFactory.class);

    int defaultConnectionFactoryCount = 0;
    int explicitConnectionFactoryCount = 0;

    for (DefaultMessageListenerContainer container : containers.values()) {
      if (container.getConnectionFactory().equals(defaultConnectionFactory)) {
        defaultConnectionFactoryCount++;
        assertEquals(2, container.getConcurrentConsumers());
        assertEquals(3, container.getMaxConcurrentConsumers());
      } else if (container.getConnectionFactory().equals(explicitConnectionFactory)) {
        explicitConnectionFactoryCount++;
        assertEquals(1, container.getConcurrentConsumers());
        assertEquals(2, container.getMaxConcurrentConsumers());
      }
    }

    assertEquals(
        "1 container should have the default connectionFactory", 1, defaultConnectionFactoryCount);
    assertEquals(
        "2 containers should have the explicit connectionFactory",
        2,
        explicitConnectionFactoryCount);
  }
 @Test
 public void channelWithConcurrencySettings() {
   assertEquals(
       JmsDestinationBackedMessageChannel.class, channelWithConcurrencySettings.getClass());
   JmsDestinationBackedMessageChannel channel =
       (JmsDestinationBackedMessageChannel) channelWithConcurrencySettings;
   DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
   DefaultMessageListenerContainer container =
       (DefaultMessageListenerContainer) accessor.getPropertyValue("container");
   assertEquals(11, container.getConcurrentConsumers());
   assertEquals(55, container.getMaxConcurrentConsumers());
 }
 @Test
 public void testJmsListenerContainerFactoryWithCustomSettings() {
   load(
       EnableJmsConfiguration.class,
       "spring.jms.listener.autoStartup=false",
       "spring.jms.listener.acknowledgeMode=client",
       "spring.jms.listener.concurrency=2",
       "spring.jms.listener.maxConcurrency=10");
   JmsListenerContainerFactory<?> jmsListenerContainerFactory =
       this.context.getBean("jmsListenerContainerFactory", JmsListenerContainerFactory.class);
   assertThat(jmsListenerContainerFactory.getClass())
       .isEqualTo(DefaultJmsListenerContainerFactory.class);
   DefaultMessageListenerContainer listenerContainer =
       ((DefaultJmsListenerContainerFactory) jmsListenerContainerFactory)
           .createListenerContainer(mock(JmsListenerEndpoint.class));
   assertThat(listenerContainer.isAutoStartup()).isFalse();
   assertThat(listenerContainer.getSessionAcknowledgeMode()).isEqualTo(Session.CLIENT_ACKNOWLEDGE);
   assertThat(listenerContainer.getConcurrentConsumers()).isEqualTo(2);
   assertThat(listenerContainer.getMaxConcurrentConsumers()).isEqualTo(10);
 }
  @Test
  public void createJmsContainerFullConfig() {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    setDefaultJmsConfig(factory);
    factory.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONSUMER);
    factory.setConcurrency("3-10");
    factory.setMaxMessagesPerTask(5);

    SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
    MessageListener messageListener = new MessageListenerAdapter();
    endpoint.setMessageListener(messageListener);
    endpoint.setDestination("myQueue");
    DefaultMessageListenerContainer container = factory.createListenerContainer(endpoint);

    assertDefaultJmsConfig(container);
    assertEquals(DefaultMessageListenerContainer.CACHE_CONSUMER, container.getCacheLevel());
    assertEquals(3, container.getConcurrentConsumers());
    assertEquals(10, container.getMaxConcurrentConsumers());
    assertEquals(5, container.getMaxMessagesPerTask());

    assertEquals(messageListener, container.getMessageListener());
    assertEquals("myQueue", container.getDestinationName());
  }
  @Override
  protected AbstractMessageListenerContainer createListenerContainer() throws Exception {
    // Use DefaultMessageListenerContainer as it supports reconnects (see CAMEL-3193)
    // request-reply listener container should not allow quick-stop so we can keep listening for
    // reply messages
    DefaultMessageListenerContainer answer =
        new DefaultJmsMessageListenerContainer(endpoint, false);

    answer.setDestinationName("temporary");
    answer.setDestinationResolver(destResolver);
    answer.setAutoStartup(true);
    if (endpoint.getMaxMessagesPerTask() >= 0) {
      answer.setMaxMessagesPerTask(endpoint.getMaxMessagesPerTask());
    }
    answer.setIdleConsumerLimit(endpoint.getIdleConsumerLimit());
    answer.setIdleTaskExecutionLimit(endpoint.getIdleTaskExecutionLimit());
    answer.setMessageListener(this);
    answer.setPubSubDomain(false);
    answer.setSubscriptionDurable(false);
    answer.setConcurrentConsumers(endpoint.getConcurrentConsumers());
    if (endpoint.getMaxConcurrentConsumers() > 0) {
      answer.setMaxConcurrentConsumers(endpoint.getMaxConcurrentConsumers());
    }
    answer.setConnectionFactory(endpoint.getConnectionFactory());
    // we use CACHE_CONSUMER by default to cling to the consumer as long as we can, since we can
    // only consume
    // msgs from the JMS Connection that created the temp destination in the first place
    if (endpoint.getReplyToCacheLevelName() != null) {
      if ("CACHE_NONE".equals(endpoint.getReplyToCacheLevelName())) {
        throw new IllegalArgumentException(
            "ReplyToCacheLevelName cannot be CACHE_NONE when using temporary reply queues. The value must be either CACHE_CONSUMER, or CACHE_SESSION");
      }
      answer.setCacheLevelName(endpoint.getReplyToCacheLevelName());
    } else {
      answer.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONSUMER);
    }
    String clientId = endpoint.getClientId();
    if (clientId != null) {
      clientId += ".CamelReplyManager";
      answer.setClientId(clientId);
    }

    // we cannot do request-reply over JMS with transaction
    answer.setSessionTransacted(false);

    // other optional properties
    answer.setExceptionListener(
        new TemporaryReplyQueueExceptionListener(destResolver, endpoint.getExceptionListener()));

    if (endpoint.getErrorHandler() != null) {
      answer.setErrorHandler(endpoint.getErrorHandler());
    } else {
      answer.setErrorHandler(
          new DefaultSpringErrorHandler(
              TemporaryQueueReplyManager.class,
              endpoint.getErrorHandlerLoggingLevel(),
              endpoint.isErrorHandlerLogStackTrace()));
    }
    if (endpoint.getReceiveTimeout() >= 0) {
      answer.setReceiveTimeout(endpoint.getReceiveTimeout());
    }
    if (endpoint.getRecoveryInterval() >= 0) {
      answer.setRecoveryInterval(endpoint.getRecoveryInterval());
    }
    if (endpoint.getTaskExecutor() != null) {
      if (log.isDebugEnabled()) {
        log.debug(
            "Using custom TaskExecutor: {} on listener container: {}",
            endpoint.getTaskExecutor(),
            answer);
      }
      answer.setTaskExecutor(endpoint.getTaskExecutor());
    }

    // setup a bean name which is used by Spring JMS as the thread name
    // use the name of the request destination
    String name = "TemporaryQueueReplyManager[" + endpoint.getDestinationName() + "]";
    answer.setBeanName(name);

    if (answer.getConcurrentConsumers() > 1) {
      // log that we are using concurrent consumers
      log.info(
          "Using {}-{} concurrent consumers on {}",
          new Object[] {answer.getConcurrentConsumers(), answer.getMaxConcurrentConsumers(), name});
    }
    return answer;
  }