如何为单个方法允许多个@JmsListener目标 [英] How can I allow multiple @JmsListener destinations for a single method

查看:337
本文介绍了如何为单个方法允许多个@JmsListener目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在将IBM Webshere应用程序迁移到Spring Boot.

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

作为此过程的一部分,有一个MDB类需要转换为@JmsListener.此MDB具有侦听多个队列的单个方法.我想对多个目标使用@JmsListener来执行相同的操作.我看到了此线程,但这不起作用.

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.

这是当前的MDB配置:

This is the current MDB Configuration :

豆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>

推荐答案

@JmsListener是Java 8上的可重复注释,因此您可以通过向其添加其他@JmsListener声明,将多个JMS目标与同一方法相关联.

@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-注释

这篇关于如何为单个方法允许多个@JmsListener目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆