如何让Spring JMS从注释@JmsListener中选择目标队列名称

2024-02-03

任何帮助将不胜感激。我正在尝试使用 spring JMSListener 创建 MDB 的替代品。我希望将目的地名称作为注释传递,但我注意到org.springframework.jms.listener.DefaultMessageListenerContainer容器配置有destinationName or destination作为强制性的。我错过了什么吗?如何利用目标解析器来使用来自的队列名称@JmsListener注解?

@Component 
public class InitStRspnLstnr {

@JmsListener(destination = "${xyz.company.MQ.INITST.RSPN.FADS.Q}")
public void onMessage(Message msg) throws JMSException {
    System.out.println("**********************************************"+msg);
}}

下面是我粘贴的 Xml,我现在对容器进行了注释,因为 spring 试图连接到虚拟队列而不是注释中的队列。

        <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:util="http://www.springframework.org/schema/util"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:cxf="http://cxf.apache.org/core"    
        xmlns:jaxrs="http://cxf.apache.org/jaxrs"
        xmlns:jaxws="http://cxf.apache.org/jaxws"    
        xsi:schemaLocation="
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/mvc
            http://www.springframework.org/schema/mvc/spring-mvc.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context.xsd  
            http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
            http://cxf.apache.org/jaxrs
            http://cxf.apache.org/schemas/jaxrs.xsd
            http://cxf.apache.org/jaxws
            http://cxf.apache.org/schemas/jaxws.xsd
            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
            ">

        <import resource="classpath*:com/xyz/svc/component.xml"/>

        <mvc:annotation-driven enable-matrix-variables="true"/>
        <context:component-scan base-package="com.xyz.css.rplr.initst"></context:component-scan>

        <!-- WebSphere MQ Connection setup start -->
        <bean id="mqIdsConnectionFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory">
            <property name="hostName"><value>${xyz.company.MQ.HOST.NM}</value></property>
            <property name="port"><value>${xyz.company.MQ.PORT}</value></property>
            <property name="queueManager"><value>${xyz.company.MQ.QMNGR}</value></property>
            <property name="channel"><value>${xyz.company.MQ.CHANNEL}</value></property>
            <property name="CCSID"><value>819</value></property>
            <property name="transportType">
                <util:constant static-field="com.ibm.mq.jms.JMSC.MQJMS_TP_CLIENT_MQ_TCPIP" />
            </property>
        </bean>
        <bean id="jmsQueueIdsConnectionFactory"
            class="org.springframework.jms.connection.SingleConnectionFactory">
            <property name="targetConnectionFactory">
                <ref bean="mqIdsConnectionFactory" />
            </property>
        </bean>
        <bean id="jmsDestinationResolver"
            class="org.springframework.jms.support.destination.DynamicDestinationResolver">
        </bean>
        <bean id="jmsQueueIdsTemplate" class="org.springframework.jms.core.JmsTemplate">
            <property name="connectionFactory">
                <ref bean="jmsQueueIdsConnectionFactory" />
            </property>
            <property name="destinationResolver">
                <ref bean="jmsDestinationResolver" />
            </property> <!--    
            <property name="defaultDestinationName">
                <value>${xyz.company.MQ.INITST.Q}</value>
            </property>-->
            <property name="pubSubDomain">
                <value>false</value>
            </property>
            <property name="receiveTimeout">
                <value>20000</value>
            </property>
        </bean>

        <!-- <bean id="jmsContainer"
            class="org.springframework.jms.listener.DefaultMessageListenerContainer">
            <property name="connectionFactory">
                <ref bean="jmsQueueIdsConnectionFactory" />
            </property>
            <property name="destinationResolver">
                <ref bean="jmsDestinationResolver" />
            </property>
            <property name="destinationName" value="dummyQueue"/>
            <property name="concurrency" value="3-10" />
        </bean> -->

        <!-- WebSphere MQ Connection setup end -->
    </beans>

添加了下面的工作版本。如果通过注释在代码中设置,则 xml 中不需要 defaultDestinationName 。${company.project.MQ.module.Q}和其他值是从属性文件加载的,它也可以是硬编码的。

@Component 
public class SampleLstner{     
@JmsListener(concurrency = "1", destination = "${company.project.MQ.module.Q}", containerFactory = "jmsListenerContainerFactory")
           public void onMessage(Message msg) throws JMSException {}
 }

XML

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:cxf="http://cxf.apache.org/core"    
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:jaxws="http://cxf.apache.org/jaxws"    
xmlns:jms="http://www.springframework.org/schema/jms"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd  
    http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
    http://cxf.apache.org/jaxrs
    http://cxf.apache.org/schemas/jaxrs.xsd
    http://cxf.apache.org/jaxws
    http://cxf.apache.org/schemas/jaxws.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
    http://www.springframework.org/schema/jms
    http://www.springframework.org/schema/jms/spring-jms-4.1.xsd
    ">

<import resource="classpath*:com/company/svc/component.xml"/>

<mvc:annotation-driven enable-matrix-variables="true"/>
<context:component-scan base-package="com.company.test.main.module"></context:component-scan>

<!-- WebSphere MQ Connection setup start -->
<bean id="mqIdsConnectionFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory">
    <property name="hostName"><value>${company.project.MQ.HOST.NM}</value></property>
    <property name="port"><value>${company.project.MQ.PORT}</value></property>
    <property name="queueManager"><value>${company.project.MQ.QMNGR}</value></property>
    <property name="channel"><value>${company.project.MQ.CHANNEL}</value></property>
    <property name="CCSID"><value>819</value></property>
    <property name="transportType"><value>1</value></property>
</bean>
<bean id="jmsQueueIdsConnectionFactory"
    class="org.springframework.jms.connection.SingleConnectionFactory">
    <property name="targetConnectionFactory">
        <ref bean="mqIdsConnectionFactory" />
    </property>
</bean>
<bean id="jmsDestinationResolver"
    class="org.springframework.jms.support.destination.DynamicDestinationResolver">
</bean>
<bean id="jmsQueueIdsTemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory">
        <ref bean="jmsQueueIdsConnectionFactory" />
    </property>
    <property name="destinationResolver">
        <ref bean="jmsDestinationResolver" />
    </property> <!--    
    <property name="defaultDestinationName">
        <value>${company.project.MQ.module.Q}</value>
    </property>-->
    <property name="pubSubDomain">
        <value>false</value>
    </property>
    <property name="receiveTimeout">
        <value>20000</value>
    </property>
</bean>

<bean id="jmsListenerContainerFactory" class="org.springframework.jms.config.DefaultJmsListenerContainerFactory">
    <property name="connectionFactory">
        <ref bean="jmsQueueIdsConnectionFactory" />
    </property>
    <property name="destinationResolver">
        <ref bean="jmsDestinationResolver" />
    </property>
    <property name="concurrency" value="1" />
 </bean>
<!-- WebSphere MQ Connection setup end -->
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何让Spring JMS从注释@JmsListener中选择目标队列名称 的相关文章

随机推荐

  • 如何在 php 中添加形状文件 (.shp) 并在 php 文件中使用该形状文件数据?

    我必须在 php 中开发一个项目 并且必须包含形状文件 并且该形状文件需要转换为 kml 文件 我知道如何将形状文件转换为 kml 文件 但我不知道如何将形状文件导入 导入到 php 项目中 我还有包含更多信息的形状文件的支持文件 其中一些
  • 使用python访问google

    我怎样才能访问谷歌 我试过那个代码 urllib urlopen http www google com 但它显示消息prove you are human或者有些人的想法是这样的 有人说尝试用户代理 我不知道 您应该使用谷歌应用程序编程接
  • 在本地计算机上编译 Azure Functions(.csx 文件)

    我正在使用 AzureQueue 触发器模板 最好在本地计算机中编写函数 编译并执行它 然后部署 而不是在 azure 门户中编写它 有什么办法可以做到吗 Thanks Krishh 答案是肯定的 但目前体验并不好 随着我们增强服务 本地开
  • Alamofire HTTPS 10.3 中的更改

    我目前正在一个项目中使用 Alamofire 并且看到了有关具有不同功能的 10 3 beta 的问题 我有一个在 iOS 10 2 模拟器中运行良好的相同项目 我使用自签名证书向 HTTPS url 发出 get 请求 当我在安装了相同证
  • 如何打印 groupby 对象

    我想打印与 Pandas 分组的结果 我有一个数据框 import pandas as pd df pd DataFrame A one one two three three one B range 6 print df A B 0 on
  • CUDA 不支持边界检查

    我尝试使用 Numba 并访问 GPU 以加速代码 但出现以下错误 in jit raise NotImplementedError bounds checking is not supported for CUDA NotImplemen
  • 测试抛出 IntegrityError 的 SQLAlchemy 代码的正确方法是什么?

    我读过了this https stackoverflow com questions 129507 how do you test that a python function throws an exception问答 并且已经尝试捕获我
  • 在 tfs 中看不到上线选项

    我在离线模式下打开了一个解决方案 但现在我尝试上网并连接到 tfs 但我似乎看不到 文件 gt 源代码管理 下的 上网 按钮 我使用 团队 gt 连接到 Team Foundation Server 选项连接到 TFS 但在 文件 gt 源
  • 将字节数组转换为不使用画布的图像数据

    是否可以在不使用画布的情况下将字节数组转换为图像数据 我目前使用类似的东西 但是我认为可以在没有画布的情况下完成 还是我错了 var canvas document getElementsByTagName canvas 0 var ctx
  • jQuery/Javascript - 淡入 div onclick 淡出另一个不起作用

    我想在点击 div 时弹出一个菜单 我在这个 Fiddle 中一切正常 http jsfiddle net EhtrR 825 http jsfiddle net EhtrR 825 但我无法让它在我的代码上工作 HTML div clas
  • 如何创建一个可以点击其他应用程序的自动点击器应用程序?

    我见过很多提供自动点击功能的应用程序 但他们不提供一些特定的定制 所以我决定创建一个 我看过很多提供自动点击的教程 但它们应该在同一个应用程序中使用 但我想创建一个自动点击应用程序 可以单击其他应用程序的视图 我是一名中级java开发人员
  • Delphi 应用程序如何检测 Windows PC 的网络代理设置?

    我有一个 Delphi 应用程序 它使用以下命令与 Internet 上的 Web 服务器进行通信印地组件 http www indyproject org 该应用程序的大多数用户都具有直接的 Internet 连接 但有些用户位于本地网络
  • Lua 作为嵌入式语言的替代品?

    我正在开发一个在 DSP 上运行 Linux 的嵌入式系统 现在我们想让它的某些部分可以编写脚本 并且我们正在寻找一种很好的嵌入式脚本语言 这些脚本应该与我们现有的 C 代码库很好地集成 并且小而快 我知道 Lua 是解决此类问题的行业选择
  • 将 GCController 与 tvOS 模拟器结合使用

    我没有新的 Apple TV 但正在使用模拟器为其制作游戏原型 不幸的是 我似乎无法让 GCController 将 Siri 遥控器列为可用控制器 正如 tvOS 文档所示 我的控制器列表始终是 0 个元素长 即使我调用startWire
  • OS X 的 Boot2Docker 无法启动

    我是 docker 新手 我正在尝试在我的工作计算机上运行 boot2docker 我使用从办公室网络挂载主目录的用户帐户登录到运行 OS X 版本 10 10 1 Yosemite 的计算机 我安装了 Docker v1 4 1https
  • 禁用内联CSS样式[重复]

    这个问题在这里已经有答案了 当我使用 IE Developer 工具检查 html 时 我发现按钮有一种内联样式 我什么都不想要width此输入元素的属性 如何禁用或用空覆盖它width 如果您想覆盖内联样式 那么您需要在样式表中添加样式
  • Elasticsearch 的 406(不可接受)错误代码是什么意思?

    我正在尝试使用qwest http dreamysource io project qwest将一些数据发送到 Elasticsearch qwest post http elk example com 9200 incidents thi
  • 固定列标题宽度与正文列宽度不匹配

    标题与列宽不对齐 JsFiddle http jsfiddle net DyMSb 1 截屏 http s17 postimg org dybznay9b screen png 我在用着 ajax aspnetcdn com ajax jq
  • 以单下划线或双下划线开头的函数和变量

    我在各种编程语言 PHP 和 Python 中看到过以下划线开头的函数和变量 并且对其背后的含义感到困惑 假设 PHP 中使用正常约定 单下划线表示受保护的成员变量或方法 双下划线表示私有成员变量或方法 这源于当时 PHP 的 OOP 支持
  • 如何让Spring JMS从注释@JmsListener中选择目标队列名称

    任何帮助将不胜感激 我正在尝试使用 spring JMSListener 创建 MDB 的替代品 我希望将目的地名称作为注释传递 但我注意到org springframework jms listener DefaultMessageLis