DynamicurIOutboundEndpoint在Mule 3中没有在运行时获取newUri。我已将我的flow和java代码片段粘贴在下面以供参考。最初我将一个出站端点添加到自定义路由器,然后通过java代码我尝试使用DynamicURIOutboundEndpoint动态更新出站端点的uri。但是在运行时没有使用newUri更新DynamicURIOutboundEndpoint。我也试过扩展AbstractOutboundRouter来代替FilteringOutboundRouter,但结果仍然相同。我已经在网上看到了DynamicURIOutboundEndpoint工作的例子,但它正在使用Mule2。有人可以帮我用mule 3来解决它。我想使用DynamicURIOutboundEndpoint动态设置uri。
<flow name="DemoVipFlow1" doc:name="DemoVipFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP" path="rapp"/>
<logger level="INFO" doc:name="Logger" message="Stage1"/>
<custom-router class="com.vip.DynamicCustomRouter">
<outbound-endpoint address="http://doesnotexist:9999"/>
</custom-router>
</flow>
package com.tivo.vip;
import org.mule.api.MuleEvent;
import org.mule.api.MuleException;
import org.mule.api.MuleMessage;
import org.mule.api.endpoint.EndpointURI;
import org.mule.api.endpoint.OutboundEndpoint;
import org.mule.api.processor.MessageProcessor;
import org.mule.api.routing.CouldNotRouteOutboundMessageException;
import org.mule.api.routing.RoutePathNotFoundException;
import org.mule.api.routing.RoutingException;
import org.mule.config.i18n.CoreMessages;
import org.mule.endpoint.DynamicURIOutboundEndpoint;
import org.mule.endpoint.MuleEndpointURI;
import org.mule.routing.outbound.FilteringOutboundRouter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DynamicCustomRouter extends FilteringOutboundRouter {
@Override
public MuleEvent route(MuleEvent event) throws RoutingException {
MuleMessage message = event.getMessage();
MuleEvent result;
if (routes == null || routes.size() == 0) {
throw new RoutePathNotFoundException(
CoreMessages.noEndpointsForRouter(), event, null);
}
try {
MessageProcessor ep = routes.get(0);
EndpointURI newUri;
if (ep instanceof OutboundEndpoint) {
newUri = new MuleEndpointURI(
"http://${ipAddress}:8899/jolokia/list", muleContext);
ep = new DynamicURIOutboundEndpoint((OutboundEndpoint) ep,
newUri);
}
result = sendRequest(event, message, ep, true);
} catch (MuleException e) {
throw new CouldNotRouteOutboundMessageException(event,
routes.get(0), e);
}
return result;
}
}
答案 0 :(得分:0)
如果您只想发送到动态网址,那么您的方法就会变得非常复杂。假设ipAddress
是可解析的全局属性,则以下工作:
<scripting:component>
<scripting:script engine="groovy">
muleContext.client.send('http://${ipAddress}:8899/jolokia/list',
eventContext.message)
</scripting:script>
</scripting:component>
可用于替换custom-router
。