예제 #1
0
        private async Task <RemoteInvokeResultMessage> RetryExectueAsync(Context ctx, IAddressResolver resolver, string serviceId, TransportMessage transportMessage)
        {
            var address = await resolver.ResolverAsync(serviceId);

            ctx["address"] = address;
            var client = _clientFactory.CreateClientAsync(address.CreateEndPoint());

            return(await client.SendAsync(transportMessage));
        }
        public async Task <RemoteInvokeResultMessage> InvokeAsync(RemoteInvokeContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (context.ServiceId == null)
            {
                throw new ArgumentNullException("serviceId");
            }

            RemoteInvokeMessage message = new RemoteInvokeMessage()
            {
                ServiceId  = context.ServiceId,
                Parameters = context.Parameters
            };
            var transportMessage = TransportMessage.CreateInvokeMessage(message);

            //todo: 添加断路器(polly)

            var address = await _addressResolver.ResolverAsync(context.ServiceId);

            var client = _clientFactory.CreateClientAsync(address.CreateEndPoint());

            try
            {
                return(await client.SendAsync(transportMessage));
            }
            catch (Exception e)
            {
                await _healthCheckService.MarkFailure(address);

                _logger.LogError("发送远程消息错误", e);
                throw e;
            }
        }