简体   繁体   中英

How to create DefaultMessageListenerContainer in Spring-Boot?

I am new to Spring-Boot and trying to create DefaultMessageListenerContainer so I can use the weblogic workmanager and run several message listeners in multithreaded fashion.

Can someone please provide some example. So far, I found the below solution but how do I implement this in Spring-Boot?

<bean class="org.springframework.jms.listener.SimpleMessageListenerContainer">
    <property name="connectionFactory" ref="connectionFactory"/>
    <property name="destination" ref="destination"/>
    <property name="messageListener" ref="receiver"/>
    <property name="taskExecutor" ref="taskExecutor"/>
</bean>

Create a ConnectionFactory :

  @Bean
  public ActiveMQConnectionFactory receiverActiveMQConnectionFactory() {
    ActiveMQConnectionFactory activeMQConnectionFactory =
        new ActiveMQConnectionFactory();
    activeMQConnectionFactory.setBrokerURL("yourBrokerUrl");

    return activeMQConnectionFactory;
  }

Create a DefaultJmsListenerContainerFactory :

  @Bean
  public DefaultJmsListenerContainerFactory orderDefaultJmsListenerContainerFactory() {
    DefaultJmsListenerContainerFactory factory =
        new DefaultJmsListenerContainerFactory();
    factory
        .setConnectionFactory(receiverActiveMQConnectionFactory());
    factory.setConcurrency("3-10");

    return factory;
  }

Create your DefaultMessageListenerContainer :

  @Bean
  public DefaultMessageListenerContainer orderMessageListenerContainer() {
    SimpleJmsListenerEndpoint endpoint =
        new SimpleJmsListenerEndpoint();
    endpoint.setMessageListener(new YourMessageListener());
    endpoint.setDestination("yourDestination");

    return orderDefaultJmsListenerContainerFactory()
        .createListenerContainer(endpoint);
  }

For a more detailed example checkout this post I created on Spring JMS listeners .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM