我有一个引用TCP连接器的TCP入站端点。这是一个请求 - 响应端点。 TCP客户端是第三方应用程序,它仅在一个套接字上发送请求。这就是我设置TCP端点的方法。 端点:
<tcp:inbound-endpoint exchange-pattern="request-response"
responseTimeout="10000" doc:name="TCP" address="${Endpoint}" encoding="ISO-8859-1" connector-ref="TCP"/>
连接器:
<tcp:connector name="TCP" doc:name="TCP connector"
clientSoTimeout="${Client_SO_Timeout}" receiveBacklog="0" receiveBufferSize="0"
sendBufferSize="0" serverSoTimeout="${Server_SO_Timeout}" socketSoLinger="0"
validateConnections="true" keepAlive="true" sendTcpNoDelay="true">
<receiver-threading-profile maxThreadsActive="${TCP_MaxThreadsActive}" maxThreadsIdle = "${TCP_MaxThreadsIdle}" />
<reconnect-forever />
<service-overrides messageReceiver="CustomMessageReceiver" />
<tcp:custom-protocol ref="CustomLengthProtocol" />
</tcp:connector>
流程正常。但是,当必须处理并发请求时,最后几个请求将超时。我从中理解的是,消息在接收器处等待处理(因为只使用了一个TCP会话),直到前一个请求由骡子流完成。
为了调整这个,我正在寻找一种方法来改变骡子流如下:在收到来自客户端的请求后,我需要将它发送到mule-flow,它可以异步处理它并推送响应到同一个插座。一旦在端点处接收到请求,则在处理下一个请求之前不需要等待先前请求的流程完成。没有要求保持来自骡子流的请求/响应的顺序。 有没有办法通过扩展mule TCP端点功能来实现这一目标?这与排队异步流处理策略类似,只是必须将响应发送回原始TCP套接字。
答案 0 :(得分:0)
这是我解决这个问题的方法: (i)我使用的是TCP入站(单向)和TCP出站(单向),而不是使用tcp请求 - 响应入站端点 (ii)TCP-Inbound接收请求,自定义长度协议拆分消息并将其提供给流。 (iii)使用具有VM端点的请求 - 回复范围(入站和出站) (iv)vm端点将消息定向到一个单独的流,该流具有处理策略为&#34;排队异步&#34;。我打算在此流程级别上设置maxThreads以进行线程池化。 (v)第二个流执行业务逻辑,并将响应发送回主流以发送到套接字。 (vi)为了从入站端点访问套接字,我覆盖了TCPMessageReceiver类中的preRouteMuleMessage方法,并添加了一个名为&#34; ClientSocket&#34;的出站属性。到了mulemessage。然后,我将此属性传播到主流到出站端点的末尾。在TCPOutbound端点,我创建了自己的TCPMessageDispatcher并扩展了doDispatch方法。我使用作为mulemessage的一部分共享的套接字对象,而不是使用来自出站端点的线程池的套接字。 样本流程:
<tcp:connector name="TCP" doc:name="TCP connector"
clientSoTimeout="70000" receiveBacklog="0" receiveBufferSize="0"
sendBufferSize="0" serverSoTimeout="70000" socketSoLinger="0"
validateConnections="true" keepAlive="true" sendTcpNoDelay="true" keepSendSocketOpen="true">
<receiver-threading-profile
maxThreadsActive="1" maxThreadsIdle="1" />
<reconnect-forever />
<service-overrides messageReceiver="CustomMessageReceiver" />
<tcp:custom-protocol ref="CustomLengthProtocol" />
</tcp:connector>
<tcp:connector name="TCP2" doc:name="TCP connector"
clientSoTimeout="70000" receiveBacklog="0" receiveBufferSize="0"
sendBufferSize="0" serverSoTimeout="70000" socketSoLinger="0"
validateConnections="true" keepAlive="true" sendTcpNoDelay="true"
keepSendSocketOpen="true">
<receiver-threading-profile
maxThreadsActive="1" maxThreadsIdle="1" />
<reconnect-forever />
<service-overrides dispatcherFactory="CustomMessageDispatcherFactory"/>
<tcp:custom-protocol ref="CustomLengthProtocol" />
</tcp:connector>
<spring:beans>
<spring:bean id="CustomLengthProtocol" name="CustomLengthProtocol"
class="CustomLengthProtocol" />
</spring:beans>
<flow name="tcptestFlow" doc:name="tcptestFlow">
<tcp:inbound-endpoint address="tcp://localhost:4444"
responseTimeout="100000" doc:name="TCP" connector-ref="TCP" />
<byte-array-to-string-transformer
doc:name="Byte Array to String" />
<logger level="INFO" category="Expression" doc:name="Logger" />
<set-session-variable variableName="Socket"
value="#[message.outboundProperties['ClientSocket']]"
doc:name="Session Variable" />
<logger message="#[payload] - #[Socket]" level="INFO" category="Request"
doc:name="Logger" />
<request-reply doc:name="Request-Reply">
<vm:outbound-endpoint exchange-pattern="one-way"
path="/qin" doc:name="VM" >
<message-properties-transformer scope="outbound">
<delete-message-property key="MULE_REPLYTO"></delete-message-property>
</message-properties-transformer>
</vm:outbound-endpoint>
<vm:inbound-endpoint exchange-pattern="one-way"
path="/qout" doc:name="VM" />
</request-reply>
<logger message="#[payload]" level="INFO" doc:name="Logger"
category="Response" />
<string-to-byte-array-transformer
doc:name="String to Byte Array" />
<tcp:outbound-endpoint address="tcp://localhost:4444"
responseTimeout="10000" doc:name="TCP" connector-ref="TCP2" />
</flow>
<flow name="tcptestFlow1" processingStrategy="queued-asynchronous"
doc:name="tcptestFlow1">
<vm:inbound-endpoint exchange-pattern="one-way"
path="/qin" doc:name="VM" />
<logger message="Inside VM Flow" level="INFO" doc:name="Logger" />
<set-payload value="Appended Response - #[payload]"
doc:name="Set Payload" />
<vm:outbound-endpoint exchange-pattern="one-way"
path="/qout" doc:name="VM" />
</flow>