Ejemplo n.º 1
0
        /// <summary>
        /// 业务调用RPC服务端
        /// </summary>
        private static void BusinessCallRpcServer()
        {
            // 创建Rabbit连接和Rpc服务端
            var conn = new RabbitConnection();

            conn.OpenByHostId("host1");
            var rpcServer = conn.CreateRpcServer("RpcExchange", "RpcQueue");

            // 创建Rpc监听服务
            var listen = new RpcServerListen();

            // 设置接口映射配置文件
            var mapImplCache = new InterfaceMapImplCache();

            mapImplCache.Set(new DictionaryJson("Config/interfaceAssemblyMapImplAssemblyConfig.json"));

            // 将映射赋值到监听中
            listen.InterfaceMapImpl = mapImplCache;

            // 将RPC服务设置到监听中
            listen.RpcServer          = rpcServer;
            listen.BytesSerialization = new MessagePackBytesSerialization();

            // 注册错误事件
            listen.ReceivingError += Listen_ReceivingError;

            // 开始监听
            Console.WriteLine("监听Rpc服务的请求:");
            listen.ListenAsync();
        }
        static void Main()
        {
            var mapImplCache = new InterfaceMapImplCache();

            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Main());
        }