Skip to content

Injecting Parameters as Environment Variables

When deploying integration artifacts in different environments, it is necessary to change the synapse parameters used in the artifacts according to the environment. For example, the 'endpoint URL' will be different in each environment. If you define the synapse parameters in your artifacts as explained below, you can inject the required parameter values for each environment using system variables. Without this feature, you need to create and maintain separate artifacts for each environment.

This feature is useful for container deployments. We need to dynamically inject the parameter values to the docker container.

Injecting Endpoint parameters

Configure the Endpoint parameters in your synapse configuration as shown below.

Endpoint Type Parameters
Address Endpoint uri
HTTP Endpoint uri
Loadbalance Endpoint hostname and port
RecipientList Endpoint hostname and port
Template Endpoint uri
WSDL Endpoint wsdlURI

Example

In the following example, the endpoint URL is configured for an environment variable.

<?xml version="1.0" encoding="UTF-8"?>
<endpoint xmlns="http://ws.apache.org/ns/synapse" name="JSON_EP">
  <address uri="$SYSTEM:VAR"/>
</endpoint>
  • In a VM deployment, you can export the variables as shown below. Here VAR is the url you need to have set as environment property.

    export VAR=http://localhost:61616/...

Injecting Data service parameters

  • Driver
  • URL
  • Username
  • Password

Example

In the following example, the data service parameters are configured for an environment variable.

<data name="DataServiceSample" serviceGroup="" serviceNamespace="">
    <description/>
    <config id="SourceSample">
        <property name="org.wso2.ws.dataservice.user">$SYSTEM:uname</property>
        <property name="org.wso2.ws.dataservice.password">$SYSTEM:pass</property>
        <property name="org.wso2.ws.dataservice.protocol">$SYSTEM:url1</property>
        <property name="org.wso2.ws.dataservice.driver">$SYSTEM:driver1</property>
    </config>
    <query>
    --------------------
    </query>
    <operation>
    --------------------
    </operation>
</data>
<datasource>
    <name>MySQLConnection</name>
    <description>MySQL Connection</description>
    <definition type="RDBMS">
        <configuration>
            <driverClassName>$SYSTEM:driver1</driverClassName>
            <url>$SYSTEM:url1</url>
            <username>$SYSTEM:uname</username>
            <password>$SYSTEM:pass</password>
        </configuration>
    </definition>
</datasource>
  • In a VM deployment, you can export the variables as shown below. Here VAR is the url you need to have set as environment property.

    export uname=
    export pass=
    export url1=
    export driver1=

Injecting Scheduled Task parameters

The pinned servers parameter can be set as an environment variable for a scheduled task or proxy service. See the examples given below.

Example

<?xml version="1.0" encoding="UTF-8"?>
<task class="org.apache.synapse.startup.tasks.MessageInjector" group="synapse.simple.quartz" name="ProxytestInject" pinnedServers="$SYSTEM:pinned" xmlns="http://ws.apache.org/ns/synapse">
    <trigger count="5" interval="10"/>
    <property name="injectTo" value="proxy" xmlns:task="http://www.wso2.org/products/wso2commons/tasks"/>
    <property name="proxyName" value="testProxy" xmlns:task="http://www.wso2.org/products/wso2commons/tasks"/>
    <property name="soapAction" value="mediate" xmlns:task="http://www.wso2.org/products/wso2commons/tasks"/>
    <property name="message" xmlns:task="http://www.wso2.org/products/wso2commons/tasks">
        ----------
    </property>
</task>
  • In a VM deployment, you can export the variables as shown below. Here VAR is the url you need to have set as environment property.

    export pinned=

Injecting Inbound Endpoint parameters

See the list of properties that can be defined as environment variables:

Example

<?xml version="1.0" encoding="UTF-8"?>
<inboundEndpoint name="jms" onError="fault" protocol="jms" sequence="LogMsgSeq" suspend="false" xmlns="http://ws.apache.org/ns/synapse">
    <parameters>
        <parameter name="interval">15000</parameter>
        <parameter name="sequential">true</parameter>
        <parameter name="coordination">true</parameter>
        <parameter name="transport.jms.Destination">myq</parameter>
        <parameter name="transport.jms.CacheLevel">3</parameter>
        <parameter name="transport.jms.ConnectionFactoryJNDIName">$SYSTEM:jmsconfac</parameter>
        <parameter name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>
        <parameter name="java.naming.provider.url">$SYSTEM:jmsurl</parameter>
        <parameter name="transport.jms.UserName">$SYSTEM:jmsuname</parameter>
        <parameter name="transport.jms.SessionAcknowledgement">AUTO_ACKNOWLEDGE</parameter>
        <parameter name="transport.jms.Password">$SYSTEM:jmspass</parameter>
        <parameter name="transport.jms.SessionTransacted">false</parameter>
        <parameter name="transport.jms.ConnectionFactoryType">queue</parameter>
        <parameter name="transport.jms.ContentType">application/xml</parameter>
        <parameter name="transport.jms.SharedSubscription">false</parameter>
        <parameter name="pinnedServers">$SYSTEM:pinned</parameter>
        <parameter name="transport.jms.ResetConnectionOnPollingSuspension">false</parameter>
    </parameters>
</inboundEndpoint>
  • In a VM deployment, you can export the variables as shown below. Here VAR is the url you need to have set as environment property.

    export jmsconfac=
    export jmsurl=
    export jmsuname=
    export jmspass=
    export pinned=

Injecting proxy service parameters

The pinned servers parameter as well as all the service-level transport parameters:

Example

<?xml version="1.0" encoding="UTF-8"?>
<proxy name="JmsListner" pinnedServers="localhost" startOnLoad="true" transports="http https jms" xmlns="http://ws.apache.org/ns/synapse">
    <target>
        <inSequence>
            -------------
            <drop/>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </target>
    <parameter name="transport.jms.SessionAcknowledgement">AUTO_ACKNOWLEDGE</parameter>
    <parameter name="transport.jms.Destination">myq</parameter>
    <parameter name="transport.jms.ConnectionFactoryType">queue</parameter>
    <parameter name="transport.jms.ContentType">application/xml</parameter>
    <parameter name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>
    <parameter name="java.naming.provider.url">$SYSTEM:jmsurl</parameter>
    <parameter name="transport.jms.SessionTransacted">false</parameter>
    <parameter name="transport.jms.ConnectionFactoryJNDIName">$SYSTEM:jmsconfac</parameter>
    <parameter name="transport.jms.UserName">$SYSTEM:jmsuname</parameter>
    <parameter name="transport.jms.Password">$SYSTEM:jmspass</parameter>
</proxy>
  • In a VM deployment, you can export the variables as shown below. Here VAR is the url you need to have set as environment property.

    export jmsurl=
    export jmsconfac=
    export jmsuname=
    export jmspass=

Injecting Message Store parameters

Message Store Type Parameters
JMS Message Store
  • store.jms.username
  • store.jms.password
  • store.jms.connection.factory
WSO2 MB Message Store
RabbitMQ Message Store
  • store.rabbitmq.host.name
  • store.rabbitmq.host.port
  • store.rabbitmq.username
  • store.rabbitmq.password
JDBC Message Store
  • store.jdbc.drive
  • store.jdbc.connection.url
  • store.jdbc.username
  • store.jdbc.password
Resequence Message Store

Example

<?xml version="1.0" encoding="UTF-8"?>
<messageStore class="org.apache.synapse.message.store.impl.rabbitmq.RabbitMQStore" name="InboundStore" xmlns="http://ws.apache.org/ns/synapse">
    <parameter name="store.rabbitmq.host.name">$SYSTEM:rabbithost</parameter>
    <parameter name="store.producer.guaranteed.delivery.enable">false</parameter>
    <parameter name="store.rabbitmq.host.port">$SYSTEM:rabbitport</parameter>
    <parameter name="store.rabbitmq.route.key"/>
    <parameter name="store.rabbitmq.username">$SYSTEM:rabbitname</parameter>
    <parameter name="store.rabbitmq.virtual.host"/>
    <parameter name="rabbitmq.connection.ssl.enabled">false</parameter>
    <parameter name="store.rabbitmq.exchange.name">exchange3</parameter>
    <parameter name="store.rabbitmq.queue.name">queue3</parameter>
    <parameter name="store.rabbitmq.password">$SYSTEM:rabbitpass</parameter>
</messageStore>
  • In a VM deployment, you can export the variables as shown below.

    export rabbithost=
    export rabbitport=
    export rabbitname=
    export rabbitpass=
Top