Exemple #1
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="path"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public async Task <T> SendMessage <T>(string channelKey, IPEndPoint endPoint, string flowControlCfgKey, ServiceConfigureInfo configure, string key, string path, object message) where T : class
        {
            T result = default;

            if (Channels.TryGetValue(channelKey, out var _channel))
            {
                try
                {
                    result = await _flowControlCenter.ExcuteAsync(key, endPoint, flowControlCfgKey, configure, async() =>
                    {
                        var taskId      = Guid.NewGuid();
                        var sendMessage = new RpcGlobalMessageBase <object>
                        {
                            CustomerIp = _customerInfo.Ip,
                            TaskId     = taskId,
                            Path       = path,
                            Message    = message is string?_serialize.Deserializes <object>(_serialize.SerializesJsonString((string)message)) : message
                        };
                        sendMessage.Sign(GlobalCommon.SHA256Encrypt(taskId + OxygenSetting.SignKey));
                        var resultTask = RegisterResultCallbackAsync(taskId);
                        await _channel.WriteAndFlushAsync(sendMessage);
                        var resultBt = await resultTask;
                        if (resultBt != null && resultBt.Any())
                        {
                            return(_serialize.Deserializes <T>(resultBt));
                        }
                        return(default);
Exemple #2
0
 protected override void Encode(IChannelHandlerContext context, RpcGlobalMessageBase <T> message, IByteBuffer output)
 {
     output.WriteBytes(_serialize.Serializes(message));
 }
Exemple #3
0
 /// <summary>
 /// 消息分发处理
 /// </summary>
 /// <param name="message"></param>
 /// <returns></returns>
 public async Task <RpcGlobalMessageBase <object> > Invoke(RpcGlobalMessageBase <object> message)
 {
     if (message == null)
     {
         _logger.LogError($"订阅者消息分发不能为空消息");
         return(default);