public async Task EditServiceToken(AddressModel address) { var routes = await GetService <IServiceRouteManager>().GetRoutesAsync(address.ToString()); routes = routes.ToList(); List <ServiceRoute> serviceRoutes = new List <ServiceRoute>(); routes.ToList().ForEach(route => { var addresses = new List <AddressModel>(); route.Address.ToList().ForEach(addressModel => { if (addressModel.ToString() == address.ToString()) { addressModel.Token = address.Token; } addresses.Add(addressModel); }); serviceRoutes.Add(new ServiceRoute() { ServiceDescriptor = route.ServiceDescriptor, Address = addresses }); }); await GetService <IServiceRouteManager>().ClearAsync(); await GetService <IServiceRouteManager>().SetRoutesAsync(serviceRoutes); }
public async Task <RemoteInvokeResultMessage> InvokeAsync(RemoteInvokeContext context, int requestTimeout) { var invokeMessage = context.InvokeMessage; AddressModel address = null; try { address = await ResolverAddress(context, context.Item); var endPoint = address.CreateEndPoint(); if (_logger.IsEnabled(LogLevel.Information)) { _logger.LogInformation($"使用地址:'{endPoint}'进行调用。"); } var client = await _transportClientFactory.CreateClientAsync(endPoint); RpcContext.GetContext().SetAttachment("RemoteAddress", address.ToString()); using (var cts = new CancellationTokenSource()) { var rpcResult = await client.SendAsync(invokeMessage, cts.Token).WithCancellation(cts, requestTimeout); return(rpcResult); } } catch (CommunicationException ex) { if (address != null) { _logger.LogError($"使用地址:'{address.ToString()}'调用服务{context.InvokeMessage.ServiceId}失败,原因:{ex.Message}"); await _healthCheckService.MarkFailure(address); } throw; } catch (TimeoutException ex) { if (address != null) { _logger.LogError($"使用地址:'{address.ToString()}'调用服务{context.InvokeMessage.ServiceId}超时,原因:{ex.Message}"); //await _healthCheckService.MarkTimeout(address, invokeMessage.ServiceId); } throw; } catch (Exception exception) { _logger.LogError(exception, $"发起请求中发生了错误,服务Id:{invokeMessage.ServiceId}。错误信息:{exception.Message}"); throw; } }
/// <summary> /// 判断一个地址是否健康。 /// </summary> /// <param name="address">地址模型。</param> /// <returns>健康返回true,否则返回false。</returns> public ValueTask <bool> IsHealth(AddressModel address) { var key = address.ToString(); MonitorEntry entry; return(!_dictionary.TryGetValue(key, out entry) ? new ValueTask <bool>(Check(address, _timeout)) : new ValueTask <bool>(entry.Health)); }
public async Task <RemoteInvokeResultMessage> InvokeAsync(RemoteInvokeContext context, int requestTimeout) { var invokeMessage = context.InvokeMessage; AddressModel address = null; var vt = ResolverAddress(context, context.Item); address = vt.IsCompletedSuccessfully ? vt.Result : await vt; try { var endPoint = address.CreateEndPoint(); if (_logger.IsEnabled(LogLevel.Debug)) { _logger.LogDebug($"使用地址:'{endPoint}'进行调用。"); } var task = _transportClientFactory.CreateClientAsync(endPoint); var client = task.IsCompletedSuccessfully ? task.Result : await task; RpcContext.GetContext().SetAttachment("RemoteAddress", address.ToString()); using (var cts = new CancellationTokenSource()) { return(await client.SendAsync(invokeMessage, cts.Token).WithCancellation(cts, requestTimeout)); } } catch (CommunicationException) { await _healthCheckService.MarkFailure(address); throw; } catch (Exception exception) { _logger.LogError(exception, $"发起请求中发生了错误,服务Id:{invokeMessage.ServiceId}。错误信息:{exception.Message}"); throw; } }
/// <summary> /// 标记一个地址为失败的。 /// </summary> /// <param name="address">地址模型。</param> /// <returns>一个任务。</returns> public Task MarkFailure(AddressModel address) { return(Task.Run(() => { var key = address.ToString(); var entry = _dictionary.GetOrAdd(key, k => new MonitorEntry(address, false)); entry.Health = false; })); }
/// <summary> /// 判断一个地址是否健康。 /// </summary> /// <param name="address">地址模型。</param> /// <returns>健康返回true,否则返回false。</returns> public Task <bool> IsHealth(AddressModel address) { return(Task.Run(() => { var key = address.ToString(); MonitorEntry entry; return !_dictionary.TryGetValue(key, out entry) ? Check(address): entry.Health; })); }
public AddrValidationResponseModel ValidateAddress(AddressModel addr) { _log.Debug("START ValidateAddress"); _log.Debug(addr.ToString()); QASearch search = TranslateAddrValidationModel.MapAddressToQasSearch(addr); QASearchResult result = _proxy.ValidateAddress(search); AddrValidationResponseModel response = TranslateAddrValidationModel.MapGetResponseToModel(result); _log.Debug("END ValidateAddress"); return(response); }
/// <summary> /// 监控一个地址。 /// </summary> /// <param name="address">地址模型。</param> /// <returns>一个任务。</returns> public void Monitor(AddressModel address) { _dictionary.GetOrAdd(address.ToString(), k => new MonitorEntry(address)); }
/// <summary> /// 监控一个地址 /// </summary> /// <param name="address">地址模型</param> /// <returns>一个任务</returns> public Task Monitor(AddressModel address) { return(Task.Run(() => { _dictionary.GetOrAdd(address.ToString(), k => new MonitorEntry(address)); })); }