【问题标题】:how to set a timeout for a service remoting call in service fabric如何为服务结构中的服务远程调用设置超时
【发布时间】:2017-11-15 20:28:42
【问题描述】:

我有一个服务结构服务,我从另一个服务这样调用它:

var checkerProxy = new ServiceProxyFactory<ICheck>(uri);
var checker = checkerProxy.CreateSingletonServiceProxy();
success = await checker.CheckMe();

如果通话时间超过超时,我想中止通话。

如何在服务结构中为远程调用设置超时?

编辑 1:注意我可以这样做:

success = checker.CheckMe().Wait(TimeSpan.FromSeconds(10));

但这不会中止远程调用,而只会在超时时停止等待任务完成并且我没有返回值。

【问题讨论】:

    标签: c# timeout azure-service-fabric remoting


    【解决方案1】:

    您可以使用FabricTransportRemotingSettings 在代理中设置超时:

                FabricTransportRemotingSettings settings = new FabricTransportRemotingSettings();
                settings.OperationTimeout = TimeSpan.FromMinutes(5);
    
                return new ServiceProxyFactory(
                    (h) =>
                    {
                        return new FabricTransportServiceRemotingClientFactory(settings);
                    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-03-22
      • 2021-10-13
      • 2018-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多