4 Replies Latest reply on Apr 16, 2012 12:15 PM by dbeltran

    JMS: Best way to connect from server A to server B

    dbeltran

      Hi,

       

      As far I have understanded from: https://issues.jboss.org/browse/AS7-1338, the use of remote protocol is an adaptation to the developers who want to use the old way. So what the suggested way to connect to a remote server from a applicattion running in another servers. Thank you in advance and best regards,

       

      David

        • 1. Re: JMS: Best way to connect from server A to server B
          jbertram

          The best way for an application in one instance of AS 7 to connect to another instance for AS 7 is by using the HornetQ JCA resource adapter.  If you need to consume messages then use an MDB with the approrpriate activation configuration properties, e.g.:

           

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

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

                  @ActivationConfigProperty(propertyName = "destination", propertyValue = "testQueue"),

                  @ActivationConfigProperty(propertyName = "connectorClassName", propertyValue = "org.hornetq.core.remoting.impl.netty.NettyConnectorFactory"),       

                  @ActivationConfigProperty(propertyName = "connectionParameters", propertyValue = "host=192.168.1.137;port=5445")})

           

          If you need to send messages then configure a <pooled-connection-factory>, e.g.:

           

                          <connectors>

                              ...

                              <connector name="remote-jmsxa">

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

                                  <param key="host" value="my.remote.host"/>

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

                              </connector>

                              ...

                          </connectors>

                          ...

                          <jms-connection-factories>

                               ...

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

                                  <transaction mode="xa"/>

                                  <connectors>

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

                                  </connectors>

                                  <entries>

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

                                  </entries>

                              </pooled-connection-factory>

                          </jms-connection-factories>

           

          Then look-up this connection factory (i.e. "java:/RemoteJmsXA") and use it as needed.

          • 2. Re: JMS: Best way to connect from server A to server B
            dbeltran

            Thank Justin,

             

            Do you know where I coud find an example for the producer java code?

             

            Best regards,

             

            David

            • 3. Re: JMS: Best way to connect from server A to server B
              jbertram

              The producer code will follow the standard JMS API.  You can find examples all over the Internet.

               

              You can get a reference to the connection factory from JNDI either using a blank InitialContext or via injection.

              • 4. Re: JMS: Best way to connect from server A to server B
                dbeltran

                Thanks again,

                 

                I asked you because I have founded another thread, https://community.jboss.org/message/721977#721977#721977, in which they are creating the destination through the session instead of the lookup operation. Its a good practice? As far I have read in the jms specification the lookup is more portable. Below is the related snipped code:

                 

                InitialContext ic = new InitialContext();

                ConnectionFactory cf = (ConnectionFactory) ic.lookup(jndiConnectionFactory);

                Connection connection = cf.createConnection(user, passwd);

                Session session = connection.createSession(transactable, acknowledge);

                Destination resourceJMS = session.createQueue(destinationn);

                 

                Best regards,

                 

                David