6 Replies Latest reply: Apr 28, 2010 12:57 PM by Jean-Claude Rouvinez RSS

Accessing HornetQ remotely from JBoss AS

Jean-Claude Rouvinez Newbie

I want to test (proof of concept) the following configuration:


- HornetQ 2.0.0.GA, running in the stand-alone, non clustered mode
   It contains 2 queues:
    - a request queue
    - a reply queue


- A JBoss server (jboss-5.1.0.GA) accessing remotely both queues on
   HornetQ:
   - it writes messages in the request queue
   - it reads (MDB implements MessageListener) messages from the reply queue


- A JBoss server (jboss-5.0.0.GA) accessing remotely both queues on
   HornetQ:
   - it reads (MDB implements MessageListener) messages from the request queue
   - it writes messages in the reply queue

 

How do I have to configure the JBoss servers to access the queues on HornetQ using JNDI?
How do I have to specify the configuration of the MDB (@MessageDriven(activationConfig)) to access the queues on HornetQ?

 

I want to use JNDI and not the core libraries of HornetQ.
Which HornetQ libraries should I copy to the JBoss servers (copying the libraries according to "HornetQ 2.0 User Manual", ch. 10.2 didn't help)?

 

Thank you in advance.

  • 1. Re: Accessing HornetQ remotely from JBoss AS
    Andy Taylor Master

    The JCA example in the distribution covers exactly this

  • 2. Re: Accessing HornetQ remotely from JBoss AS
    Jean-Claude Rouvinez Newbie

    Do you mean this?

     

    HornetQ 2.0 User Manual

    • 5.3. HornetQ integrated with a JEE application server
    • 32. Application Server Integration and Java EE
    • Example 11.3.3. Resource Adapter Configuration

     

    Example in the distribution

    • examples/javaee/jca-config
  • 3. Re: Accessing HornetQ remotely from JBoss AS
    Alexander Sanchez Newbie

    Hello, my scenary is this:

     

    esquemaQueue.png

     

    I followed:

     

    • 5.3. HornetQ integrated with a JEE application server
    • 32.  Application Server Integration and Java EE
    • Example 11.3.3.  Resource Adapter Configuration

     

    In the jboss aplication server, I did this:

     

          1) I copied the hornetq-ra.rar adapter file  in directory jboss-4.2.3.GA\server\default\deploy\jms\

          2) I opened the hornetq-ra.rar file and I edited the ra.xml file that found under directory hornetq-ra.rar\META-INF

     

    ra.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <connector xmlns="http://java.sun.com/xml/ns/j2ee"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee  http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd"  version="1.5">
       <description>HornetQ 2.0 Resource Adapter</description>
       <display-name>HornetQ 2.0 Resource Adapter</display-name>
       <vendor-name>Red Hat Middleware LLC</vendor-name>
       <eis-type>JMS 1.1 Server</eis-type>
       <resourceadapter-version>1.0</resourceadapter-version>
       <license>
          <description>
              Copyright 2009 Red Hat, Inc. Red Hat licenses this file to you under the Apache License, version  2.0 (the "License"); you may not use this  file except in compliance with the License.  You may obtain a copy of the License at    http://www.apache.org/licenses/LICENSE-2.0
     Unless required by applicable law or agreed to in writing, software  distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or  implied.  See the License for the specific language governing
     permissions and limitations under the License.  
          </description>
          <license-required>true</license-required>
       </license>
    
       <resourceadapter>
          <resourceadapter-class>org.hornetq.ra.HornetQResourceAdapter</resourceadapter-class>
          <config-property>
             <description>The transport type</description>
             <config-property-name>ConnectorClassName</config-property-name>
             <config-property-type>java.lang.String</config-property-type>
             <config-property-value>org.jboss.messaging.integration.transports.netty.NettyConnectorFactory</config-property-value>
          </config-property>
          <config-property>
             <description>The transport configuration. These values must be in the form of key=val;key=val;</description>
             <config-property-name>ConnectionParameters</config-property-name>
             <config-property-type>java.lang.String</config-property-type>
             <config-property-value>hornetq.remoting.netty.host=192.168.1.144;hornetq.remoting.netty.port=5445</config-property-value>
          </config-property>
          <config-property>
            <description>Use XA?</description>
            <config-property-name>UseXA</config-property-name>
            <config-property-type>java.lang.Boolean</config-property-type>
            <config-property-value>true</config-property-value>
          </config-property>
       
          <outbound-resourceadapter>
             <connection-definition>
                <managedconnectionfactory-class>org.hornetq.ra.HornetQRAManagedConnectionFactory</managedconnectionfactory-class>
                <config-property>
                   <description>The default session type</description>
                   <config-property-name>SessionDefaultType</config-property-name>
                   <config-property-type>java.lang.String</config-property-type>
                   <config-property-value>javax.jms.Queue</config-property-value>
                </config-property>
                <config-property>
                   <description>Try to obtain a lock within specified number of seconds; less than or equal to 0 disable this functionality</description>
                   <config-property-name>UseTryLock</config-property-name>
                   <config-property-type>java.lang.Integer</config-property-type>
                   <config-property-value>0</config-property-value>
                </config-property>
    
                <connectionfactory-interface>org.hornetq.ra.HornetQRAConnectionFactory</connectionfactory-interface>
                <connectionfactory-impl-class>org.hornetq.ra.HornetQRAConnectionFactoryImpl</connectionfactory-impl-class>
                <connection-interface>javax.jms.Session</connection-interface>
                <connection-impl-class>org.hornetq.ra.HornetQRASession</connection-impl-class>
             </connection-definition>
    
             <transaction-support>XATransaction</transaction-support>
             <authentication-mechanism>
                <authentication-mechanism-type>BasicPassword</authentication-mechanism-type>
                <credential-interface>javax.resource.spi.security.PasswordCredential</credential-interface>
             </authentication-mechanism>
    
             <reauthentication-support>false</reauthentication-support>
          </outbound-resourceadapter>
    
          <inbound-resourceadapter>
             <messageadapter>
                <messagelistener>
                   <messagelistener-type>javax.jms.MessageListener</messagelistener-type>
                   <activationspec>
                      <activationspec-class>org.hornetq.ra.inflow.HornetQActivationSpec</activationspec-class>
                      <required-config-property>
                          <config-property-name>destination</config-property-name>
                      </required-config-property>
                   </activationspec>
                </messagelistener>
             </messageadapter>
          </inbound-resourceadapter>
       </resourceadapter>
    </connector>
    

     

    The line

     

    <config-property-value>hornetq.remoting.netty.host=192.168.1.144;hornetq.remoting.netty.port=5445</config-property-value>

     

    was edited so I could establish a connetion to the hornetq server that is running on other server (ip: 192.168.1.144).

     

    3) In the MDB :

     

    package HornetQ;
    import javax.ejb.MessageDriven;
    import javax.ejb.ActivationConfigProperty;
    import javax.jms.JMSException;
    import javax.jms.Message;
    import javax.jms.MessageListener;
    import javax.jms.ObjectMessage;
    import javax.jms.TextMessage;
    
    
    import org.jboss.ejb3.annotation.ResourceAdapter;
    
    
    @MessageDriven(name = "MDBExample",
            activationConfig =
            {
            @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
            @ActivationConfigProperty(propertyName="destination", propertyValue="queues/OrderQueue")
            })
    @ResourceAdapter("hornetq-ra.rar")        
    public class MDBExample  implements MessageListener
    {
    
    
        @Override
        public void onMessage(Message recvMsg) {
            .......
        }
    }

     

    4) In jboss.xml

     

    <?xml version="1.0" encoding="UTF-8"?>
    <jboss>
        <enterprise-beans>
            <message-driven>
                   <ejb-name>ExampleMDB</ejb-name>
                   <resource-adapter-name>hornetq-ra.rar</resource-adapter-name>
            </message-driven>        
        </enterprise-beans>
    </jboss>
    

     

     

    When I publish the project this error appears:

     

    17:01:31,923 WARN  [JmsActivation] Failure in jms activation org.jboss.resource.adapter.jms.inflow.JmsActivationSpec@18efc0c(ra=org.jboss.resource.adapter.jms.JmsResourceAdapter@c07f58 destination=queues/OrderQueue isTopic=false tx=true durable=false reconnect=10 provider=java:/DefaultJMSProvider user=null maxMessages=1 minSession=1 maxSession=15 keepAlive=60000 useDLQ=true DLQHandler=org.jboss.resource.adapter.jms.inflow.dlq.GenericDLQHandler DLQJndiName=queue/DLQ DLQUser=null DLQMaxResent=5)
    javax.naming.NameNotFoundException: queues not bound
        at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
        at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
        at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
        at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
        at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:667)
        at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
        at javax.naming.InitialContext.lookup(Unknown Source)
        at org.jboss.util.naming.Util.lookup(Util.java:215)
        at org.jboss.resource.adapter.jms.inflow.JmsActivation.setupDestination(JmsActivation.java:409)
        at org.jboss.resource.adapter.jms.inflow.JmsActivation.setup(JmsActivation.java:316)
        at org.jboss.resource.adapter.jms.inflow.JmsActivation$SetupActivation.run(JmsActivation.java:635)
        at org.jboss.resource.work.WorkWrapper.execute(WorkWrapper.java:204)
        at org.jboss.util.threadpool.BasicTaskWrapper.run(BasicTaskWrapper.java:275)
        at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:756)
        at java.lang.Thread.run(Unknown Source)
    

     

    The Jboss server is using the jms-ra adapter (org.jboss.resource.adapter.jms.JmsResourceAdapter) to connect with destination "queues/OrderQueue" instead of using the hornetq-ra adapter (org.hornetq.ra.HornetQResourceAdapter) that is on the remote hornetq server.

     

    Please help me to find the error.

  • 4. Re: Accessing HornetQ remotely from JBoss AS
    Jean-Claude Rouvinez Newbie

    I tested it with the example located under

    $HORNETQ_HOME/examples/javaee/jca-config

     

    I started HornetQ instand-alone, non clustered mode
    on the host myHost.myDomain.ch

     

    I started the application in a JBoss Application Server
    installed on another host

     

    I have noticed that in ra.xml
    the following informations are different than yours (see below):
    1. <config-property-value>org.hornetq.integration.transports.netty.Netty...
    2. I defined 2 config-property for the port and the host

    {code:xml}

    <resourceadapter>
          <resourceadapter-class>org.hornetq.ra.HornetQResourceAdapter</resourceadapter-class>
          <config-property>
             <description>The transport type</description>
             <config-property-name>ConnectorClassName</config-property-name>
             <config-property-type>java.lang.String</config-property-type>
             <config-property-value>org.hornetq.integration.transports.netty.NettyConnectorFactory</config-property-value>
          </config-property>
          <config-property>
             <description>The transport configuration. These values must be in the form of key=val;key=val;</description>
             <config-property-name>ConnectionParameters</config-property-name>
             <config-property-type>java.lang.String</config-property-type>
             <config-property-value>port=5445</config-property-value>
          </config-property>
          <config-property>
             <description>The transport configuration. These values must be in the form of key=val;key=val;</description>
             <config-property-name>ConnectionParameters</config-property-name>
             <config-property-type>java.lang.String</config-property-type>
             <config-property-value>host=myHost.myDomain.ch</config-property-value>
          </config-property>

    {code}

     

    But it doesn't work: I see this line in the log file on the JBoss Application Server:

    {code}

    2010-04-27 18:05:35,750 DEBUG [UID=] [ch.ipi.hornetq.example.jcaconfig.server.StatelessSender] ENTRY sendHello(Hello there MDB!)
    and then my application stops, waiting for ?

    {code}

     

    Could you please try to change the file ra.xml as I mentionned above? Maybe it helps.

  • 5. Re: Accessing HornetQ remotely from JBoss AS
    Andy Taylor Master

    I am guessing that the host cant be reached using that URl but because reconnectAttempts=-1 (infinite) it is just sitting there trying to connect. check your network settings and if u set reconnectAttempts to 0 or 1 you should see it fail

  • 6. Re: Accessing HornetQ remotely from JBoss AS
    Jean-Claude Rouvinez Newbie

    We did it successfully as follows:

     

    - On the Host where HornetQ resides:
       - Configure HornetQ according to the "HornetQ 2.0 User Manual"
         Chapter 16
       - Start HornetQ in a stand-alone, non clustered mode

     

    - On the host where JBoss resides:
       - Run the example "examples/javaee/jca-config"
         to obtain the configuration.
         "jca-config-example-profile2" and "jca-config-example-profile"
         are created.
       - Copy "jca-config-example-profile2/deploy/hornetq-ra.rar"
         to the JBoss deploy directory
       - Copy "jca-config-example-profile2/deploy/hornetq.sar/jms-remote-ds.xml"
         to the JBoss deploy directory
       - Change the configuration of "jms-remote-ds.xml" and
         "hornetq-ra.rar/META-INF/ra.xml in the JBoss deploy directory
         (see below)
       - Start JBoss
       - Deploy the part of "examples/javaee/jca-config" you want to
         test to JBoss deploy directory
       - Start JBoss

     

    - "jms-remote-ds.xml"
      Set the right host and port in this line:
       <tx-connection-factory>
        ...
        <config-property-value>host=myhost.mydomain.ch;port=5445</config-property-value>
        ...

     

    - "ra.xml"
      Set the right host and port in this line:
       <resourceadapter>
       ...
        <config-property>
        ...
         <config-property-name>ConnectionParameters</config-property-name>
         <config-property-type>java.lang.String</config-property-type>
         <config-property-value>host=myhost.mydomain.ch;port=5445</config-property-value>

     

      Warning: The syntax is:
        host= ... ; port=...

     


    I hope this helps.