【问题标题】:Message-driven Beans in Open Liberty 19.0.0.3 do not activate when accessing ActiveMQOpen Liberty 19.0.0.3 中的消息驱动 Bean 在访问 ActiveMQ 时未激活
【发布时间】:2019-09-04 17:44:16
【问题描述】:

我有一个通过资源适配器访问 Active MQ 5.15.18 的 OpenLiberty 应用程序服务器,但我无法正确配置激活规范,因此当有新消息进入时会激活 MDB。

应用程序能够将消息放入输出队列,但是,当新消息到达输入队列时,MDB 不会被激活。相同的代码适用于通过嵌入式本地提供程序在本地创建的队列(WLP 作为 JMS 服务器,不涉及 ActiveMQ)。

我已经尝试了几个代码 sn-ps cherry 选择了堆栈溢出,我的问题看起来很像 WebSphere Liberty ActiveMQ 但相同的配方对我不起作用。

这是我的 MDB 代码:

@MessageDriven(name = "MyMDB",
        activationConfig = {  
           @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),  
           @ActivationConfigProperty(propertyName="destination", propertyValue="APP1_QIN"),  
           @ActivationConfigProperty(propertyName="acknowledgeMode", propertyValue="Auto-acknowledge")  
        })
public class MyMDB implements MessageListener {

    @PostConstruct
    public void postConstruct() {
        System.out.println("Init MDB");
    }

    @Override
    public void onMessage(Message message) {
        System.out.println("Message received in MDB: " + message);
    }

    @Resource
    MessageDrivenContext ejbcontext;
    @SuppressWarnings("unused")
    private void setMessageDrivenContext(EJBContext ejbcontext) {
    }

}

在我的 server.xml 下:

<server description="defaultServer">
    <featureManager>
        <feature>webProfile-7.0</feature>
        <feature>localConnector-1.0</feature>
        <feature>wasJmsClient-2.0</feature>
        <feature>jca-1.7</feature>
    </featureManager>

    ...

    <resourceAdapter id="ActiveMQResourceAdapter" location="/path/to/libs/activemq-rar-5.15.8.rar">
        <properties.ActiveMQResourceAdapter ServerUrl="tcp://localhost:61616" />
    </resourceAdapter>

    <jmsQueueConnectionFactory connectionManagerRef="QueueConnMgr" jndiName="jms/QCF">  
        <properties.ActiveMQResourceAdapter />      
    </jmsQueueConnectionFactory>    

    <jmsQueue id="APP1_QIN" jndiName="jms/APP1_QIN">
        <properties.ActiveMQResourceAdapter PhysicalName="APP1_QIN" />
    </jmsQueue>

    <jmsQueue id="APP1_QOUT" jndiName="jms/APP1_QOUT">
        <properties.ActiveMQResourceAdapter PhysicalName="APP1_QOUT" />
    </jmsQueue>

     <jmsActivationSpec id="MyMDB">     
        <properties.ActiveMQResourceAdapter/> <!--  destination="APP1_QIN"   -->
    </jmsActivationSpec>

    <connectionManager id="QueueConnMgr" maxPoolSize="5"/>
</server>

我希望 MDB 在收到消息后立即正确激活,但事实并非如此。此外,查看 ActiveMQ 控制台,该队列上的消费者似乎为零。

有什么想法吗?

【问题讨论】:

  • MyMDB 有 2 个 @MessageDriven 注释实例。这是故意的吗?
  • 根据 EJB 规范,destinationType 激活配置属性应该是 javax.jms.Topicjavax.jms.Queue。因此,我认为org.apache.activemq.command.ActiveMQQueue 不会被认为是有效的。
  • 感谢@JustinBertram 这实际上是之前测试的剩余代码。我已经修改了上面的代码。我实际上正在尝试使用一种表示法和 javax.jms.Queue 作为目标类型,结果相同。
  • 如果它与本地 ActiveMQ 队列一起工作,那么它可能与网络相关。检查您是否在 Liberty 和 AMQ 之间设置了任何防火墙。此外,您显示的配置具有 localhost(但它可能来自您的旧测试) - ServerUrl="tcp://localhost:61616"
  • 它适用于本地托管在 WLP 内的 JMS 队列(作为 WLP 队列提供者)。它不适用于方程式中的 Active MQ。它在本地主机上运行,​​因此不涉及防火墙。我也可以(明确地)在队列中放置和获取消息,唯一的问题是 MDB 没有激活。

标签: java jakarta-ee activemq websphere-liberty message-driven-bean


【解决方案1】:

看起来您的 AS id 可能不正确,它应该采用以下形式:&lt;activationSpec id="app1/module1/MyMessageDrivenBean"&gt; 以及应用程序、模块和消息驱动 bean 的正确名称。

在此处查看更多关于配置 AS 的详细信息Configuring JCA activation specifications

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-05
    • 2016-10-23
    • 2012-11-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-22
    • 2012-05-11
    • 1970-01-01
    相关资源
    最近更新 更多