title: How to manually acknowledge message from ActiveMQ using Spring JmsListener
body: <p>I am using ActiveMQ (with JMS) with Spring's JmsListener. I am able to consume messages from an ActiveMQ queue, but it is using <code>AUTO_ACKNOWLEDGE</code>. How can I set <code>CLIENT_ACKNOWLEDGE</code> so that I can consume the other message only after that acknowledgment.</p>
  
  <pre class="lang-java prettyprint-override"><code>@Bean
  public ActiveMQConnectionFactory connectionFactory() {
      ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
      activeMQConnectionFactory.setTransactedIndividualAck(true);
      activeMQConnectionFactory.setUserName(mqUserName);
      activeMQConnectionFactory.setPassword(mqPassword);
      activeMQConnectionFactory.setBrokerURL(mqUrl);
      return activeMQConnectionFactory;
  }
  
  @Bean
  public JmsListenerContainerFactory myFactory(ConnectionFactory connectionFactory, DefaultJmsListenerContainerFactoryConfigurer configurer) {
  
      DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
      factory.setErrorHandler(t -&gt; {
          logger.info("An error has occurred in the transaction");
          logger.error(t.getCause().getMessage());
      });
  
      configurer.configure(factory, connectionFactory);
      factory.setConcurrency("4");
  
      // You could still override some of Boot's default if necessary.
      return factory;
  }
  
  @Bean
  public MessageConverter jacksonJmsMessageConverter() {
      MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
      converter.setTargetType(MessageType.TEXT);
      converter.setTypeIdPropertyName("_type");
      return converter;
  }
  
  @JmsListener(destination = "QUEUE_1", containerFactory = "myFactory", concurrency = "2")
  public void receiveImgGenerationMessage(String transaction) {
      logger.info("message received in queue " + transaction);
      //I will call other api to process the message and do some operation 
      //after the message is processed 
      //I have to Acknowledge the message is processed
      //so that i can consume the other message for process.
  }
  
  // jmsTemplate bean
  public void sendmessage() {
      for (int i =0 ; i &lt; 10 ; &lt; i++) { 
          jmsTemplate.convertAndSend("QUEUE_1", i);
      }
  }
  </code></pre>