Thursday, January 26, 2017

WSO2 ESB - How to assign endpoints at build time

In WSO2 ESB endpoint values can be represented as resource variables(place holders). Endpoint values can then be assigned at build time. You need to use maven-replacer-plugin to achieve this.
1. Using ESB Tooling, create an ESB Config project and create a proxy service within the project. Define your endpoint address as a variable using  a syntax similar to follows

   
       
           
               
                   
2. Add the maven-replacer-plugin configuration to in the pom.xml file of the ESB project.

   com.google.code.maven-replacer-plugin
   replacer
   1.5.3
   
       
           package
           
               replace
           
       
   
   
       
           ${basedir}/target/**/*.xml
       
       
           
               @HelloWorldEp
               ${helloWorld.ep}
           
       
   

3. Create a CApp containing the ESB Config project you created above.
4. Build the ESB Config project first, using the following command
         mvn clean install -DhelloWorld.ep="http://localhost:9773/services/HelloService/"
5. And then  build the CApp project. Check the proxy service created in the target directory of the CApp project. You will see the variable @HelloWorldEp is replaced by the URL value provided at the time of building.  





   
       
           
               
NOTE
Alternatively you can use the Maven Multi Module(MMM) project to make this process more simpler (which is also the best practice[1] when developing WSO2 projects). We can use MMM as the parent project for ESB and CApp projects. For this, first create a MMM project, then create ESB project and CApp project as child modules of MMM project (following step 1,2 and 3). Then Build the Maven Multi Module project using the same command as in step 4. This reduces the build of each modules, as MMM does that for you. Sample project for this implementation can be found at my Github esb-samples Repo https://github.com/susinda/esb-samples/tree/master/assign-endpoints-at-buildtime/

[1] - http://wso2.com/library/articles/2015/10/article-wso2-developer-studio-development-and-deployment-best-practices/

No comments: