bontade
bontade

Reputation: 3224

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&amp;rabbitmq.server.port=5672&amp;rabbitmq.server.user.name=test&amp;rabbitmq.server.password=test&amp;rabbitmq.queue.name=outputQueue_001&amp;rabbitmq.exchange.name=amq.direct&amp;rabbitmq.queue.routing.key=outputQueue_001&amp;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}&amp;rabbitmq.server.port=5672&amp;rabbitmq.server.user.name=test&amp;rabbitmq.server.password=test&amp;rabbitmq.queue.name=outputQueue_001&amp;rabbitmq.exchange.name=amq.direct&amp;rabbitmq.queue.routing.key=outputQueue_001&amp;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}&amp;rabbitmq.server.port=5672&amp;rabbitmq.server.user.name=test&amp;rabbitmq.server.password=test&amp;rabbitmq.queue.name=outputQueue_001&amp;rabbitmq.exchange.name=amq.direct&amp;rabbitmq.queue.routing.key=outputQueue_001&amp;rabbitmq.message.content.type=application/json

instead of:

rabbitmq:/Test?rabbitmq.server.host.name=localhost&amp;rabbitmq.server.port=5672&amp;rabbitmq.server.user.name=test&amp;rabbitmq.server.password=test&amp;rabbitmq.queue.name=outputQueue_001&amp;rabbitmq.exchange.name=amq.direct&amp;rabbitmq.queue.routing.key=outputQueue_001&amp;rabbitmq.message.content.type=application/json

Do you know what I am doing wrong? I will apreciate any example codes.

Thank you in advance!

Upvotes: 2

Views: 841

Answers (1)

Dilshani Subasinghe
Dilshani Subasinghe

Reputation: 1952

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

Upvotes: 1

Related Questions