I would like to create a parametrized endpoint to send messages to JMS queue depending on content of the message, say e.g. MY_QUEUE. The endpoint uri should thus look like
jms:/MY_QUEUE?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:61616&transport.jms.DestinationType=queue
I created and endpoint template like this:
<template xmlns="http://ws.apache.org/ns/synapse" name="TM_out_endpoint_template">
<axis2ns158:parameter xmlns:axis2ns158="http://ws.apache.org/ns/synapse" name="queue"></axis2ns158:parameter>
<endpoint name="$name">
<address uri="jms:/$queue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:61616&transport.jms.DestinationType=queue">
<suspendOnFailure>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension>
</address>
</endpoint>
</template>
However like this the $queue parameter won't get processed. If I substitute the whole URI, it works, but I would like to keep the rest of the URI in the template rather than to pass them from a calling sequence. In short I only want to pass the queue name. How can I concat a param with a string within the endpoint template? E.g. jms:/${queue}?transport... or something. Is there a way?
This is happening because, $ in $queue parameter get ignored during template rendering because of the / prior to that. So you have to populate the queue name with jms:/ prefix.
This is the modified version of your template.
<template xmlns="http://ws.apache.org/ns/synapse" name="TM_out_endpoint_template">
<axis2ns158:parameter xmlns:axis2ns158="http://ws.apache.org/ns/synapse" name="queue"></axis2ns158:parameter>
<endpoint name="$name">
<address uri="$queue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:61616&transport.jms.DestinationType=queue">
<suspendOnFailure>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension>
</address>
</endpoint>
</template>
Related
I am calling an http endpoint in WsO2 Integration Studio. How can I give the address of this endpoint externally as envrionment? .Because the addresses of my endpoints are different in dev environment and live environment. I looked at the document about it. But I couldn't do it.
I want to changeable localhost:XXX address as a environment
Below is my WSO2 code:
<call>
<endpoint>
<http method="get" uri-template="http://localhost:XXX/test">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>-1</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
You can use $SYSTEM:EP_ADDR as the uri-template and set the environment variable EP_ADDR on your environment,
<call>
<endpoint>
<http method="get" uri-template="$SYSTEM:EP_ADDR">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>-1</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
The above config works in fine MI 4.1.0. If this doesn't help please specify the version you are using.
For more info: https://ei.docs.wso2.com/en/latest/micro-integrator/develop/injecting-parameters/#endpoint-parameters
To see how we can inject variables in embed runtime of Integration Studio check https://medium.com/think-integration/how-to-inject-environment-variables-to-wso2-integration-studio-runtime-83b8f0cb882e
What Sanoj mentioned is one option. Another option is to use the Property Mediator. This will allow you are dynamically constructing the URL using the Environment variable or file parameters.
<property expression="concat('https://', get-property('env', 'host'), ':', get-property('env', 'port'))" name="uri.var.ep" scope="default" type="STRING"/>
Then use it in your Endpoint configuration
<call>
<endpoint>
<http method="get" uri-template="{uri.var.ep}">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>-1</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
Update
In order to add them to your runtime you need to export them as environment variables in the server runtime. If you are on a linux environment you can add them into the integrator.sh (Depending on the Product you are using this may change.) For example for the given example above you can add the following two lines.
export host=abcd.efg.com
export port=8987
I am re-factorizing a wso2 project and I wondered how/whether I could do the following. This project is designed to send data to a SOAP Api. In every environment, this API exposes a .wsdl file and the URL and credentials are the only things changing from one environment to another. The most natural thing to do is thus to
create those in the Registry and
load it in the beginning of the job like so
<propertyGroup>
<property expression="get-property('registry', 'gov:/endpoints/sap_constructionSiteUser')" name="sap_constructionSiteUser" scope="default" type="STRING"/>
<property expression="get-property('registry', 'gov:/endpoints/sap_constructionSitePassword')" name="sap_constructionSitePassword" scope="default" type="STRING"/>
<property expression="get-property('registry', 'gov:/endpoints/sap_constructionSiteUrl')" name="uri.var.sap_constructionSiteUrl" scope="default" type="STRING"/>
</propertyGroup>
But I could not find a straightforward way to use this uri.var.sap_constructionSiteUrl in the endpoint definition. The following does not work
<call>
<endpoint>
<wsdl optimize="mtom" uri="{uri.var.sap_constructionSiteUrl}" port="OUVERTURE_CHANTIER" service="OUVERTURE_CHANTIER" statistics="enable">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>-1</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</wsdl>
</endpoint>
</call>
Looks like uri= only accept plain value. Is there a way I could made this dynamic without writing the entire endpoint in the Registry (the point is to keep things simple for the clients)
[Environment]
wso2ei 6.5.0
====================EDIT========================
I just created a template:
<template name="crm4sap-constructionSiteTemplate" xmlns="http://ws.apache.org/ns/synapse">
<axis2ns488:parameter name="port" xmlns:axis2ns488="http://ws.apache.org/ns/synapse"/>
<axis2ns489:parameter name="service" xmlns:axis2ns489="http://ws.apache.org/ns/synapse"/>
<axis2ns490:parameter name="uri" xmlns:axis2ns490="http://ws.apache.org/ns/synapse"/>
<endpoint name="$name">
<wsdl port="$port" service="$service" uri="$uri">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</wsdl>
</endpoint>
</template>
And I call it with
<call>
<endpoint name="constructionSiteEndpoint" template="crm4sap-constructionSiteTemplate">
<axis2ns468:parameter name="port" value="OUVERTURE_CHANTIER" xmlns:axis2ns468="http://ws.apache.org/ns/synapse"/>
<axis2ns469:parameter name="service" value="OUVERTURE_CHANTIER" xmlns:axis2ns469="http://ws.apache.org/ns/synapse"/>
<axis2ns469:parameter name="uri" value="{$ctx:sap_constructionSiteUrl}" xmlns:axis2ns469="http://ws.apache.org/ns/synapse"/>
</endpoint>
</call>
Variable substitution does not seem to occur:
[2020-04-15 12:30:54,032] [] WARN - TemplateEndpointFactory Could not read the WSDL endpoint {$ctx:sap_constructionSiteUrl}
java.net.MalformedURLException: no protocol: {$ctx:sap_constructionSiteUrl}
at java.net.URL.<init>(URL.java:600)
at java.net.URL.<init>(URL.java:497)
at java.net.URL.<init>(URL.java:446)
Looks like a common problem
You can try to template this endpoint and then call the template with the parameters. You can pass dynamic values to the template in the runtime.
https://docs.wso2.com/display/EI650/Endpoint+Template
I was able to do it using the following code in the sequence:
<call-template target="template-for-calling-soap">
<with-param name="url" value="{get-property('soap-uri')}"/>
</call-template>
Where soap-uri is a local entry or a simple property, and the sequence template named template-for-calling-soap takes as parameter the url value and has the following code:
<template name="template-for-calling-soap"
xmlns="http://ws.apache.org/ns/synapse">
<parameter name="url"/>
<sequence>
<property expression="$func:url" name="uri.var" scope="default"
type="STRING"/>
<send>
<endpoint>
<address format="soap11" uri="${uri.var}"/>
</endpoint>
</send>
</sequence>
</template>
Let's say we have a micro integrator communicating with several services.
We want to be able to cluster one of the services, for example if we send two requests to a service we want each of these requests to be processed by a different node of a service, is that possible?
Services are third party REST API, we want to send requests to two different URL.
There is Load-BalanceEndPoint element in the Integration studio element, but it's not clear how it works, or even if it permit us to solve the issue above.
Could anyone help us resolve this problem/explain how we should use mentioned endpoint?
Yes, you can use Load-Balance Endpoint for your usecase. Have a look at the following sample configurations.
API configuration :
<?xml version="1.0" encoding="UTF-8"?>
<api context="/loadbalance" name="checkLoadBalance" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET">
<inSequence>
<call>
<endpoint key="testLoadBalance"/>
</call>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
Endpoint Configuration :
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="testLoadBalance" xmlns="http://ws.apache.org/ns/synapse">
<loadbalance algorithm="org.apache.synapse.endpoints.algorithms.RoundRobin">
<endpoint name="endpoint_urn_uuid_6179155B57847314A657084710149040-304004407">
<http method="GET" uri-template="http://www.mocky.io/v2/5e574b1c3000006000fd38cd">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
<endpoint name="endpoint_urn_uuid_6179155B57847314A657084710149040-304004407">
<http method="GET" uri-template="http://www.mocky.io/v2/5185415ba171ea3a00704eed">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</loadbalance>
<description/>
</endpoint>
Here I have used two different mocky endpoints. They will return {"Hello": "World"} and {"hello": "world"}.
After deploying, if I invoke checkLoadBalance API for first time, I will get response from the first endpoint. If I invoke for the second time, I will get response from the second endpoint. Here I have given the algorithm as Roundrobin. Hence it will scheduled in a RoundRobin manner.
I have different services and there respective endpoints in my WSO2 DSS like
http://localhost:9764/services/Get_details/
http://localhost:9764/services/muser_DataService/
etc
so,when am creating a proxy service in WSO2 ESB i want to give a default endpoint in my proxy rather then the particular endpoint in DSS
For this approach i used Recipient List Group as shown below
<endpoint xmlns="http://ws.apache.org/ns/synapse" name="Endpoint">
<endpoint name="null_value">
<address uri="http://localhost:9764/services/null_value/">
<suspendOnFailure>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension>
</address>
</endpoint>
<endpoint name="Get_details">
<address uri="http://localhost:9764/services/Get_details/">
<suspendOnFailure>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension>
</address>
</endpoint>
<endpoint name="Get_geodetails">
<address uri="http://localhost:9764/services/Get_geodetails/">
<suspendOnFailure>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension>
</address>
</endpoint>
<endpoint name="muser_DataService">
<address uri="http://localhost:9764/services/muser_DataService/">
<suspendOnFailure>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension>
</address>
</endpoint>
But when am using this endpoint in my proxy, process is failing to find the required endpoint in the created Recipient List Group and throwing an error as shown below
"Fault":{"faultcode":"axis2ns2:Client","faultstring":"The endpoint reference (EPR) for the Operation not found is \/services\/Get_details\/ and the WSA Action = null. If this EPR was previously reachable, please contact the server administrator.","detail":""}
What can be done for a successful execution......
Recipient endpoint is used for different purpose. You should have different endpoint definition, if your backend service URL is different. Then use proper endpoint in your proxy.
I'm using wso2esb 4.7.0 and wso2dss 3.0.0. Their are multiple services on server i wish to use load balancing endpoint.For that i went through documents.I have cleared my concept but in littlebit confusion that how to implement that in actual proxy service.I have created a load balance endpoint as :
<endpoint xmlns="http://ws.apache.org/ns/synapse" name="TestAddressEndpoint">
<session type="http">
<sessionTimeout>0</sessionTimeout>
</session>
<loadbalance algorithm="org.apache.synapse.endpoints.algorithms.RoundRobin">
<endpoint name="Addressdetail_endp">
<address uri="http://localhost:9764/services/maddress_Dataservice/">
<suspendOnFailure>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension>
</address>
</endpoint>
<endpoint name="Addressdetail_endp2.0">
<address uri="http://localhost:9764/services/maddress_Dataservice2.0/">
<suspendOnFailure>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension>
</address>
</endpoint>
<endpoint name="Addressdetail_endp3.0">
<address uri="http://localhost:9764/services/maddress_Dataservice3.0/">
<suspendOnFailure>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension>
</address>
</endpoint>
</loadbalance>
</endpoint>
Now i wanted to ask that how can i used this endpoint in actual proxy service? Should i make changes in axis2.xml file?
Have a look at this sample. Or else if you can refer to a saved endpoint as below;
<target endpoint="TestAddressEndpoint"/>
Using this is a proxy service;
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="MyProxy"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target endpoint="TestAddressEndpoint"/>
<description/>
...
</proxy>