3 Replies Latest reply on Jun 2, 2014 5:45 AM by ravi.teja

    Example on how to connect to a remote HornetQ topic from an MDB

    cremersstijn

      I am looking for an example on how to connect from a java MDB to a remote HornetQ topic in jboss EAP 6.2

       

      This is my mdb:

       

      @MessageDriven(activationConfig = {
          @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
          @ActivationConfigProperty(propertyName = "destination", propertyValue = "jms/OutboundAsnPublishDeliveryNoteTopic"),
          @ActivationConfigProperty(propertyName = "clientId", propertyValue = "ProductLoggerService"),
          @ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "Durable"),
          @ActivationConfigProperty(propertyName = "subscriptionName", propertyValue = "ProductLogger"),
          @ActivationConfigProperty(propertyName = "maxSession", propertyValue = "2"),
          @ActivationConfigProperty(propertyName = "reconnectInterval", propertyValue = "60000"),
          @ActivationConfigProperty(propertyName = "reconnectAttempts", propertyValue = "-1")})
      @Pool(value = "ReceiveDeliveryNoteMDB")
      public class ReceiveDeliveryNoteMDB implements MessageListener {
      ...
      }
      

       

      But where do i specify which connection factory it should used?

       

      I have configured a pooled connection factory in the standalone.xml

        • 1. Re: Example on how to connect to a remote HornetQ topic from an MDB
          ravi.teja

          Hi

          In standalone.xml there is subsystem called messaging. See the below code .

           

          Standalone hornetq configuration with jboss as 7

          1) Add or Replace  the below code in jboss standalone-full.xml

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

           

          Hornetq-Configuaration

           

           

          1

           

          2

          3

          4

          5

          6

          7

          8

          9

          10

          11

          12

          13

          14

          15

          16

          17

          18

          19

          20

          21

          22

          23

          24

          25

          26

          27

          28

          29

          30

          31

          32

          33

          34

           

          <hornetq-server>

           

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

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

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

           

                          <connectors>

          <connector name="netty" socket-binding="messaging">

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

          <!–This connecting for remote hornetq server if localhost it is not required -->

          <param key="host" value="<host-name>"/>

          <param key="port" value="<hornetq-port-number>"/>

          </connector>

                          </connectors>

           

                          <jms-connection-factories>

                              <connection-factory name="RemoteConnectionFactory">

                                  <connectors>

                                      <connector-ref connector-name="netty"/>

                                  </connectors>

                                  <entries>

                                      <entry name="RemoteConnectionFactory"/>

                                  </entries>

                              </connection-factory>

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

                                  <transaction mode="xa"/>

                                  <connectors>

                                      <connector-ref connector-name="netty"/>

                                  </connectors>

                                  <entries>

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

                                  </entries>

                              </pooled-connection-factory>

                          </jms-connection-factories>

          </hornetq-server>

          2) Add the socket binding  <socket-binding name="messaging" port="5445"/>

          If any queries please find the attachment named standalone-pool.xml

          3) Once this configuaration done success download the hornetq from www.hornetq.com

          4) For Starting the hornetq open terminal or cmd and  goto hornetq -->bin (folder)

          5) If you are using linux then type command ./run.sh .If it in windows ./run.bat

          If everything goes fine in terminal or command you can see a message hornetq is started

          6)Then start the jboss you can see a message hornetq resource adapter started

           

          Create a queue or topic in hornetq-server and then deploy your application in jboss .

          • 2. Re: Example on how to connect to a remote HornetQ topic from an MDB
            cremersstijn

            That works if all your mdb's need to connect to the same jms server, but not if 1 mdb should connect to server A and another mdb to server B.

             

            But we have found the solution, we need to create another pooled-connection-factory and reference this on the mdb using @ResourceAdapter

            • 3. Re: Example on how to connect to a remote HornetQ topic from an MDB
              ravi.teja

              Hi cremersstijn

               

              Yes , You are absolutely correct .