private async ValueTask <AddressModel> ResolverAddress(RemoteInvokeContext context, string item) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.InvokeMessage == null) { throw new ArgumentNullException(nameof(context.InvokeMessage)); } if (string.IsNullOrEmpty(context.InvokeMessage.ServiceId)) { throw new ArgumentException("服务Id不能为空。", nameof(context.InvokeMessage.ServiceId)); } var invokeMessage = context.InvokeMessage; var vt = _addressResolver.Resolver(invokeMessage.ServiceId, item); var address = vt.IsCompletedSuccessfully ? vt.Result : await vt; if (address == null) { throw new CPlatformException($"无法解析服务Id:{invokeMessage.ServiceId}的地址信息。"); } return(address); }
private async ValueTask <AddressModel> ResolverAddress(RemoteInvokeContext context, int hashCode) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.InvokeMessage == null) { throw new ArgumentNullException(nameof(context.InvokeMessage)); } if (string.IsNullOrEmpty(context.InvokeMessage.ServiceId)) { throw new ArgumentException("服务Id不能为空。", nameof(context.InvokeMessage.ServiceId)); } var invokeMessage = context.InvokeMessage; var address = await _addressResolver.Resolver(invokeMessage.ServiceId, hashCode); if (address == null) { throw new CPlatformException($"无法解析服务Id:{invokeMessage.ServiceId}的地址信息。"); } return(address); }
private ConsistentHashNode GetRedisNode(string item) { if (addressResolver != null) { return(addressResolver.Resolver($"{KeySuffix}.{CacheTargetType.Redis.ToString()}", item).Result); } else { ConsistentHash <ConsistentHashNode> hash; _context.Value.dicHash.TryGetValue(CacheTargetType.Redis.ToString(), out hash); return(hash != null?hash.GetItemNode(item) : default(ConsistentHashNode)); } }
public async Task <RemoteInvokeResultMessage> InvokeAsync(RemoteInvokeContext context, CancellationToken cancellationToken) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.InvokeMessage == null) { throw new ArgumentNullException(nameof(context.InvokeMessage)); } if (string.IsNullOrEmpty(context.InvokeMessage.ServiceId)) { throw new ArgumentException("服务Id不能为空", nameof(context.InvokeMessage.ServiceId)); } var invokeMessage = context.InvokeMessage; var address = await _addressResolver.Resolver(invokeMessage.ServiceId); if (address == null) { throw new RpcException($"无法解析服务Id:{invokeMessage.ServiceId}的地址信息"); } try { var endPoint = address.CreateEndPoint(); if (_logger.IsEnabled(LogLevel.Debug)) { _logger.LogDebug($"使用地址:'{endPoint}'进行调用"); } var client = _transportClientFactory.CreateClient(endPoint); return(await client.SendAsync(context.InvokeMessage)); } catch (RpcCommunicationException) { await _healthCheckService.MarkFailure(address); throw; } catch (Exception exception) { _logger.LogError($"发起请求中发生了错误,服务Id:{invokeMessage.ServiceId}", exception); throw; } }
public async Task <RemoteInvokeResultMessage> InvokeAsync(RemoteInvokeContext context, CancellationToken cancellationToken) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.InvokeMessage == null) { throw new ArgumentNullException(nameof(context.InvokeMessage)); } if (string.IsNullOrEmpty(context.InvokeMessage.ServiceId)) { throw new ArgumentException("服务Id不能为空。", nameof(context.InvokeMessage.ServiceId)); } var invokeMessage = context.InvokeMessage; var address = await _addressResolver.Resolver(invokeMessage.ServiceId); if (address == null) { throw new RpcException($"无法解析服务Id:{invokeMessage.ServiceId}的地址信息。"); } try { var client = _transportClientFactory.CreateClient(address.CreateEndPoint()); var message = context.InvokeMessage; var resultMessage = client.ReceiveAsync(message.Id); await client.SendAsync(message); return(await resultMessage); } catch (Exception exception) { _logger.Fatal($"发起请求中发生了错误,服务Id:{invokeMessage.ServiceId}。", exception); throw; } }