【问题标题】:WebSphere Liberty ActiveMQWebSphere Liberty ActiveMQ
【发布时间】:2016-05-30 14:24:48
【问题描述】:

我的目标是使用来自 ActiveMQ 的 WebSphere Liberty Appserver(完整 Java EE 标准)使用消息。不幸的是,我不知道如何配置 WebSphere Liberty。我使用的 ActiveMQ 服务器是开箱即用的,我添加了一个名为 myQueue 的队列。

在我的 Java EE 应用程序中,我希望有一个消息驱动 Bean,如果消息在队列中,它就会被踢出。我试图从wasDev JMS Example 中“窃取”配置,就像其他人在example 上所做的那样。但不幸的是,配置不适合我。我研究了活动的 mq 资源适配器设置并尝试在我的 server.xml 中使用它们。

首先我从 ActiveMQ 下载了资源适配器 rar 并将其包含在服务器和 server.xml 中,如下所示:

<resourceAdapter id="activemq"  location="/opt/ibm/wlp/usr/servers/defaultServer/resources/activemq-rar-5.13.1.rar">
    <properties.activemq ServerUrl="tcp://192.168.200.6:61616" />
</resourceAdapter>

这应该激活资源适配器并告诉他服务器的位置。接下来我编写了只输出 MessageID 的 Message Driven Bean。

@MessageDriven(name = "PythonDaemonMessageEJB")

public class PythonDaemonMessageBean implements MessageListener {
    public PythonDaemonMessageBean() {
    }

    @Override
    public void onMessage(Message var1) {
        try {
            System.out.println(var1.getJMSMessageID());
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }
}

我希望在队列中有消息时立即调用 onMessage。接下来我做了一个 ejb-jar.xml 条目:

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
      http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"
     version="3.1">
    <enterprise-beans>
    <session>
        <ejb-name>TestEJB</ejb-name>
        <ejb-class>ch.TestBean</ejb-class>
        <session-type>Stateless</session-type>
        <transaction-type>Container</transaction-type>
    </session>
    <message-driven>
        <ejb-name>PythonDaemonMessageEJB</ejb-name>
        <ejb-class>ch.PythonDaemonMessageBean</ejb-class>
        <messaging-type>javax.jms.MessageListener</messaging-type>
        <transaction-type>Container</transaction-type>
        <message-destination-type>javax.jms.Queue</message-destination-type>
        <activation-config>
            <activation-config-property>
                <activation-config-property-name>destination</activation-config-property-name>
                <activation-config-property-value>myQueue</activation-config-property-value>
            </activation-config-property>
            <activation-config-property>
                <activation-config-property-name>destinationType</activation-config-property-name>
                <activation-config-property-value>javax.jms.Queue</activation-config-property-value>
            </activation-config-property>
        </activation-config>
    </message-driven>
</enterprise-beans>

最后一步我“激活”了我 server.xml 中的 bean

<jmsActivationSpec id="cert-manager-ear/cert-manager-ejb/PythonDaemonMessageEJB" />

就是这样 - 在我的理解中,现在应该没问题了。这是完整的 server.xml,其中包含我也尝试过的其他内容。如果您有解决方案,请解释我做错了什么。

    <server description="new server">

    <!-- Enable features -->
    <featureManager>
        <feature>javaee-7.0</feature>
    <feature>localConnector-1.0</feature>
    </featureManager>

    <httpEndpoint id="defaultHttpEndpoint"
                  httpPort="9080"
                  httpsPort="9443" />

    <!-- Automatically expand WAR files and EAR files -->
    <applicationManager autoExpand="true"/>

    <resourceAdapter id="activemq"  location="/opt/ibm/wlp/usr/servers/defaultServer/resources/activemq-rar-5.13.1.rar">
        <properties.activemq ServerUrl="tcp://192.168.200.6:61616" />
    </resourceAdapter>

    <jmsActivationSpec id="cert-manager-ear/cert-manager-ejb/PythonDaemonMessageEJB" />
    #       <properties.activemq />  #destinationRef="jndi/MDBQ" destinationType="javax.jms.Queue" />
    #   </jmsActivationSpec>

    #   <jmsQueueConnectionFactory jndiName="jndi_JMS_BASE_QCF">
    #       <properties.activemq />
    #   </jmsQueueConnectionFactory>

    #   <jmsQueue> jndiName="jndi_INPUT_Q">
    #       <properties.activemq PhysicalName="QUEUE1" />
    #   </jmsQueue>

    #   <jmsQueue id="jndi/MDBREPLYQ" jndiName="jndi/MDBREPLYQ">
    #       <properties.activemq PhysicalName="MDBREPLYQ" />
    #   </jmsQueue>

    #   <jmsQueue id="jndi/MDBQ" jndiName="jndi/MDBQ">
    #       <properties.activemq PhysicalName="myQueue" />
    #   </jmsQueue>
    </server>

我正在使用 WebSphere Liberty V8.5.5.8 和 ActiveMQ 5.13.1

日志文件说:

The message endpoint for the message driven bean PythonDaemonMessageEJB can not be activated because the target myQueue is not available. 

我的 Python 脚本可以毫无问题地读取和写入目标。 ActiveMQ 日志文件什么也没说,所以我认为问题不在 ActiveMQ 方面。达不到。

【问题讨论】:

  • '#' 字符实际上是否在您的 server.xml 中?要在 xml 中发表评论,您必须使用 &lt;!-- comment --&gt;

标签: java jakarta-ee activemq websphere-liberty


【解决方案1】:

需要对您的服务器配置进行一些更新才能使其正常工作。

首先,您需要一个 id 与激活配置属性中指定的目标匹配的 jmsQueue 元素。例如,

   <jmsQueue id="myQueue" jndiName="jndi/MDBQ">
       <properties.activemq PhysicalName="myQueue" />
   </jmsQueue>

其次,jmsActivationSpec 元素需要一个嵌套的 properties.activemq(即使您不想覆盖任何属性并想要所有默认值)来识别 jmsActivationSpec 对应于您配置的具有 id activemq 的 resourceAdapter(相对于任何其他 resourceAdapter也可以添加到配置中)。例如,

<jmsActivationSpec id="cert-manager-ear/cert-manager-ejb/PythonDaemonMessageEJB" />
   <properties.activemq />
</jmsActivationSpec>

【讨论】:

  • @DarioLötscher 如果这回答了您的问题,您应该单击答案左侧的复选标记以接受它。这将提高回答者的声誉,并提高您的接受率,从而使人们将来更有可能回答您的问题。
  • 谁能链接ActiveMQ资源适配器的XML规范文档?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-13
  • 2013-02-03
  • 2021-09-13
  • 1970-01-01
相关资源
最近更新 更多