Dario Lötscher
Dario Lötscher

Reputation: 99

WebSphere Liberty ActiveMQ

My goal is to consume Messages with the WebSphere Liberty Appserver (Full Java EE Standard) from an ActiveMQ. Unlucky I can't figure out how to configurate the WebSphere Liberty. The ActiveMQ Server im using is out of the box and I have added a Queue named myQueue.

In my Java EE application I want to have a Message Driven Beans which gets kicked if a message is in the queue. I tried to "steal" the configuration from the wasDev JMS Example like someone else did on this example. But unlucky the config is not working out for me. I studied the active mq resource adapter settings and tried the used them in my server.xml.

First of all I downloaded the Resource Adapter rar from ActiveMQ and included it into the server and the server.xml like this:

<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>

This should active the resource adapter and tell him where the server is located. Next I wrote my Message Driven Bean which only outputs the MessageID.

@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();
        }
    }
}

I want the onMessage to be called asoon a message is in the queue. Next I made an ejb-jar.xml entry:

<?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>

Last step i "active" the bean in my server.xml

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

In that's it - in my understanding things should be fine now. Here is the full server.xml containing other things I tried out too. If you have a solution please explane me what I did wrong.

    <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>

I'm using the WebSphere Liberty V8.5.5.8 and ActiveMQ 5.13.1

The Log File says:

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

My Python scripts can read and write to the target without problems. The ActiveMQ Log files doesn't say anything so I think the problem is not on the ActiveMQ side. It does not get reached.

Upvotes: 3

Views: 2667

Answers (1)

njr
njr

Reputation: 3484

A couple of updates are needed to your server configuration for this to work.

First, you need a jmsQueue element with an id that matches the destination specified in the activation config properties. For example,

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

Second, the jmsActivationSpec element needs a nested properties.activemq (even if you don't want to override any properties and want all the defaults) to identify that the jmsActivationSpec corresponds to your configured resourceAdapter with id activemq (versus any other resourceAdapter that could also be added to the configuration). For example,

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

Upvotes: 3

Related Questions