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