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);
            }
        }
Example #2
0
 private async Task HandleUndoLogDelete(UndoLogDeleteRequest undoLogDeleteRequest)
 {
     try
     {
         await handler.OnRequest(undoLogDeleteRequest, null);
     }
     catch (Exception ex)
     {
         Logger().LogError(ex, "Failed to delete undo log by undoLogDeleteRequest on" + undoLogDeleteRequest.ResourceId);
     }
 }
        private async Task HandleBranchCommit(RpcMessage request, string serverAddress, BranchCommitRequest branchCommitRequest)
        {
            BranchCommitResponse resultMessage = (BranchCommitResponse)(await handler.OnRequest(branchCommitRequest, null));

            if (Logger().IsEnabled(LogLevel.Debug))
            {
                Logger().LogDebug($"branch commit result:{resultMessage}");
            }
            try
            {
                await this.remotingClient.SendAsyncResponse(serverAddress, request, resultMessage);
            }
            catch (Exception throwable)
            {
                Logger().LogError(throwable, $"branch commit error: {throwable.Message}");
            }
        }