WebSphere 自由 ActiveMQ

WebSphere Liberty ActiveMQ

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

在我的 Java EE 应用程序中,我想要一个消息驱动 Bean,如果队列中有消息,它就会被踢出。我尝试从 wasDev JMS Example like someone else did on this example "steal" 配置。但不幸的是配置不适合我。我研究了活动的 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>

最后一步我 "active" 我的豆子 server.xml

<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 方面。它没有达到。

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

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

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

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

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