问题
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