title: High Performance DefaultMessageListenerContainer config for thousands of topics
body: <p>for my current project i need to consume messages from many destinations (from hundreds up to 20 or 30k) all destinations are topics. currently (for initial load tests) all messages are created localy on the same server, in a thread pool.</p>
  
  <p>my current spring config uses an embedded activemq in a network of brokers (for clustering) and DefaultMessageListenerContainers (DMLCs) with a common TaskExecutor. while the number of destinations is very high, the throughput of each destination is relatively low.</p>
  
  <p>My only requirement is that all messages are consumed as soon as possible.</p>
  
  <p>My Config:</p>
  
  <pre><code>&lt;bean id="connectionfactory" class="org.springframework.jms.connection.CachingConnectionFactory" destroy-method="destroy"&gt;
      &lt;property name="targetConnectionFactory"&gt;
          &lt;ref bean="amqConnectionFactory" /&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  &lt;bean id="amqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"&gt;
      &lt;property name="brokerURL" value="vm://localhost:61616?async=false&amp;amp;jms.dispatchAsync=false" /&gt;
      &lt;property name="userName" value="admin" /&gt;
      &lt;property name="password" value="admin" /&gt;
  &lt;/bean&gt;
  &lt;bean id="listenerThreadPoolTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"&gt;
      &lt;property name="corePoolSize" value="70" /&gt;
      &lt;property name="maxPoolSize" value="70" /&gt;
      &lt;property name="daemon" value="true" /&gt;
      &lt;property name="keepAliveSeconds" value="60" /&gt;
  &lt;/bean&gt;
  
  &lt;!-- Message Listener Container Template for Topics --&gt;
  &lt;bean id="topiccontainertemplate" class="org.springframework.jms.listener.DefaultMessageListenerContainer" scope="prototype"
      destroy-method="destroy"&gt;
      &lt;property name="autoStartup" value="false" /&gt;
      &lt;property name="connectionFactory" ref="connectionfactory" /&gt;
      &lt;property name="pubSubDomain" value="true" /&gt;
      &lt;property name="cacheLevelName" value="CACHE_CONSUMER" /&gt;
      &lt;property name="destinationName" value="default" /&gt;
      &lt;property name="maxMessagesPerTask" value="1" /&gt;
      &lt;property name="receiveTimeout" value="1" /&gt;
      &lt;property name="taskExecutor" ref="listenerThreadPoolTaskExecutor" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>My code uses the application context as a DMLC-Factory and sets the final configuration of the container:</p>
  
  <pre><code>    AbstractMessageListenerContainer container = context.getBean("simpletopiccontainertemplate", AbstractMessageListenerContainer.class);
      container.setDestinationName(localEntity.getId().getDestination());
      container.setMessageListener(mylistener);
      container.start();
  </code></pre>
  
  <p>while we don't lose messages in this configuration the transition time for an individual message can be very long.</p>
  
  <p><strong>Q1:</strong> Is there a more efficient way to listen to a big number of destinations?</p>
  
  <p><strong>Q2:</strong> Are there possible improvements for my listener configuration?</p>
  
  <p><strong>Q3:</strong> Beside the DMLC i also tried the SimpleMessageListenerContainer but i couldn't get it to work. is there something wrong with my config?</p>
  
  <pre><code>&lt;bean id="simpletopiccontainertemplate" class="org.springframework.jms.listener.SimpleMessageListenerContainer" scope="prototype"
      destroy-method="destroy"&gt;
      &lt;property name="autoStartup" value="false" /&gt;
      &lt;property name="connectionFactory" ref="connectionfactory" /&gt;
      &lt;property name="destinationName" value="default" /&gt;
      &lt;property name="concurrency" value="1" /&gt;
      &lt;property name="pubSubDomain" value="true" /&gt;
      &lt;property name="taskExecutor" ref="listenerThreadPoolTaskExecutor" /&gt;
  &lt;/bean&gt;
  </code></pre>