java – How to create a Spring Boot consumer for an ActiveMQ queue?

java – How to create a Spring Boot consumer for an ActiveMQ queue?

For your consumer app, you do need to add Pool connection factory & JMS message listener factory for your consumer JMStemplate to start receiving messages.

@Configuration
@EnableJms
public class ConsumerConfig {

  @Value(${activemqbrokerurl})
  private String brokerUrl;

  @Bean
  public ActiveMQConnectionFactory activeMQConnectionFactory() {
    ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
    activeMQConnectionFactory.setBrokerURL(brokerUrl);
    return activeMQConnectionFactory;
  }

  @Bean
  public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
    factory.setConnectionFactory(activeMQConnectionFactory());
    factory.setConcurrency({#setDesiredConcurrency});
    return factory;
  }
}

Springs MessagListenerContainer should be used for message consumption. This provides all the power of MDBs – efficient JMS consumption and pooling of the message listeners – but without requiring a full EJB container.

You can use the activemq-pool org.apache.activemq.pool.PooledConnectionFactory for efficient pooling of the connections and sessions for your collection of consumers, or you can use the Spring JMS org.springframework.jms.connection.CachingConnectionFactory to achieve the same effect.

You can read more about it here

java – How to create a Spring Boot consumer for an ActiveMQ queue?

Leave a Reply

Your email address will not be published. Required fields are marked *