13 Replies Latest reply: May 25, 2012 5:27 PM by Luiz Carlos Silva RSS

JMS Remote Connection

Luiz Carlos Silva Newbie

Hi friends, I have problem

I have one application that use JBoss 7 and some process utility JMS,'s, but there is Server Messagem external that where I need connect it. I used the example  (https://community.jboss.org/message/737801#737801) but not work.

anyone ever needed to do something like that?


 


  • 1. Re: JMS Remote Connection
    Justin Bertram Master

    What exactly are you trying to do?  Are you trying to connect an application in one instance of JBoss AS7 to a JMS destination hosted by a different instance of JBoss AS7?  If so, are you using MDBs?

     

    What behavior do you expect, and what behavior do you actually observe?

     

    What version of JBoss AS7 are you using?

  • 2. Re: JMS Remote Connection
    Luiz Carlos Silva Newbie

    Yes I have one instance of JBoss As 7 to a JMS destination hosted remote and I using MDB's.

    The verion is jboss-as-7.1.1.Final

  • 3. Re: JMS Remote Connection
    Justin Bertram Master

    What behavior do you expect, and what behavior do you actually observe?

  • 4. Re: JMS Remote Connection
    Luiz Carlos Silva Newbie

    No, I wish I could create objects to a queue outside and use my listeners.

  • 5. Re: JMS Remote Connection
    Luiz Carlos Silva Newbie

    Apparently I could but if the external server restart, the following error occurs

     

    Caused by: java.lang.IllegalStateException: Cannot create session factory, server locator is closed (maybe it has been garbage collected)

  • 6. Re: JMS Remote Connection
    Justin Bertram Master

    Can you paste the full stack-trace for this exception as well as the code which throws it?

  • 7. Re: JMS Remote Connection
    Luiz Carlos Silva Newbie

    standalone.xml

    Remembering that the remote server is still in a local instance HornetQ, but will be done through a remote machine.

     

     

      <subsystem xmlns="urn:jboss:domain:messaging:1.1">

                <hornetq-server>

                    <persistence-enabled>true</persistence-enabled>

                    <journal-file-size>102400</journal-file-size>

                    <journal-min-files>2</journal-min-files>

     

     

                    <connectors>

                        <connector name="remote-jms">

                            <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>

                            <param key="host" value="localhost"/>

                            <param key="port" value="5445"/>

                        </connector>

                    </connectors>

     

     

                    <security-settings>

                        <security-setting match="#">

                            <permission type="send" roles="guest"/>

                            <permission type="consume" roles="guest"/>

                            <permission type="createNonDurableQueue" roles="guest"/>

                            <permission type="deleteNonDurableQueue" roles="guest"/>

                        </security-setting>

                    </security-settings>

     

     

                    <address-settings>

                        <address-setting match="#">

                            <dead-letter-address>jms.queue.DLQ</dead-letter-address>

                            <expiry-address>jms.queue.ExpiryQueue</expiry-address>

                            <redelivery-delay>0</redelivery-delay>

                            <max-size-bytes>10485760</max-size-bytes>

                            <address-full-policy>BLOCK</address-full-policy>

                            <message-counter-history-day-limit>10</message-counter-history-day-limit>

                        </address-setting>

                    </address-settings>

     

     

                    <jms-connection-factories>

                        <connection-factory name="RemoteConnectionFactory">

                            <connectors>

                                <connector-ref connector-name="remote-jms"/>

                            </connectors>

                            <entries>

                                <entry name="java:/RemoteConnectionFactory"/>

                                <entry name="java:jboss/exported/jms/RemoteConnectionFactory"/>

                            </entries>

                        </connection-factory>

                        <pooled-connection-factory name="hornetq-ra">

                            <transaction mode="xa"/>

                            <connectors>

                                <connector-ref connector-name="remote-jms"/>

                            </connectors>

                            <entries>

                                <entry name="java:/JmsXA"/>

                            </entries>

                        </pooled-connection-factory>

                    </jms-connection-factories>

     

     

                    <jms-destinations>

                        <jms-topic name="ServerNotificationTopic">

                            <entry name="topic/ServerNotification"/>

                            <entry name="java:jboss/exported/jms/topic/ServerNotification"/>

                        </jms-topic>

                    </jms-destinations>

                </hornetq-server>

            </subsystem>

     

     

    hornetq-jms.xml

     

       <topic name="ServerNotificationTopic"> 

                        <entry name="topic/ServerNotification"/>  

            <entry name="java:jboss/exported/jms/topic/ServerNotification"/>

       </topic>

     

    Listener

     

     

    @MessageDriven(name = "MyMdbHandlerName", activationConfig = {

                        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),

                        @ActivationConfigProperty(propertyName = "destination", propertyValue = "jboss/exported/jms/topic/ServerNotification"),

                        // @ActivationConfigProperty(propertyName = "messageSelector",

                        // propertyValue = "MySelector='MyHandlerValue'"),

                        @ActivationConfigProperty(propertyName = "user", propertyValue = "guest"),

                        @ActivationConfigProperty(propertyName = "password", propertyValue = "guest"),

                        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })

    public class ProdutoJMSSample implements MessageListener {

     

     

              @EJB

              private FactoryDAO factoryDAO;

     

     

              @Override

              public void onMessage(Message msg) {

     

     

                        if (msg instanceof ObjectMessage) {

                                  ObjectMessage objMsg = (ObjectMessage) msg;

                                  try {

                                            Produto produto = (Produto) objMsg.getObject();

                                            try {

                                                      ((ProdutoDAO) factoryDAO.getBaseDaoImp(ProdutoDAO.class))

                                                                          .salvar(produto);

                                            } catch (Exception e) {

                                                      // TODO Auto-generated catch block

                                                      e.printStackTrace();

                                            }

                                  } catch (JMSException e) {

                                            // TODO Auto-generated catch block

                                            e.printStackTrace();

                                  }

     

     

                        }

     

     

              }

     

     

    }

     

     

    Productor Message

     

    package dev.com.shopping.product.jms;

     

     

    import javax.annotation.PostConstruct;

    import javax.annotation.PreDestroy;

    import javax.annotation.Resource;

    import javax.ejb.LocalBean;

    import javax.ejb.Stateless;

    import javax.jms.Connection;

    import javax.jms.ConnectionFactory;

    import javax.jms.Destination;

    import javax.jms.JMSException;

    import javax.jms.MessageProducer;

    import javax.jms.ObjectMessage;

    import javax.jms.Session;

     

     

    import dev.com.shopping.product.entity.Produto;

     

     

    /**

    * Session Bean implementation class ProdutorDeMensagem

    */

    @Stateless

    @LocalBean

    public class ProdutorDeMensagem {

     

     

              @Resource(mappedName = "java:/RemoteConnectionFactory")

              private ConnectionFactory connectionFactory;

     

     

     

     

              private Connection connection;

              private Session session;

              javax.jms.Topic topic;

     

     

              @PostConstruct

              public void init() {

                        try {

                                  connection = connectionFactory.createConnection();

                                  session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

                                   topic = session.createTopic("ServerNotificationTopic");

                        } catch (JMSException e) {

                                  e.printStackTrace();

                                  throw new RuntimeException(e);

                        }

              }

     

     

              @PreDestroy

              public void destroy() {

                        if (connection != null) {

                                  try {

                                            connection.close();

                                  } catch (JMSException e) {

                                            e.printStackTrace();

                                  }

                        }

              }

     

     

              public void enviarMensagem(Produto produto) {

                        ObjectMessage message;

     

                        try {

     

                                  javax.jms.MessageProducer producer = session.createProducer(topic);

                                  message = session.createObjectMessage(produto);

                                  producer.send(message);

     

     

                        } catch (JMSException e) {

                                  e.printStackTrace();

                        }

              }

     

     

     

    }

  • 8. Re: JMS Remote Connection
    Justin Bertram Master

    I still don't see your stack-trace and you still have not told me what behavior you expect vs. what you're actually observing.

     

    Based on your latest comment I have a few more questions:

     

    1. I don't see any acceptors in your standalone.xml.  Is that intentional?
    2. Where exactly is <connector name="remote-jms"> supposed to connect?  What is listening on localhost:5445?
    3. Why is <connection-factory name="RemoteConnectionFactory"> referencing <connector-ref connector-name="remote-jms"/>?
    4. What role does hornetq-jms.xml play?  JBoss AS7 doesn't use this file.
    5. Is dev.com.shopping.product.entity.Produto.ProdutorDeMensagem supposed to be sending messages to a remote server?
    6. Is the MDB supposed to be consuming messages from a remote server?
  • 9. Re: JMS Remote Connection
    Luiz Carlos Silva Newbie

    Sorry fogout stack-trace

     

    16:34:09,901 WARN  [com.arjuna.ats.jta] (Periodic Recovery) ARJUNA016027: Local XARecoveryModule.xaRecovery got XA exception XAException.XAER_RMERR: javax.transaction.xa.XAException: Error trying to connect to any providers for xa recovery

              at org.hornetq.jms.server.recovery.HornetQXAResourceWrapper.getDelegate(HornetQXAResourceWrapper.java:275) [hornetq-jms-2.2.13.Final.jar:]

              at org.hornetq.jms.server.recovery.HornetQXAResourceWrapper.recover(HornetQXAResourceWrapper.java:77) [hornetq-jms-2.2.13.Final.jar:]

              at com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule.xaRecovery(XARecoveryModule.java:503) [jbossjts-4.16.2.Final.jar:]

              at com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule.resourceInitiatedRecoveryForRecoveryHelpers(XARecoveryModule.java:471) [jbossjts-4.16.2.Final.jar:]

              at com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule.bottomUpRecovery(XARecoveryModule.java:385) [jbossjts-4.16.2.Final.jar:]

              at com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule.periodicWorkSecondPass(XARecoveryModule.java:166) [jbossjts-4.16.2.Final.jar:]

              at com.arjuna.ats.internal.arjuna.recovery.PeriodicRecovery.doWorkInternal(PeriodicRecovery.java:789) [jbossjts-4.16.2.Final.jar:]

              at com.arjuna.ats.internal.arjuna.recovery.PeriodicRecovery.run(PeriodicRecovery.java:371) [jbossjts-4.16.2.Final.jar:]

    Caused by: java.lang.IllegalStateException: Cannot create session factory, server locator is closed (maybe it has been garbage collected)

              at org.hornetq.core.client.impl.ServerLocatorImpl.assertOpen(ServerLocatorImpl.java:1823) [hornetq-core-2.2.13.Final.jar:]

              at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:699) [hornetq-core-2.2.13.Final.jar:]

              at org.hornetq.jms.server.recovery.HornetQXAResourceWrapper.connect(HornetQXAResourceWrapper.java:321) [hornetq-jms-2.2.13.Final.jar:]

              at org.hornetq.jms.server.recovery.HornetQXAResourceWrapper.getDelegate(HornetQXAResourceWrapper.java:251) [hornetq-jms-2.2.13.Final.jar:]

              ... 7 more

     

     

     

    I don't see any acceptors in your standalone.xml.  Is that intentional?

         I retired because my connection is remote,

     

              <acceptors>

                     <netty-acceptor name="netty" socket-binding="messaging"/>

                      <netty-acceptor name="netty-throughput" socket-binding="messaging-throughput">

                            <param key="batch-delay" value="50"/>

                            <param key="direct-deliver" value="false"/>

                      </netty-acceptor>

                     <in-vm-acceptor name="in-vm" server-id="0"/>

               </acceptors>

     

    I   changed for

     

    <connectors>

                        <connector name="remote-jms">

                            <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>

                            <param key="host" value="localhost"/>

                            <param key="port" value="5445"/>

                        </connector>

                    </connectors>

     

     

    and

     

    <connection-factory name="RemoteConnectionFactory">

                            <connectors>

                                <connector-ref connector-name="remote-jms"/>

                            </connectors>

                            <entries>

                                <entry name="java:/RemoteConnectionFactory"/>

                                <entry name="java:jboss/exported/jms/RemoteConnectionFactory"/>

                            </entries>

                        </connection-factory>

     

     

     

     

     

     

    Where exactly is <connector name="remote-jms"> supposed to connect?  What is listening on localhost:5445?

    Yes,  I have one instance HornetQ running Local in 5445 Port, but the company will have a single server queue and I'll change this IP to this remote.

     

    Why is <connection-factory name="RemoteConnectionFactory"> referencing <connector-ref connector-name="remote-jms"/>?

    Because is need connected the remote HornetQ and my remote-jms is the host for him.

     

    What role does hornetq-jms.xml play?  JBoss AS7 doesn't use this file.

    Is o file HorneQ Remote

     

    Is dev.com.shopping.product.entity.Produto.ProdutorDeMensagem supposed to be sending messages to a remote server?

    Yes

    Is the MDB supposed to be consuming messages from a remote server?

    Yes

  • 10. Re: JMS Remote Connection
    Justin Bertram Master

    Although it is technically possible, it's bad practice to change "RemoteConnectionFactory" to point to a remote server.  "RemoteConnectionFactory" is meant to be used by clients running remotely from the server.  It is not meant for clients running locally in the server to connect to a remote server.  As the documentation states, "A connection-factory referencing a netty-connector is suitable to be used by a remote client to send messages to or receive messages from the server (assuming the connection-factory has an appropriately exported entry)."  Since your server has no acceptors then you should remove <connection-factory name="RemoteConnectionFactory"> completely to avoid confusion.  If you want to send messages to a remote server then you can use "java:/JmsXA" as it's currently configured.

     

    Your MDB has no chance to consume messages from a remote server because you haven't configured it correctly.  You need to configure the "connectorClassName" and "connectionParameters" activation configuration properties.  For example:

     

    @MessageDriven(name = "MyMdbHandlerName", activationConfig = {
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
        @ActivationConfigProperty(propertyName = "destination", propertyValue = "jms/topic/ServerNotification"),
        @ActivationConfigProperty(propertyName = "user", propertyValue = "guest"),
        @ActivationConfigProperty(propertyName = "password", propertyValue = "guest"),
        @ActivationConfigProperty(propertyName = "connectorClassName", propertyValue = "org.hornetq.core.remoting.impl.netty.NettyConnectorFactory"),        
        @ActivationConfigProperty(propertyName = "connectionParameters", propertyValue = "host=127.0.0.1;port=5445")
        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })
    
  • 11. Re: JMS Remote Connection
    Luiz Carlos Silva Newbie

    Ok, but I need connect in external system HornetQ, the configuration standalone.xml is my major problem, but I'll do some tests with the changes you told me.

  • 12. Re: JMS Remote Connection
    Justin Bertram Master

    Ok, but I need connect in external system HornetQ...

    Yes, of course.  Just change the "connectionParameters" activation configuration property to suit your environment.

  • 13. Re: JMS Remote Connection
    Luiz Carlos Silva Newbie

    Hum, but even changed this confuration , I need change the standalone.xml? Or I can leave the default setting as if I was using the hornet that it already exists, and only change like the post below

    https://community.jboss.org/message/585727