Pages

Wednesday, October 8, 2014

Create WSO2 ESB Connector for Absolute beginners

In this blog post I’m presenting proper, easiest and standard approach to create esb connector for The WSO2 ESB.

If you follow these steps you can avoid errors or problems at the end of the project, specially when writing integration test.

If you are not familiar with WSO2 ESB read the article “Enterprise Service Integration with WSO2 ESB” [1], and it presents most of information about enterprise integration, wso2 ESB and how we can use it in real world application with an example (Better read you are new to wso2 products).

Fork and clone or just clone wso2 esb-connectors repository following the link https://github.com/wso2-dev/esb-connectors. this repository consists of source codes of all the wso2 esb connectors.
Now find the template directory in your local copy, {LOCAL_CLONE_DIR}/esb-connectors/template ({LOCAL_CLONE_DIR} is the directory that you cloned the repository). It’s a template of directory structure which you need to create for your connector. The most basic file structure is shown below.
If you follow this link to article “How to write WSO2 ESB connectors”[2] you could find summary of purpose of each file in this structure. assemble-connector.xml and filter.properties files does not need to modify for now. Just let it untouched :D …

If you like to contribute for wso2 esb connectors make your file structure to new standardized file structure, we’ll need to modify the above shown file structure to following structure.

Here we’ll consider the connector name as "demo".

First modify {LOCAL_CLONE_DIR}/esb-connectors/demo/demo-connector/pom.xml (which is parent pom file of the connector project) to add module.

add module demo-connector-1.0.0
<modules>
           <module>demo-connector-1.0.0</module>
    </modules>

Note: if you like to contribute project, follow the naming convention for the module name
<name_of_connector>-connector-<verion>

Use {LOCAL_CLONE_DIR}/esb-connectors/demo/demo-connector/demo-connector-1.0.0/pom.xml pom file to add repositories, 3rd party libraries (as dependencies) used in the project if available. Update the maven-assembly-plugin as follows:
<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-assembly-plugin</artifactId>
   <executions>
      <execution>
        <id>demo-library</id>
        <phase>compile</phase>
        <goals>
          <goal>attached</goal>
        </goals>
        <configuration>
          <finalName>demo-connector-1.0.0</finalName>
              <appendAssemblyId>true</appendAssemblyId>
              <filters>
            <filter>${basedir}/src/main/assembly/filter.properties</filter>
              </filters>
              <descriptors>
                  <descriptor>src/main/assembly/assemble-connector.xml</descriptor>
              </descriptors>
          </configuration>
      </execution>
   </executions>
</plugin>

Now we’ll focus on where to put our source {LOCAL_CLONE_DIR}/esb-connectors/demo/demo-connector/demo-connector-1.0.0/src/main folder. This folder contains three folders, assembly, resources, java.

‘resources’ folder contains all the synapse configurations.
‘java’ folder contains java source codes that consumed by the connector.
‘assembly’ contains configuration files required for maven-assembly-plugin

Now, you can follow “Creating a Connector”[3] in documentation and “How to write WSO2 ESB connectors”[2] article and create your own connector.

[3] https://docs.wso2.com/display/ESB480/Creating+a+Connector     
 

No comments:

Post a Comment