Sql server 通过TCP连接器连接时超时

Sql server 通过TCP连接器连接时超时,sql-server,sockets,jdbc,tcp,mule,Sql Server,Sockets,Jdbc,Tcp,Mule,我想通过Mule为MSSQL数据库路由流量。数据库在端口1433上的url“internalserverurl”上运行 Mule应充当TCP服务器/代理,简单地将1433上的传入TCP流量重新路由到端口1433上“internalserverurl”的地址,处理响应并返回 示例代码: <?xml version="1.0" encoding="UTF-8"?> <mule xmlns:tcp="http://www.mulesoft.org/schema/mule/tcp"

我想通过Mule为MSSQL数据库路由流量。数据库在端口1433上的url“internalserverurl”上运行

Mule应充当TCP服务器/代理,简单地将1433上的传入TCP流量重新路由到端口1433上“internalserverurl”的地址,处理响应并返回

示例代码:

<?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>

如果我运行这段代码,mule应用程序启动正常,我还可以通过JDBC连接到端口1433 thorugh localhost。 但是数据库连接不成功。 Mule将抛出套接字异常:

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)
异常堆栈是:
1.套接字已关闭(java.net.SocketException)
java.net.Socket:864(空)
2.未能通过端点路由事件:DefaultOutboundEndpoint{endpointUri=tcp://internalserverurl:1433,连接器=TCP连接器
{
名称=TCP_C_81
生命周期=开始
这=7ffba3f9
ConcurrentTransacticedReceiver的数量=4
CreateMultipleTransactedReceiver=true
已连接=真
supportedProtocols=[tcp]
服务覆盖=
}
,name='endpoint.tcp.internalserverurl.1433',mep=REQUEST\u RESPONSE,properties={},transactionConfig=Transaction{factory=null,action=interference,timeout=0},deleteUnceptedMessages=false,initialState=started,responseTimeout=10000,endpointEncoding=UTF-8,disableTransportTransformer=false}。消息负载的类型为: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)
为什么会有套接字超时?当我直接(从运行这个Mule应用程序的同一台机器)进行JDBC连接时,连接很好

如果我使用

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

而不是

<tcp:streaming-protocol/>

然后我可以看到MSSQL服务器上传入的TCP数据包,但SQL服务器将记录一条消息,如: 2014年8月18日12:16:41,登录,未知,用于打开连接的登录数据包在结构上无效;连接已关闭。请联系客户端库的供应商。[客户:10.2.60.169] 2014年8月18日12:16:41,登录,未知,错误:17832严重性:20状态:2

谢谢,
Sebastian查看TCP连接器协议表:

流媒体协议
具有以下读取属性:

在套接字关闭之前发送的所有字节

如果客户端没有断开连接,Mule将使用此协议永远保持读取

请记住,Mule是一个面向消息的中间件:如果您希望TCP网桥工作,则需要使用与MSSQL协议兼容的协议

这意味着协议必须识别SQL客户端用于标记请求结束的任何字符或字符序列,以便Mule可以从迄今为止接收到的字节中剪切消息,然后将其沿流路由


可能提供的协议都不允许这样做,这意味着您必须创建自己的协议…

您想要实现什么?如果您只是想要一个基本的TCP级别代理,最好使用比Mule更简单的方法。如果你想在这座桥上增加额外的行为,那么好吧,这是有道理的……听起来不错,但不幸的是,这不是我希望的答案:)