0
votes

I would like to route traffic through Mule for a MSSQL database. The database runs on the url "internalserverurl" on port 1433.

Mule shall act as a TCP-Server/Proxy and simply re-route the incoming TCP traffic on 1433 to the address at "internalserverurl" on port 1433, handle the response and return it back.

Example Code:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:tcp="http://www.mulesoft.org/schema/mule/tcp" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.3.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/tcp http://www.mulesoft.org/schema/mule/tcp/current/mule-tcp.xsd 
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd 
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd ">
    <tcp:connector name="TCP_C_L" validateConnections="false" receiveBufferSize="102400" sendBufferSize="102400" doc:name="TCP connector">
    <tcp:streaming-protocol/>
    </tcp:connector>
    <tcp:connector name="TCP_C_81" validateConnections="false" receiveBufferSize="102400" sendBufferSize="102400" doc:name="TCP connector">
    <tcp:streaming-protocol/>
    </tcp:connector>
    <flow name="IncomingEndpoint" doc:name="IncomingEndpoint">
        <tcp:inbound-endpoint exchange-pattern="request-response" responseTimeout="10000" doc:name="TCP-Proxy" host="localhost" port="1433" connector-ref="TCP_C_L" />
        <tcp:outbound-endpoint exchange-pattern="request-response" host="internalserverurl" port="1433" responseTimeout="10000" doc:name="TCP" connector-ref="TCP_C_81" />
    </flow>
</mule>

If I run this code the mule application starts fine, I can also connect via JDBC to the port 1433 thorugh localhost. But the DB connection is not successful. Mule will throw an Socket Exception:

Exception stack is:
1. Socket is closed (java.net.SocketException)
  java.net.Socket:864 (null)
2. Failed to route event via endpoint: DefaultOutboundEndpoint{endpointUri=tcp://internalserverurl:1433, connector=TcpConnector
{
  name=TCP_C_81
  lifecycle=start
  this=7ffba3f9
  numberOfConcurrentTransactedReceivers=4
  createMultipleTransactedReceivers=true
  connected=true
  supportedProtocols=[tcp]
  serviceOverrides=<none>
}
,  name='endpoint.tcp.internalserverurl.1433', mep=REQUEST_RESPONSE, properties={}, transactionConfig=Transaction{factory=null, action=INDIFFERENT, timeout=0}, deleteUnacceptedMessages=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8, disableTransportTransformer=false}. Message payload is of type: TcpMessageReceiver$TcpWorker$1 (org.mule.api.transport.DispatchException)
  org.mule.transport.AbstractMessageDispatcher:109 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transport/DispatchException.html)

Why is there a Socket timeout ? When I simply do the JDBC connection directly (from the same machine that runs this Mule application) the connection is fine.

If I use

<tcp:direct-protocol payloadOnly="true"/>

instead of

<tcp:streaming-protocol/>

Then I can see the TCP packet incoming on the MSSQL server, but the SQL server will log a message like: 08/18/2014 12:16:41,Logon,Unknown,The login packet used to open the connection is structurally invalid; the connection has been closed. Please contact the vendor of the client library. [CLIENT: 10.2.60.169] 08/18/2014 12:16:41,Logon,Unknown,Error: 17832 Severity: 20 State: 2.

Thanks, Sebastian

1
What are you trying to achieve? If you just want a barebone TCP level proxy, better use something way simpler than Mule. If you intend to add extra behaviour to this bridge, then OK, this could make sense...David Dossot

1 Answers

1
votes

Take a look at the TCP Connector protocol table: http://www.mulesoft.org/documentation/display/current/TCP+Transport+Reference#TCPTransportReference-ProtocolTables

The streaming-protocol has this Read property:

All bytes sent until the socket is closed

If the client doesn't disconnect, Mule will keep reading for ever with this protocol.

Keep in mind Mule is a message-oriented middleware: if you want your TCP bridge to work, you need to use a protocol that is compatible with the MSSQL protocol.

This means that the protocol must recognize whatever character or sequence of characters is used by the SQL client to mark an end of request, so Mule can cut a message out of the bytes received so far then route it down the flow.

It's possible that none of the provided protocols allow this, meaning that you would have to create your own protocol...