How to define environment specific parameters and resolve them during build time using maven - WSO2 ESB endpoints

Lets say we have multiple environments named DEV, QA, PROD, you need to have different Carbon Application (C-App) projects to group the dynamic artifacts for different environments such as endpoints, WSDLs and policies.

To address this we can have property file along with artifacts to store environment specific parameters. Maven can build the artifacts based on the properties in the property file to create artifacts that are specific to the given environment.

Given below is an example of this. An endpoint value should be different from one environment to another. We can follow the below approach to achieve this.

Define the endpoint EP1 as below, having a token for hostname which could be replaced later.
    <address trace="disable" uri="http://@replace_token/path"/>

Add the maven antrun plugin to replace the token using a maven property as below in pom file.
  <plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <executions>
      <execution>
        <phase>prepare-package</phase>
        <configuration>
          <tasks>
            <replace token= "@replace_token" value="${hostName}" dir="${basedir}/target/capp/artifacts/endpoint/EP1/">                                 
              <include name="**/*.xml"/>
                           </replace>
          </tasks>
        </configuration>
        <goals>
          <goal>run</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

Now build the project providing the maven property hostName as below,
mvn clean install -DhostName=127.0.0.1
Instead of giving the hostname manually as above, now we can configure jenkins or any other build server to pick up the hostname from a config file and feed it as a system property to the build process.


Once we completed environment specific builds we will have 2 car files for each environment and they have same endpoints but actually they are pointed to different URLs as follows.

|___ End Point Project
    |___DEV
        |__ backendEP.xml     //points to dev backend,   http://dev.wso2as.com/9763
    |___QA
        |__ backendEP.xml     //points to qa backend,      http://qa.wso2as.com/9763


2 comments:

  1. Nice to see your frequent posts, machan. Just came here to say hi. Hope all is well. :)

    Regards,
    Pradeeban.

    ReplyDelete
  2. Yes machan. You are one of the person who truly inspire me to blog :-) Still remember old good days.
    Everything is good. Hope you also doing good.

    ReplyDelete

Empowering the Future of API Management: Unveiling the Journey of WSO2 API Platform for Kubernetes (APK) Project and the Anticipated Alpha Release

  Introduction In the ever-evolving realm of API management, our journey embarked on the APK project eight months ago, and now, with great a...