0

在 Mule 3 中,DynamicURIOutboundEndpoint 没有在运行时获取 newUri。我在下面粘贴了我的流程和 java 代码片段以供参考。最初,我将出站端点添加到自定义路由器,然后通过 java 代码尝试使用 DynamicURIOutboundEndpoint 动态更新出站端点的 uri。但是 DynamicURIOutboundEndpoint 没有在运行时使用 newUri 进行更新。我也尝试过扩展 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;
}
}
4

1 回答 1

0

如果您只想发送到动态 URL,那么您的方法会不必要地复杂。假设ipAddress是可解析的全局属性,则以下工作:

<scripting:component>
    <scripting:script engine="groovy">
        muleContext.client.send('http://${ipAddress}:8899/jolokia/list',
                                eventContext.message)
    </scripting:script>
</scripting:component>

并可用于替换您的custom-router.

于 2013-06-13T15:40:25.987 回答