コード例 #1
0
ファイル: Program.cs プロジェクト: zengcooper/MyOcelot
        /// <summary>
        ///
        /// </summary>
        static void PubSubServer()
        {
            Console.Title = "发布服务器";
            string strChannel = "channel-lcq";

            using (PooledRedisClientManager pooledRedisClientManager = new PooledRedisClientManager("localhost"))
                using (RedisPubSubServer redisPubSubServer = (RedisPubSubServer)pooledRedisClientManager.CreatePubSubServer(channel: strChannel))
                {
                    redisPubSubServer.OnStart         += () => { Console.WriteLine("PubSubServer start channel:{0} ", strChannel); };
                    redisPubSubServer.OnStop          += () => { Console.WriteLine("PubSubServer stop channel:{0} ", strChannel); };
                    redisPubSubServer.OnMessage       += (e, m) => { Console.WriteLine("RedisPubSubServer OnMessage:{0} {1}", e, m); };
                    redisPubSubServer.OnHeartbeatSent += () => { Console.WriteLine("OnHeartbeatSent"); };
                    redisPubSubServer.Start();//启动发布服务

                    Console.WriteLine("请输入消息内容...");
                    while (true)
                    {
                        string message = Console.ReadLine();
                        PublishMessage(message);//发布消息
                    }
                    Console.ReadLine();
                }
        }