Exemplo n.º 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);
Exemplo n.º 2
0
        /// <summary>
        /// 设置缓存
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <returns></returns>
        public T GetCache <T>(string key) where T : class
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentNullException(nameof(key));
            }

            var value = CsRedisFactory.GetDatabase().Get <byte[]>(key);

            if (value == null)
            {
                return(default(T));
            }

            return(_serialize.Deserializes <T>(value));
        }