Platinum Partner
java,soa,enterprise-integration,maven,integration,esb,wso2

How to write a custom dispatcher for WSO2 ESB

Create a maven project and add the following dependencies to the pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>Custom_Dispatcher</groupId>
    <artifactId>CustomDispatcher</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>org.apache.synapse</groupId>
            <artifactId>synapse-core</artifactId>
            <version>2.1.0-wso2v5</version>
        </dependency>
        <dependency>
            <groupId>org.apache.synapse</groupId>
            <artifactId>synapse-extensions</artifactId>
            <version>2.1.0-wso2v5</version>
        </dependency>
    </dependencies>
</project>
The new dispatcher will be 'CustomDispatcher'.

Write your own dispatcher (Get an idea about the CustomURIBasedDispatcher.java )
https://svn.wso2.com/wso2/custom/projects/projects/carbon/3.2.3/trunk/dependencies/synapse/2.1.0-wso2v5/modules/core/src/main/java/org/apache/synapse/core/axis2/CustomURIBasedDispatcher.java

Copy it to [WSO2_ESB_Installation]/repository/components/lib and restart ESB.

Include the following in the axis2.xml. It should be inserted into the dispatch phase of the In-Flow of the ESB. It should be the first handler in the Dispatch phase.
<handler name="CustomDispatcher"
 class="com.wso2.Dispatcher.CustomDispatcher"/>

Published at DZone with permission of {{ articles[0].authors[0].realName }}, DZone MVB. (source)

Opinions expressed by DZone contributors are their own.

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}