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

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.

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 throws an error when content type is application/ld+json

I want to call an API that I created with Integration Studio. There are headers that this API uses. API returns ld+json data.When I make a request to the API I created via Postman,gives the following error.
Unexpected character in preface '{' (code 123); expected '<' in [row,col
I added TRANSPORT_HEADERS as remove using Property Mediator. But this time, the API does not work because the Headers information is deleted. I added the following lines to the deployment.toml and axis2.xml files. But it still didn't work.
[[custom_message_builders]]
content_type = "application/json"
class="org.apache.synapse.commons.json.JsonStreamBuilder"
Below is the xml file I used.
<?xml version="1.0" encoding="UTF-8"?>
<api context="/x" name="x" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST GET">
<inSequence>
<call>
<endpoint>
<http method="get" uri-template="https://json-ld.org/contexts/person.jsonld">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>-1</progressionFactor>
<maximumDuration>0</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
<script language="js"><![CDATA[var x = mc.getPayloadJSON();
if (x.id == "urn:ngsi-ld:AirQualitySensor:012")
mc.setPayloadJSON('{"s":"success"}');
else
mc.setPayloadJSON('{"s":"fail"}');]]></script>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
Thank you in advance for your answers
You need to map the correct custom content type to the appropriate message builder. For example if your response content type is application/ld+json you need to add the message builder like the below.
[[custom_message_builders]]
content_type = "application/ld+json"
class="org.apache.synapse.commons.json.JsonStreamBuilder"

WSO2 - value dynamically injected to the endpoint

I am a newbie in WSO2 ESB and I am struggling with one issue related to the dynamically generated endpoint adress uris.
I followed by the tutorial how to integrate RabbitMQ with WSO2 and I created following endpoint:
<?xml version="1.0" encoding="UTF-8"?>
<endpoint xmlns="http://ws.apache.org/ns/synapse" name="Test2">
<address trace="disable" uri="rabbitmq:/Test?rabbitmq.server.host.name=localhost&rabbitmq.server.port=5672&rabbitmq.server.user.name=test&rabbitmq.server.password=test&rabbitmq.queue.name=outputQueue_001&rabbitmq.exchange.name=amq.direct&rabbitmq.queue.routing.key=outputQueue_001&rabbitmq.message.content.type=application/json" />
</endpoint>
However, I wanted to inject dynamically value of rabbitmq.server.host.name, so I created a local entry, like below:
<?xml version="1.0" encoding="UTF-8"?>
<localEntry key="queue.hostname" xmlns="http://ws.apache.org/ns/synapse"><![CDATA[localhost]]></localEntry>
and injected that value to the endpoint:
<?xml version="1.0" encoding="UTF-8"?>
<endpoint xmlns="http://ws.apache.org/ns/synapse" name="Test2">
<property expression="get-property('queue.hostname')" name="queue.hostname" scope="default" type="STRING" />
<address trace="disable" uri="rabbitmq:/Test?rabbitmq.server.host.name={queue.hostname}&rabbitmq.server.port=5672&rabbitmq.server.user.name=test&rabbitmq.server.password=test&rabbitmq.queue.name=outputQueue_001&rabbitmq.exchange.name=amq.direct&rabbitmq.queue.routing.key=outputQueue_001&rabbitmq.message.content.type=application/json" />
</endpoint>
During tests, I discovered that property queue.hostname value in not correctly injected to the URI and URI is:
rabbitmq:/Test?rabbitmq.server.host.name={queue.hostname}&rabbitmq.server.port=5672&rabbitmq.server.user.name=test&rabbitmq.server.password=test&rabbitmq.queue.name=outputQueue_001&rabbitmq.exchange.name=amq.direct&rabbitmq.queue.routing.key=outputQueue_001&rabbitmq.message.content.type=application/json
instead of:
rabbitmq:/Test?rabbitmq.server.host.name=localhost&rabbitmq.server.port=5672&rabbitmq.server.user.name=test&rabbitmq.server.password=test&rabbitmq.queue.name=outputQueue_001&rabbitmq.exchange.name=amq.direct&rabbitmq.queue.routing.key=outputQueue_001&rabbitmq.message.content.type=application/json
Do you know what I am doing wrong?
I will apreciate any example codes.
Thank you in advance!
As you take values from property mediator, it can't assign in the middle of URI as it does not take parameter values. So you have to use endpoint templates for that.
Sample scenario:
<template xmlns="http://ws.apache.org/ns/synapse" name="TM_out_endpoint_template">
<axis2ns158:parameter xmlns:axis2ns158="http://ws.apache.org/ns/synapse" name="host"> </axis2ns158:parameter>
<endpoint name="$name">
<address uri="jms:/MyQueue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://$host:61616&transport.jms.DestinationType=queue">
<suspendOnFailure>
<progressionFactor>1.0</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension>
</address>
</endpoint>
</template>
Use that according to your scenario. Reference: https://docs.wso2.com/display/ESB490/Endpoint+Template

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.