【问题标题】:JMSListener annotation is not working along with REST serviceJMSListener 注释不能与 REST 服务一起使用
【发布时间】:2020-10-03 13:59:43
【问题描述】:

我正在使用“Spring Boot - 2.1.5.RELEASE”和“Spring 框架 - 5.1.7.RELEASE”。 JMS 侦听器注释没有从 MQ 队列中挑选消息。我的 IntelliJ IDEA 中也没有错误日志。 关于我的项目 - 我正在公开一个 REST 服务,该服务从 MQ 发送和接收消息(使用 JMSTemplate 注释)。直到现在它还在工作。现在我必须添加另一个应该监听队列的类。因此添加了@JMSListener 注释,它不选择任何消息。任何见解都会非常有帮助。

pom 具有以下指定的依赖项。

<dependency>
    <groupId>com.ibm.mq</groupId>
    <artifactId>mq-jms-spring-boot-starter</artifactId>
    <version>2.0.0</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
    <groupId>com.ibm.mq</groupId>
    <artifactId>com.ibm.mq.allclient</artifactId>
    <version>9.1.4.0</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jms</artifactId>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.dataformat</groupId>
    <artifactId>jackson-dataformat-xml</artifactId>
</dependency>

该类具有以下指定方法。

import org.springframework.jms.annotation.JmsListener;
@Component
public class PickMyMessage {
    @JmsListener(destination = "IN",containerFactory = "myFactory")
    public void pullMyMessaage(String message){
        System.out.println("Message is pulled..");
    }
}

我的主应用程序有@EnableJMS 注释。在我的 application.yml 文件中,我提供了以下信息。

ibm:
  mq:
    channel: MY.APP.SVRCONN
    connName: 192.168.0.1(1415)
    password: Pswd
    queueManager: QM01
    user: appsrv

我的 Bean 类配置是

我的 JMS 连接工厂如下。

@Bean
    public JmsListenerContainerFactory<?> myFactory(ConnectionFactory connectionFactory,
                                                    DefaultJmsListenerContainerFactoryConfigurer configurer) {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        configurer.configure(factory, connectionFactory);
    }

不确定我在这里还缺少什么。任何见解都会非常有帮助。

如果我创建任何简单的演示项目,它会按预期工作,而不是我现有的项目。

【问题讨论】:

    标签: java spring-boot spring-jms


    【解决方案1】:

    PickMyMessage 类不是 Spring bean,这就是 Spring 忽略它的原因。将其声明为@Bean@Component

    可能还有其他问题。但这是第一个需要解决的问题。

    【讨论】:

    • 尝试像我的其他类一样添加 Component 或 Componentsscan。还是同样的问题。
    • 好的。现在展示如何将此侦听器连接到连接管理器。显示您的连接工厂 bean 的外观。
    • 更新了我的 bean 配置详细信息。我的课程中没有连接管理器。我相信它是默认的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-26
    • 2018-09-26
    • 2011-06-19
    • 2016-01-25
    相关资源
    最近更新 更多