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 :)



Thursday, March 10, 2016

Adding a sequence to ESB local registry

Hi all,

Its' WSO2 ESB. Lets add an sequence to ESB local registry. Adding sequences/or resources in to governance or configuration registry is easy. Because you can do it easily through Management Console (UI).

Lets consider about local registry...


       1.  Login to ESB

       2.  Browse registry (Home > Registry > Browse)                                                                        

   
      3.  Then u can see config, governance and local registries under _system


      4.  Click on "local"

      5.  Click on "Add resource"


      6.  Give the sequence xml file. (You have to create separate xml file which contains sequence.)
      
<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="localSeq">
    <log level="full">
        <property name="Message" value="This is on store sequence which is stored in local registry" />
    </log>
</sequence>
         
        (U have to save this xml file with the name of sequence. Ex: localSeq.xml)

       7. Click on "Add". Then it will be add to local.           


                                                                         
        8.  Then you have to point it via some mediator or from somewhere. I am using store mediator and pointing it as follows:
<store messageStore="reg" sequence="local:/localSeq.xml" />
             Use syntax "local:/localSeq.xml"


Monday, February 29, 2016

Property Mediator - WSO2 ESB

Hi all,

Property mediator is another special mediator in WSO2 ESB. Property Mediator will not change message which will flow through ESB. But it has special qualities like retrieve properties set on message context. It is very useful as we check message properties with given commands.

Property mediator is conditionally content aware mediator. That means, it will not know message context without giving proper commands. We can give commands to see content and get action upon that.

Can retrieve properties using
      get-property(prop-name)
      
When defining this function, it has to be identify relevant scope. If a property has no defined scope, it defaults to the Synapse message context scope.

General syntax for property mediator.

<property name="string" [action=set|remove] [type="string"] (value="literal" | expression="xpath") [scope=default|transport|axis2|axis2-client] [pattern="regex" [group="integer"]]>
<xml-element/>
?
</property>

Ex:
<?xml version="1.0" encoding="UTF-8"?>
<property xmlns:ns="http://org.apache.synapse/xsd" expression="get-property('axis2','jms.message.delivery.count')" name="JMSXDeliveryCount" scope="default" type="INTEGER" />
              

Refere WSO2 Documentation if you keen to know parameters and to get more knowledge :)
Link: https://docs.wso2.com/display/ESB490/Property+Mediator

Note: Remember functionality of property mediator and different properties which can defined through its scope. It is a sure thing, that u will need "property mediator" if u are an ESB user :)

Waiting for value additions :)

Wednesday, February 24, 2016

Linux Commands - Manage Users

 Hi all,

In Linux, there will be several users. Main user who has administrative authorities is "root". Other than that, you can create users when you are required (I needed a user when installing Active MQ  :) ).

You can create users:
             useradd <username>
             Ex: useradd activemq
         
You can give a password for relevant user:
             sudo passwd <username>
             Ex: sudo passwd activemq

You can see details of available users and their passwords:
             sudo vim /etc/passwd

You can Change users:
             su <username>



Create cloud instances in WSO2 OpenStack

Hey,

I know u are a beginner who are just wondering to create a new instance in WSO2 OpenStack for the first time. Let's begin...

1. You have to login to OpenStack with your credentials : https://iaas.wso2.com/dashboard/auth/login/
(Note: In here use just the first part of your mail as the user name. Ex: hello@wso2.com then just use hello)

2. Make sure you are in the right category.



3. Go to "Access and Security" Panel

4. Go to "Key Pairs" tab and Click on "Create Key Pair". Give a name (Note: Key will always referring you in future instances and make sure to give a proper user name for your key. Ex: dilshani)
Then key will be downloaded.



5. Then lets create an instance. We can create instances from images. Go to "Images" panel.  You may find instance called "Centos-6.5".
So our example instance will create upon Cent OS. You may choose variety of choices like linux, windows etc. as images.

6.  Click on "Launch" and Give a name for instance. Flavor will indicate size of instance.Then click on "Launch"



7. Instance will be created and available in "Instances" Panel. You can go there and check for newly created instance. At there, you can see the IP address of your instance.

8. Lets login to remote instance in cloud.
Go to the place you downloaded your Key. (Ex: Downloads/). There you may find your key as .pem file (dilshani.pem)

From that location you can login to your instance. Type this in terminal:

ssh -i <keyfile> <cloud-username>@<IP of instance>

Ex: ssh -i dilshani.pem centos@192.168.23.55

Note: Cloud user name will be differ according to type of instance. (Ex: "ubuntu" for ubuntu OS, "centos" for Cent OS.

You are done with your first Instance in WSO2 OpenStack :)



Monday, January 12, 2015

Storing in Carbon Registry


In WSO2, "Carbon" is the unique OSGi-based middleware platform for all WSO2 carbon products. In every carbon product like Message Broker, Complex Event Processor (CEP) and Enterprise Service Bus (ESB) has in-built carbon registry as one of common carbon feature. That in-built registry can be easily access by product management console.

Using carbon registry as a service for a carbon component

When developing an external carbon component as stat publisher for Message Broker, had to use in-built carbon registry to store UI data of stat publisher component. For developing purpose, in-built carbon registry can be use as follows: (Used the example of stat publisher component)

  • Carbon platform is OSGi based platform. Therefore have to access carbon registry as a service.  

  •  First have to retrieve registry service from Activator Class of the component. (Every OSGi bundle has bundle activator class)

  • Importing package
 import org.wso2.carbon.registry.core.service.RegistryService    

  •  src reference         
  @scr.reference name="org.wso2.carbon.registry.service"   
          interface="org.wso2.carbon.registry.core.service.RegistryService"  
          cardinality="1..1" policy="dynamic" bind="setRegistryService"   
          unbind="unsetRegistryService"  

  •  In activator class must have separate two methods to set registry to a variable and to unset.  

         /**     
         **Set RegistryService  
         **@param registryService - Registry for this server  
          */  
           protected void setRegistryService(RegistryService registryService) {  
           StatPublisherValueHolder.setRegistryService(registryService );  
           }  
         /**     
          **Remove RegistryService  
          **@param registryService - Registry for this server  
          */  
           protected void removeRegistryService(RegistryService registryService) {  
           StatPublisherValueHolder.setRegistryService(null);  
           }  

  • Through pointed registry service variable, can be used it to do any function within component context registry. Registry can be retrieve through registry service as follows;
 Registry registry = StatPublisherValueHolder.getRegistryService()  
                              .getConfigSystemRegistry(tenantId);    
                      
         ** In here use tenant ID to identify the carbon component instance. It will be useful in multitenancy environment.

Happy Storing in Carbon :)

Comments and Questions are well come !