Load Balancing endpoint in wso2esb 4.7.0 - wso2

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>

Related

How to inject http endpoint adresses as a environment in WSO2?

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

How to call many Endpoint successively in WSO2 Integration Studio?

I was about implement a workflow of a Job using many calls mediators , each one it works perfect until i put them together so it didn't work and it give me this WARN in my console
[2022-12-19 16:55:03,026] INFO {SourceHandler} - Writer null when calling informWriterError
[2022-12-19 16:55:03,027] WARN {SourceHandler} - STATE_DESCRIPTION = Socket Timeout occurred after accepting the request headers and the request body, INTERNAL_STATE = REQUEST_DONE, DIRECTION = REQUEST, CAUSE_OF_ERROR = Connection between the client and the EI timeouts, HTTP_URL = /NumSequence, HTTP_METHOD = GET, SOCKET_TIMEOUT = 180000, CLIENT_ADDRESS = /127.0.0.1:57800, CONNECTION http-incoming-3 Correlation ID : dd34a03b-a3e6-4f6a-a254-230076b41246
this is my code :
The first API execute an SQL Statement of drop
The second API execute an SQL Statement of create
The third API execute an SQL Statement select
The forth API execute an SQL Statement of update
<api context="/NumSequence" name="NumSequence" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET">
<inSequence>
<call>
<endpoint>
<http method="get" uri-template="http://ebs-dev:8290/services/RADMINDataService/numseqdrop">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>-1</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
<call>
<endpoint>
<http method="get" uri-template="http://ebs-dev:8290/services/RADMINDataService/numseqcreate">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>-1</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
<call>
<endpoint>
<http method="get" uri-template="http://ebs-dev:8290/services/CRMDataService/ReadUsername">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>-1</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
<iterate expression="//accounts/account">
<target>
<sequence>
<payloadFactory media-type="json" template-type="freemarker">
<format><![CDATA[{
"_postaddusername": {
"NumSequence":${payload.account.NumSequence},
"Prefixe":"${payload.account.Prefixe}"
}
}]]></format>
<args/>
</payloadFactory>
<call>
<endpoint>
<http method="post" uri-template="http://ebs-dev:8290/services/RADMINDataService/AddUsername">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>-1</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
</sequence>
</target>
</iterate>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>

WSO2: Can't find endpoint, error code 305100, error message: "Couldn't find the endpoint with the key"

I'm trying to call an endpoint from a sequence using WSO2 Integration Studios. Whenever I define the endpoint in-line, my code works fine and I get a response from the endpoint. Whenever I define the endpoint as a separate entity, it stops working and I get the following error-message: "MESSAGE = An unexpected error occurred., REST_API = null, ERROR_CODE = 305100, ERROR_MESSAGE = Couldn't find the endpoint with the key..."
My code looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="XMLSeq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log category="TRACE" description="Log Request Payload"/>
<call description="Send request to the endpoint">
<endpoint key="TestEndpoint" />
</call>
</sequence>
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="TestEndpoint" xmlns="http://ws.apache.org/ns/synapse">
<http method="get" uri-template="https://[api]">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
For reference, my code does work when it looks like this:
`<?xml version="1.0" encoding="UTF-8"?>
<sequence name="XMLSeq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log category="TRACE" description="Log Request Payload"/>
<call description="Send request to the endpoint">
<endpoint name="TestEndpoint" xmlns="http://ws.apache.org/ns/synapse">
` <http method="get" uri-template="https://[api]">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
</sequence>
This "Couldn't find the endpoint with the key.." error occurred when EI/ESB cannot find the endpoint configuration in the synapse configuration space.
Check whether you have added it to the composite application project when bundling all the synapse xml artefacts to the .car file.

How to create a Default Endpoint in wso2 ESB

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.

WSO2 Default configuration of Endpoints

I have a wso2 esb 4.7.0 proxy with an inline endpoint and inline configurations like suspendOnFailure ormarkForSuspension.
The <markForSuspension><errorCodes>-1 (never suspend) is very important for all my endpoints. So far I need to copy/paste the whole configuration tags for each endpoint.
How can I change the default value for markForSuspension?
Then I would not have to give the whole configuration for each endpoint anymore.
<?xml version="1.0" encoding="UTF-8"?>
<proxy>
<!-- .... -->
<send>
<endpoint>
<address uri="##To##">
<timeout>
<duration>30000</duration>
<responseAction>fault</responseAction>
</timeout>
<suspendOnFailure>
<errorCodes>-1</errorCodes>
<initialDuration>0</initialDuration>
<progressionFactor>1.0</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<errorCodes>-1</errorCodes>
</markForSuspension>
</address>
</endpoint>
</send>
</inSequence>
</target>
</proxy>
AFAIK, you cannot change the default values unless you modify the code (and recompile).
I would recommend you to create a template for you endpoint. See Sample 752
For example, you can try following configuration.
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="TestProxy"
transports="http"
statistics="enable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<send>
<endpoint name="ep_name"
template="ep_template"
uri="##To##"/>
</send>
</inSequence>
...
</target>
</proxy>
Following is the template for endpoint
<template xmlns="http://ws.apache.org/ns/synapse" name="ep_template">
<endpoint name="$name">
<address uri="$uri">
<timeout>
<duration>30000</duration>
<responseAction>fault</responseAction>
</timeout>
<suspendOnFailure>
<errorCodes>-1</errorCodes>
<initialDuration>0</initialDuration>
<progressionFactor>1.0</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<errorCodes>-1</errorCodes>
</markForSuspension>
</address>
</endpoint>
</template>
I hope this helps