Mule-Tcp出站测试

Mule-Tcp出站测试,mule,Mule,如果使用相同的主机和端口创建多个TCP出站端点,两个端点将使用相同的套接字,即连接或不同的连接,会发生什么情况。如何在mule测试流中获取套接字对象 我在这里使用两个具有相同地址和端口的端点,需要验证两者是否使用相同的连接或不同的连接 <flow name="testOutBoundTCP"> <inbound-endpoint ref="outer" /> <outbound-endpoint ref = "clientEndpoint2"/&

如果使用相同的主机和端口创建多个TCP出站端点,两个端点将使用相同的套接字,即连接或不同的连接,会发生什么情况。如何在mule测试流中获取套接字对象

我在这里使用两个具有相同地址和端口的端点,需要验证两者是否使用相同的连接或不同的连接

<flow name="testOutBoundTCP">
     <inbound-endpoint ref="outer" />
     <outbound-endpoint ref = "clientEndpoint2"/>
     <logger message="2 : #[message.payload]" category="INFO"></logger>
     <test:component appendString=" Received" logMessageDetails="true"/>
    </flow>

    <flow name="testOutBoundTCP1">
     <inbound-endpoint ref="outer1" />
     <outbound-endpoint ref = "clientEndpoint"/>
     <logger message="1 : #[message.payload]" category="INFO"></logger>
     <test:component appendString=" Received" logMessageDetails="true" />
    </flow>


    <flow name="testComponent">
        <inbound-endpoint ref="clientEndpoint" />
        <test:component/>
    </flow>

我知道这有点晚,如果您的工作流是同步的,您可以在TCP端点中使用“请求-响应”。如果您的工作流需要是异步的,并且仍然需要使用相同的套接字,那么 可以通过在入站和出站tcp端点的tcp连接器中添加服务覆盖并从端点引用这些连接器来实现这一点

<tcp:connector name="TCP_Inbound" doc:name="TCP connector"
        clientSoTimeout="${client.so.timeout}" receiveBacklog="0"
        receiveBufferSize="0" sendBufferSize="0"
        serverSoTimeout="${server.so.timeout}" socketSoLinger="0"
        validateConnections="true" keepAlive="true">
        <reconnect-forever />
        <service-overrides messageReceiver="custom.TCPMessageReceiver" />

    </tcp:connector>
    <tcp:connector name="TCP_Outbound" doc:name="TCP connector"
        clientSoTimeout="${client.so.timeout}" receiveBacklog="0"
        receiveBufferSize="0" sendBufferSize="0"
        serverSoTimeout="${server.so.timeout}" socketSoLinger="0"
        validateConnections="true" keepAlive="true">
        <reconnect-forever />
        <service-overrides dispatcherFactory="custom.TcpDispatcherFactory" />

    </tcp:connector>
现在,您可以在muleflow中引用出站属性“ClientSocket”,并使用dispatcher将其传递回出站TCP。 在dispatcher部分中,必须为DispatcherFactory类提供服务覆盖,该类应扩展AbstractMessageDispatcher类并覆盖doDispatch方法,如下所示:

protected synchronized void doDispatch(MuleEvent event) throws Exception
    {     
        /* Get the socket shared from the inbound endpoint receiver class */    
        Socket socket = (Socket) event.getMessage().getSessionProperty("Socket");           
        dispatchToSocket(socket,event);
    }
protected synchronized void doDispatch(MuleEvent event) throws Exception
    {     
        /* Get the socket shared from the inbound endpoint receiver class */    
        Socket socket = (Socket) event.getMessage().getSessionProperty("Socket");           
        dispatchToSocket(socket,event);
    }