Saturday, March 26, 2016

Adding JMS Message Store with HornetQ Broker

1) Download HornetQ Broker : http://hornetq.jboss.org/downloads.html

2) Configure HornetQ:

  • Go to HornetQ_Home/config/stand-alone/non-clustered/
  • You will find hornetq_jms.xml
  • Change it as follows:

Note: This will create queue connection factory, topic connection factory and a queue. Queue will be used as storing place for JMS message store.

 <connection-factory name="QueueConnectionFactory">  
    <xa>false</xa>  
    <connectors>  
      <connector-ref connector-name="netty"/>  
    </connectors>  
    <entries>  
      <entry name="/QueueConnectionFactory"/>  
    </entries>  
 </connection-factory>  
 <connection-factory name="TopicConnectionFactory">  
    <xa>false</xa>  
    <connectors>  
      <connector-ref connector-name="netty"/>  
    </connectors>  
    <entries>  
      <entry name="/TopicConnectionFactory"/>  
    </entries>  
 </connection-factory>  
 <queue name="wso2">  
    <entry name="/queue/mySampleQueue"/>  
 </queue>  


3) Configure ESB: 

  • Go to ESB_Home/repository/components/lib/
  • Add hornetq-all.jar: https://docs.google.com/a/wso2.com/file/d/0B_g60lAUxtLhd2RmZXJWUVkwWXM/edit
  • Go to ESB_Home/repository/conf/axis2/
  • You will find axis2.xml
  • Change it as follows:

Uncomment follow line:

 <transportSender name="jms" class="org.apache.axis2.transport.jms.JMSSender"/>  

Add these lines:

 <transportReceiver name="jms"  
  class="org.apache.axis2.transport.jms.JMSListener">  
  <parameter name="myTopicConnectionFactory" locked="false">  
  <parameter name="java.naming.factory.initial" locked="false">org.jnp.interfaces.NamingContextFactory</parameter>  
  <parameter name="java.naming.factory.url.pkgs" locked="false">org.jboss.naming:org.jnp.interfaces</parameter>  
  <parameter name="java.naming.provider.url" locked="false">jnp://localhost:1099</parameter>  
  <parameter name="transport.jms.ConnectionFactoryJNDIName"  
   locked="false">TopicConnectionFactory</parameter>  
  <parameter name="transport.jms.ConnectionFactoryType"  
   locked="false">topic</parameter>  
  </parameter>  
  <parameter name="myQueueConnectionFactory" locked="false">  
  <parameter name="java.naming.factory.initial" locked="false">org.jnp.interfaces.NamingContextFactory</parameter>  
  <parameter name="java.naming.factory.url.pkgs" locked="false">org.jboss.naming:org.jnp.interfaces</parameter>  
  <parameter name="java.naming.provider.url" locked="false">jnp://localhost:1099</parameter>  
  <parameter name="transport.jms.ConnectionFactoryJNDIName"  
   locked="false">QueueConnectionFactory</parameter>  
  <parameter name="transport.jms.ConnectionFactoryType"  
   locked="false">queue</parameter>  
  </parameter>  
  <parameter name="default" locked="false">  
  <parameter name="java.naming.factory.initial" locked="false">org.jnp.interfaces.NamingContextFactory</parameter>  
  <parameter name="java.naming.factory.url.pkgs" locked="false">org.jboss.naming:org.jnp.interfaces</parameter>  
  <parameter name="java.naming.provider.url" locked="false">jnp://localhost:1099</parameter>  
  <parameter name="transport.jms.ConnectionFactoryJNDIName"  
   locked="false">QueueConnectionFactory</parameter>  
  <parameter name="transport.jms.ConnectionFactoryType"  
   locked="false">queue</parameter>  
  </parameter>  
 </transportReceiver>  

  • You have to change JNDI properties of ESB
  • Go to ESB_HOME/repository/conf
  • And you will find jndi.properties file. Open and edit it. Add following line:
 connectionfactory.QueueConnectionFactory = jnp://localhost:1099  

Note: if you need you can also add queues and topics here.

4) Start HornetQ (HornetQ_home/bin)

 sudo ./run.sh  

5) Start ESB server (ESB_Home/bin)

 sh wso2server.sh  

6) Go to management console (https://<IP>:9443/carbon/admin/login.jsp)

7) Go to message stores (Home > Manage > Service Bus > Message Stores)

8) Add JMS message store (Add message stores > Add JMS message store)

9) Give relevant details to add message store

  • Name: As you want
  • Initial Context Factory: org.jnp.interfaces.NamingContextFactory
  • Provider URL: jnp://localhost:1099
  • JNDI Queue Name: queue/mySampleQueue
    Add other details accordingly. 

Note: Remember to remove user name and password. If you are using them, you have to configure HornetQ with that username and password.

10) Click "Save". Then your JMS message store will be created.

Yea, You may feel like "Tadaaa". But for me, it took long time to figure this out ;) 

Happy coding :)



No comments:

Post a Comment