Saturday, August 22, 2015

Getting Started with Simple WSO2 ESB Custom Inbound Endpoint

WSO2 ESB supports several inbound endpoints, but there can be scenarios that require functionality not provided by the existing inbound endpoints. For example, you might need an inbound endpoint to connect to a certain back-end server or vendor specific protocol.

To support such scenarios, you can write your own custom inbound endpoint by further extending inbound polling or inbound listening. let's Start to build a simple sample Custom Inbound endpoint .

you can download sample source code from here

below one is simple custom inbound skeleton we can implement our own inbound top of this code.


package org.wso2.carbon.inbound.custom.poll;

import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.core.SynapseEnvironment;
import org.wso2.carbon.inbound.endpoint.protocol.generic.GenericPollingConsumer;

public class SamplePollingClient extends GenericPollingConsumer{

 private static final Log log = LogFactory.getLog(SamplePollingClient.class);
 
 /**
    * @param properties
    * @param name
    * @param synapseEnvironment
    * @param scanInterval
    * @param injectingSeq
    * @param onErrorSeq
    * @param coordination
    * @param sequential
    */
   public SamplePollingClient(Properties properties, String name,
                              SynapseEnvironment synapseEnvironment, long scanInterval,
                              String injectingSeq, String onErrorSeq, boolean coordination,
                              boolean sequential) {
    super(properties, name, synapseEnvironment, scanInterval, injectingSeq, onErrorSeq, 
                 coordination, sequential);
    log.info("Initialized the custom polling consumer.");
   }

   @Override
   public Object poll() {
    //TODO need to implement the logic here
    log.info("Inside the execute method.");
    return null;
   }

    /**
     * Stopping the inbound endpoint
     */
    public void destroy() {
        //TODO need to implement the logic here
        log.info("Inside the destroy method, destroying the polling inbound ...");
    }
}

after download the source code Now, Build the code you will get the .Jar file copy file and paste it into dropins folder(/../../wso2esb-4.9.0/repository/components/dropins). then Restart the ESB

SamplePollingClient constructor will initialize and setup the running environment and this is the method to set pre-requirements for our custom inbound.

poll is the method we will implement our  logic and requirement we have to do. inbound will call this method is a given time interval.

destroy is the method will contain the logic’s and functions to clean and free the resources which inbound used while its in active (clean the Registry, etc) 

Sample Configuration through Proxy

<inboundEndpoint name="class" sequence="request" onError="fault"
                            class="org.wso2.carbon.inbound.custom.poll.SamplePollingClient" suspend="false">
   <parameters>
      <parameter name="sequential">true</parameter>
      <parameter name="interval">2000</parameter>
      <parameter name="coordination">true</parameter>
   </parameters>
</inboundEndpoint>


Output
===================
Initialized the custom polling consumer.
Inside the execute method.
Inside the execute method.
Inside the execute method.
Inside the execute method.
Inside the execute method.
.................
.....
...
     
 
when destroying the inbound

Inside the destroy method, destroying the polling inbound ...

References