Exception handling for Endpoints in wso2 - wso2

I am new to WSO2 EI.
Task: I am sending a message to Endpoint queue and if the endpoint queue is not reachable, I have to retry for 3 times and still its not reachable then I have to send message to another queue.
Approach: I got many links in Stack Overflow.
I am using below code in my endpoint.
<?xml version="1.0" encoding="UTF-8"?>
<endpoint name="DestinationEndPoint" xmlns="http://ws.apache.org/ns/synapse">
<address uri="jms:/TARGET?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://192.168.1.33:61616&transport.jms.DestinationType=queue"/>
<timeout>
<duration>30000</duration>
<responseAction>fault</responseAction>
</timeout>
<suspendOnFailure>
<errorCodes>-1</errorCodes>
<initialDuration>0</initialDuration>
<progressionFactor>1.0</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>3</retriesBeforeSuspension>
<errorCodes>-1</errorCodes>
</markForSuspension>
</endpoint>
I have given the wrong IP so that while sending message it will fail.
But the issue is at 1st trial only its sending the message to error queue, but I have to retry for 3 times and then I have to send to error queue.
Can you please give me any suggestions?

Related

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.

wso2 micro integrator clustering for a service - creating another question, since first one was closed for no eason

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.

Endpoint [ State : SUSPENDED ]

We are facing an issue with wso2 ESB endpoint getting suspended for 3000ms when the URL it tries to invoke is not available for a second, because of this suspension the next calls to the same endpoint gets fail even when the backend URL is available.
Below is the same Log what we get when an endpoint gets suspended and also the endpoint configuration what we are using now.
TID: [-1234] [] [2019-10-30 15:08:39,121] WARN {org.apache.synapse.endpoints.EndpointContext} - Endpoint : conf//endpoint/epsomebackendurl with address https://somebackendurl.com will be marked SUSPENDED as it failed
TID: [-1234] [] [2019-10-30 15:08:39,121] WARN {org.apache.synapse.endpoints.EndpointContext} - Suspending endpoint : conf//endpoint/epsomebackendurl with address https://somebackendurl.com - current suspend duration is : 30000ms - Next retry after : Wed Oct 30 15:09:09 GMT 2019
Endpoint Configuration
<?xml version="1.0" encoding="UTF-8"?>
<endpoint xmlns="http://ws.apache.org/ns/synapse"
name="conf//endpoint/epsomebackendurl">
<property name="System-Name" value="JUNIFER" scope="default"
type="STRING"/>
<http uri-template="https://somebackendurl.com"
method="get">
<suspendOnFailure>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension>
</http>
</endpoint>
Please let me know is there any other option that we can make to stop endpint getting suspended.
We are using wso2esb-5.0.0 version.
Thanks
The default behavior is faulting a request of Synapse endpoint is, the endpoint will suspend for 30000ms.
If you want to stop suspending, the following endpoint is never suspended.
<endpoint name="NoSuspendEndpoint">
<address uri="http://localhost:9000/services/SimpleStockQuoteService">
<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>

WSO2 esb endpoint template uri parameter concat

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>

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.