コード例 #1
0
ファイル: AmqpConfigCache.cs プロジェクト: alasai/Hzdtf.AMQP
        /// <summary>
        /// 读取
        /// </summary>
        /// <returns>数据</returns>
        public AmqpConfigInfo Reader()
        {
            if (configInfo == null)
            {
                lock (syncConfigInfo)
                {
                    configInfo = protoAmqpConfigReader.Reader();
                }
            }

            return(configInfo);
        }
コード例 #2
0
        /// <summary>
        /// 调用
        /// </summary>
        /// <param name="method">方法</param>
        /// <param name="message">消息</param>
        /// <returns>返回数据</returns>
        public virtual object Call(MethodInfo method, object message)
        {
            var assemblyName = method.DeclaringType.Assembly.GetName().Name;
            var configInfo   = amqpConfigReader.Reader();

            if (configInfo == null)
            {
                throw new Exception("找不到AMQP配置信息");
            }

            var assemblyQueue = configInfo.ToRpcClientAssemblyQueue(assemblyName);

            if (assemblyQueue == null)
            {
                throw new Exception($"找不到程序集[{assemblyName}]的RPC客户端配置信息");
            }

            var byteSeri = GetByteSerialization(assemblyQueue.RpcClientAssembly.DataType);
            var byteData = byteSeri.Serialize(message);

            IRpcClient rpcClient = GetAvailableRpcClient(assemblyQueue);
            var        reData    = rpcClient.Call(byteData);

            // 如果返回值是空或者类型是void,则直接返回null
            if (reData.IsNullOrLength0() || method.ReturnType.IsTypeVoid())
            {
                return(null);
            }
            else
            {
                Type targetType = method.GetReturnValueType();
                if (targetType == null)
                {
                    return(null);
                }

                return(byteSeri.Deserialize(reData, targetType));
            }
        }