1

我在单个项目中使用多个 HTTP 连接器时遇到了困难。我正在尝试做的事情可能是不可能的,但我想知道是否有一些技巧可以让我完成它。

作为一个可行的起点,我有一个包含三个流的连接器:一个处理根 URL,另外两个处理相对 URL。这是因为每个地址都返回了我期望的有效负载……例如,访问 /flow3 相对路径会返回“Flow3”。

<http:connector name="Connector1">
</http:connector>

<flow name="Flow1">
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" 
        port="8081" connector-ref="Connector1"/>
    <set-payload value="Flow1"/>
</flow>

<flow name="Flow2">
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" 
        port="8081" connector-ref="Connector1" path="flow2"/>
    <set-payload value="Flow2"/>
</flow>

<flow name="Flow3">
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" 
        port="8081" connector-ref="Connector1" path="flow3"/>
    <set-payload value="Flow3"/>
</flow>

但是,假设我想以一种方式配置一些端点,而另一种方式配置一些端点..​​....也许是不同的线程模型......使用连接器。我尝试执行以下操作,即添加另一个连接器并让第三个流程引用它:

<http:connector name="Connector1">
</http:connector>

<http:connector name="Connector2">
    <!-- Eventually some different configuration here -->
</http:connector>

<flow name="Flow1">
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" 
        port="8081" connector-ref="Connector1"/>
    <set-payload value="Flow1"/>
</flow>

<flow name="Flow2">
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" 
        port="8081" connector-ref="Connector1" path="flow2"/>
    <set-payload value="Flow2"/>
</flow>

<flow name="Flow3">
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" 
        port="8081" connector-ref="Connector2" path="flow3"/>
    <set-payload value="Flow3"/>
</flow>

当我这样做时,Flow1 和 Flow2 继续工作,但访问 /flow3 进入 Flow1 返回“Flow1”。我假设这是因为在 Connector1 上处理根级别 URL 的流表明它可以处理该地址。

我尝试删除 Flow1 看看会发生什么。Flow2 继续工作,但 Flow3 现在报告:

No receiver found with secondary lookup on connector: Connector1 with URI key: http://localhost:8081/flow3

(我想知道这是否是导致问题的网站图标请求,但不确定。)

正在做这样的事情......即,在同一个项目中有两个连接器,但将其中一个显式用于相对 URL......可能吗?

4

2 回答 2

3

问题是每个端点都会创建自己的消息接收器。通常这不是问题,但是当涉及到基于 TCP 的传输时,它们会竞争端口。

如果您查看日志,在启动启动画面之前您将看到以下错误:

Root Exception stack trace:
java.net.BindException: Address already in use
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:376)
at java.net.ServerSocket.bind(ServerSocket.java:376)
+ 3 more (set debug level logging or '-Dmule.verbose.exception

这意味着 Flow3 的入站端点无法绑定端口 8081,因为已经拥有该端口的套接字并且该套接字属于 Connector1

于 2013-07-10T00:15:55.430 回答
1

在我看来,你有两种方法:

Mule 域项目以共享资源(http-connector): http: //www.mulesoft.org/documentation/display/current/Shared+Resources

Mule模式:暴露公共端口(8081)并在内部调用使用其他端口的应用程序的http-proxy,并且绑定主机用于localhost以防止外部访问: http: //www.mulesoft.org/documentation/display/当前/HTTP+代理+模式

于 2015-03-13T14:05:35.730 回答