2016-07-19 38 views
2

我是WSO2 ESB的新手,我正在努力解决与动态生成的端点地址uris有关的一个问题。WSO2-动态注入到端点的值

我随后tutorial如何使用的RabbitMQ WSO2整合和我创建了以下端点:

<?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> 

不过,我想动态地注入rabbitmq.server.host.name的价值,所以我创建了一个本地条目,如下图所示:

<?xml version="1.0" encoding="UTF-8"?> 
    <localEntry key="queue.hostname" xmlns="http://ws.apache.org/ns/synapse"><![CDATA[localhost]]></localEntry> 

并注入该值到端点:

<?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> 

在测试过程中,我发现在不正确地注入到URI和URI该属性queue.hostname值:

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 

代替:

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 

你知道我在做什么错误? 我会补充任何示例代码。

预先感谢您!

+1

什么是您使用的ESB版本? –

+0

wso2esb-5.0.0-beta,但我可以很容易地切换到wso2esb-5.0.0-beta2,如果它将需要 – bontade

回答

1

当你从物业中介采取的价值观,它不能在URI的中间分配为它并不需要的参数值。所以你必须为此使用端点模板。

示例场景:根据您的情况

<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> 

使用。参考:https://docs.wso2.com/display/ESB490/Endpoint+Template

+0

好的,谢谢,我会测试它。说实话,我一直在寻找名为axis2ns158的标签的描述,我找不到任何有趣的东西。你怎么知道我们应该使用该标签? – bontade

+1

当您在端点模板中添加参数时,它将通过突触(供其参考)添加。你不需要强行添加它。 U可以通过管理控制台进行测试。 –