How to create DefaultMessageListenerContainer in Spring-Boot?

…衆ロ難τιáo~ 提交于 2021-01-29 04:55:41

问题


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>

回答1:


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.



来源:https://stackoverflow.com/questions/52050440/how-to-create-defaultmessagelistenercontainer-in-spring-boot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!