How can I allow multiple @JmsListener destinations for a single method

扶醉桌前 提交于 2020-07-23 09:49:05

问题


I'm currently working on migrating an IBM Webshere application to Spring Boot.

As part of this there is an MDB class which needs to be converted into @JmsListener. This MDB has a single method that is listening to multiple queues. I would like to do the same using @JmsListener with multiple destinations. I saw this thread, but that's not working.

This is the current MDB Configuration :

Bean 1

<bean id="myAppabcResponseMDB" class="company.myApp.service.mdb.MyAppMessageListenerMDB"/>
    <bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
        <property name="connectionFactory" ref="jmsConnectionFactory"/>
        <property name="destination" ref="myAppabcResponseDest"/>
        <property name="messageListener" ref="myAppabcResponseMDB"/>
        <property name="maxConcurrentConsumers" value="5"/>
        <property name="sessionTransacted" value="true"/>
        <property name="transactionManager" ref="transactionManager" />
        <property name="taskExecutor" ref="myTaskExecutor" />
      </bean>
      <bean id="myAppabcResponseDest" name="jms/myAppESBResponse" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="jms/myAppabcResponse"/>
        <property name="resourceRef" value="true"/>
      </bean>

<bean id="myAppRequestMDB" class="company.myApp.service.mdb.MyAppMessageListenerMDB"/>
  <bean id="jmsContainer2" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <property name="connectionFactory" ref="jmsConnectionFactory"/>
    <property name="destination" ref="myAppRequestDest"/>
    <property name="messageListener" ref="myAppRequestMDB"/>
    <property name="maxConcurrentConsumers" value="1"/>
    <property name="sessionTransacted" value="true"/>
    <property name="transactionManager" ref="transactionManager" />
    <property name="taskExecutor" ref="myTaskExecutor" />
  </bean>
  <bean id="myAppRequestDest" name="jms/myAppRequest" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jms/myAppRequest"/>
    <property name="resourceRef" value="true"/>
  </bean>

回答1:


@JmsListener is a repeatable annotation on Java 8, so you can associate several JMS destinations with the same method by adding additional @JmsListener declarations to it.

https://docs.spring.io/spring/docs/current/spring-framework-reference/integration.html#jms-annotated



来源:https://stackoverflow.com/questions/60537996/how-can-i-allow-multiple-jmslistener-destinations-for-a-single-method

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