Пример #1
0
        /// <summary>
        /// 广播消息
        /// </summary>
        /// <param name="request">请求消息</param>
        /// <param name="requestContext">请求目标集合</param>
        /// <returns>响应消息集合</returns>
        public ICollection <RpcTransportMessageResponse> BroadcastMessage(
            RpcTransportMessageRequest request, IEnumerable <IRpcMessageSenderContext> requestContext, out ICollection <RpcTransportErrorResponse> errorResponse)
        {
            List <RpcTransportMessageResponse> allResultMessage = new List <RpcTransportMessageResponse>();
            List <RpcTransportErrorResponse>   allErrorResponse = new List <RpcTransportErrorResponse>();

            foreach (var ctxGrp in requestContext.GroupBy(ctx => ctx.RpcType))
            {
                IRpcServer rpcServer = rpcServers.FirstOrDefault(server => server.RpcType == ctxGrp.Key);
                IList <IRpcMessageSenderContext> requestContextGroup = ctxGrp.ToList();

                ICollection <RpcTransportErrorResponse>   errorMessageGroup  = null;
                ICollection <RpcTransportMessageResponse> resultMessageGroup = rpcServer.BroadcastMessage(request, requestContextGroup, out errorMessageGroup);

                allResultMessage.AddRange(resultMessageGroup);
                if (errorMessageGroup != null)
                {
                    allErrorResponse.AddRange(errorMessageGroup);
                }
            }

            errorResponse = allErrorResponse;
            return(allResultMessage);
        }
Пример #2
0
        /// <summary>
        /// 发送RPC消息
        /// </summary>
        /// <param name="serviceName">服务名称</param>
        /// <param name="request">请求消息</param>
        /// <returns>响应消息</returns>
        public RpcTransportMessageResponse SendMessage(RpcTransportMessageRequest request, IRpcMessageSenderContext rpcContext)
        {
            IRpcServer rpcServer = rpcServers.FirstOrDefault(server => server.RpcType == rpcContext.RpcType);

            return(rpcServer.SendMessage(request, rpcContext));
        }