title: Set maximum consumer count jms solace
body: <p>I am trying to set the maximum consumer count of a topic endpoint with jms using solace as a broker, so for increasing load, multiple instances of the app can be started in cloudfoundry, and multiple subscribers can consume messages of the same topic.</p>
  
  <p>I have tried multiple combinations of the below settings (<code>setConcurrency(), setConcurrentConsumers(), setMaxConcurrentConsumers()</code>, (20 as an arbitrary high number). Judging from the documentation, I definitely need to use <code>setMaxConcurrentConsumers()</code> and set this to an appropriately high value.</p>
  
  <p>When I deploy the app, the topic endpoint gets created, but when I look at the solace management interface, the maximum consumer count is always 1 (as can be seen here: <code>Queues -&gt; Topic Endpoints -&gt; select endpoint -&gt; Configured Limit</code>), even though it should be 20. So the second consumer is not able to connect. I don't want to set this manually every time I deploy the app.</p>
  
  <p><a href="https://i.stack.imgur.com/rjiCB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rjiCB.png" alt="Screenshot of my solace management interface"></a></p>
  
  <pre><code>import javax.jms.*;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.jms.connection.CachingConnectionFactory;
  import org.springframework.jms.core.JmsTemplate;
  import org.springframework.jms.listener.DefaultMessageListenerContainer;
  
  @Configuration
  public class ProducerConfiguration {
  
      private static final Log logger = LogFactory.getLog(SolaceController.class);
  
      @Value("${durable_subscription}")
      private String subscriptionName;
  
      @Value("${topic_name}")
      private String topic_name;
  
      @Autowired
      private ConnectionFactory connectionFactory;
  
      @Bean
      public JmsTemplate jmsTemplate() {
          CachingConnectionFactory ccf = new CachingConnectionFactory(connectionFactory);
          JmsTemplate jmst = new JmsTemplate(ccf);
          jmst.setPubSubDomain(true);
          return jmst;
      }
  
      @Bean
      public Session configureSession(ConnectionFactory connectionFactory) throws JMSException {
          return connectionFactory.createConnection().createSession(false, Session.AUTO_ACKNOWLEDGE);
      }
  
  
      private TextMessage lastReceivedMessage;
  
      public class SimpleMessageListener implements MessageListener {
          @Override
          public void onMessage(Message message) {
  
              if (message instanceof TextMessage) {
                  lastReceivedMessage = (TextMessage) message;
                  try {
                      logger.info("Received message : " + lastReceivedMessage.getText());
                  } catch (JMSException e) {
                      logger.error("Error getting text of the received TextMessage: " + e);
                  }
              } else {
                  logger.error("Received message that was not a TextMessage: " + message);
              }
          }
      }
  
      @Bean
      public DefaultMessageListenerContainer orderMessageListenerContainer() {
  
          DefaultMessageListenerContainer lc = new DefaultMessageListenerContainer();
          lc.setConnectionFactory(connectionFactory);
          lc.setDestinationName(topic_name);
          lc.setMessageListener(new SimpleMessageListener());
          lc.setDurableSubscriptionName(subscriptionName);
          lc.setPubSubDomain(true);
  
          //tried multiple combinations here, also setting only setMaxConcurrentConsumers
          lc.setConcurrency("2-20");
          lc.setConcurrentConsumers(20);
          lc.setMaxConcurrentConsumers(20);
  
          lc.setSubscriptionDurable(true);
          lc.initialize();
          lc.start();
          return lc;
      }
  }
  </code></pre>