简体   繁体   English

Azure服务总线中继定期断开连接

[英]Azure Service Bus Relay Periodical Disconnection

I'm implementing a service host with the Azure Service Bus Relay. 我正在使用Azure Service Bus Relay实现服务主机。 The implementation is very straight forward: 实现非常简单:

Program.cs: Program.cs:

public class Program
{
    public static void Main(string[] args)
    {
        var random = new Random(Environment.TickCount);

        ServiceHost sh = new ServiceHost(typeof(ProblemSolver));

        var endpoint = sh.Description.Endpoints[0];
        var serviceRegistrySettings = new ServiceRegistrySettings(DiscoveryType.Public);
        endpoint.Behaviors.Add(serviceRegistrySettings);
        string randomText = random.Next().ToString();
        var listenUri = new Uri(endpoint.Address.Uri, randomText  + "/");
        endpoint.ListenUri = listenUri;

        sh.Open();
        Console.WriteLine("Hosted: " + randomText);
        Console.ReadLine();
        sh.Close();
    }
}

app.config: app.config:

<bindings>
  <netTcpRelayBinding>
    <binding name="default">
      <security mode="None" relayClientAuthenticationType="RelayAccessToken" />
    </binding>
  </netTcpRelayBinding>
</bindings>
<services>
  <service name="RelayPrototype.ProblemSolver">
    <endpoint contract="RelayServiceContract.IProblemSolver"
              binding="netTcpRelayBinding"
              bindingConfiguration="default"
              address="sb://test.servicebus.windows.net/problemSolver/"
              listenUri ="sb://test.servicebus.windows.net/problemSolver/"
              behaviorConfiguration="sbTokenProvider"/>
  </service>
</services>
<behaviors>
  <endpointBehaviors>
    <behavior name="sbTokenProvider">
      <transportClientEndpointBehavior>
        <tokenProvider>
          <sharedAccessSignature keyName="RootManageSharedAccessKey" key="[mykey]" />
        </tokenProvider>
      </transportClientEndpointBehavior>
    </behavior>
  </endpointBehaviors>
</behaviors>

The problem I'm facing is that once this is hosted, it is periodically disconnected after an interval of 2 minutes. 我面临的问题是,一旦托管,它将在2分钟的间隔后定期断开连接。

At this point, the TCP state of the service host changed from ESTABLISHED to CLOSE_WAIT. 此时,服务主机的TCP状态从ESTABLISHED变为CLOSE_WAIT。

Monitoring the TCP traffics, I found that the source ns-sb2-prod-sg3-001.cloudapp.net sent a packet that contains FIN flag, which i suspect might have caused the disconnection. 监视TCP流量,我发现源ns-sb2-prod-sg3-001.cloudapp.net发送了一个包含FIN标志的数据包,我怀疑这可能导致断开连接。

The service host will try again to establish the connection to Azure after some time. 一段时间后,服务主机将再次尝试建立与Azure的连接。 Once the connection is established again, the disconnection cycle continues. 再次建立连接后,断开连接继续。

However, this scenario only happen on my local machine. 但是,这种情况仅发生在我的本地计算机上。 The service is hosted fine on machines in other environment setup. 该服务可以在其他环境设置的计算机上很好地托管。

Could this be my implementation of the service host or is it something to do with the local network? 这可能是我对服务主机的实现,还是与本地网络有关?

Could this be my implementation of the service host or is it something to do with the local network? 这可能是我对服务主机的实现,还是与本地网络有关?

If you are seeing a FIN being sent means that the entity (client and server) is knowingly closing the connection. 如果您看到发送了FIN,则表示该实体(客户端和服务器)正在有意识地关闭连接。 And hence in the implementation of the application and not with the network. 因此在应用程序的实现中并没有与网络一起使用。 Transition to close-wait means that the FIN was received and acknowledged and the side which received the FIN needs to call close . 过渡到关闭等待意味着接收到并确认FIN,并且接收FIN的一方需要调用close

The above problem is solved. 解决了上述问题。 It appears that the relay service communicates with Azure using TCP port 5671. Our network firewall did not open up that port and therefore forced the established connection to close. 似乎中继服务使用TCP端口5671与Azure通信。我们的网络防火墙没有打开该端口,因此强制建立的连接关闭。 Hence, the TCP port 5671 should be opened for communication with Azure. 因此,应打开TCP端口5671以与Azure进行通信。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM