Ejemplo n.º 1
0
        private async Task OnRequestMessage(IChannelHandlerContext ctx, RpcMessage rpcMessage)
        {
            object     message    = rpcMessage.Body;
            RpcContext rpcContext = ChannelManager.GetContextFromIdentified(ctx.Channel);

            if (Logger().IsEnabled(LogLevel.Debug))
            {
                Logger().LogDebug($"server received:{message},clientIp:{NetUtil.ToIpAddress(ctx.Channel.RemoteAddress)},vgroup:{rpcContext.TransactionServiceGroup}");
            }
            else
            {
                try
                {
                    BatchLogHandler.INSTANCE.LogQueue.Add($"{message},clientIp:{NetUtil.ToIpAddress(ctx.Channel.RemoteAddress)},vgroup:{rpcContext.TransactionServiceGroup}");
                }
                catch (Exception e)
                {
                    Logger().LogError(e, $"put message to logQueue error: {e.Message}");
                }
            }
            if (!(message is AbstractMessage))
            {
                return;
            }
            if (message is MergedWarpMessage mergedWarpMessage)
            {
                AbstractResultMessage[] results = new AbstractResultMessage[mergedWarpMessage.msgs.Count];
                for (int i = 0; i < results.Length; i++)
                {
                    AbstractMessage subMessage = mergedWarpMessage.msgs[i];
                    results[i] = await _transactionMessageHandler.OnRequest(subMessage, rpcContext);
                }
                MergeResultMessage resultMessage = new ()
                {
                    Msgs = results
                };
                await _remotingServer.SendAsyncResponse(rpcMessage, ctx.Channel, resultMessage);
            }
            else
            {
                // the single send request message
                var msg = (AbstractMessage)message;
                AbstractResultMessage result = await _transactionMessageHandler.OnRequest(msg, rpcContext);

                await _remotingServer.SendAsyncResponse(rpcMessage, ctx.Channel, result);
            }
        }
Ejemplo n.º 2
0
 public virtual async Task Process(IChannelHandlerContext ctx, RpcMessage rpcMessage)
 {
     try
     {
         await _remotingServer.SendAsyncResponse(rpcMessage, ctx.Channel, HeartbeatMessage.PONG);
     }
     catch (Exception throwable)
     {
         Logger().LogError(throwable, $"send response error: {throwable.Message}");
     }
     if (Logger().IsEnabled(LogLevel.Debug))
     {
         Logger().LogDebug($"received PING from {ctx.Channel.RemoteAddress}");
     }
 }
Ejemplo n.º 3
0
        private async Task OnRegTmMessage(IChannelHandlerContext ctx, RpcMessage rpcMessage)
        {
            var    message   = (RegisterTMRequest)rpcMessage.Body;
            string ipAndPort = NetUtil.ToStringAddress(ctx.Channel.RemoteAddress);

            Protocol.Version.PutChannelVersion(ctx.Channel, message.Version);
            bool   isSuccess = false;
            string errorInfo = string.Empty;

            try
            {
                if (checkAuthHandler == null || await checkAuthHandler.RegTransactionManagerCheckAuth(message))
                {
                    ChannelManager.RegisterTMChannel(message, ctx.Channel);
                    Protocol.Version.PutChannelVersion(ctx.Channel, message.Version);
                    isSuccess = true;
                    if (Logger().IsEnabled(LogLevel.Debug))
                    {
                        Logger().LogDebug($"checkAuth for client:{ipAndPort},vgroup:{message.TransactionServiceGroup},applicationId:{message.ApplicationId}");
                    }
                }
            }
            catch (Exception exx)
            {
                isSuccess = false;
                errorInfo = exx.Message;
                Logger().LogError(exx, $"TM register fail, error message:{errorInfo}");
            }
            var response = new RegisterTMResponse(isSuccess);

            if (!string.IsNullOrWhiteSpace(errorInfo))
            {
                response.Msg = errorInfo;
            }
            await remotingServer.SendAsyncResponse(rpcMessage, ctx.Channel, response);

            if (Logger().IsEnabled(LogLevel.Debug))
            {
                Logger().LogInformation($"TM register success,message:{message},channel:{ctx.Channel},client version:{message.Version}");
            }
        }