1 static void Main(string[
args)
2 {
3 var messagesReceived = 0;
4 var maxMessage = 5;
5 var channelName = \"幸福框架\";
6
7 using (var redisConsumer = new RedisClient())
8 {
9 using (var subscription = redisConsumer.CreateSubscription())10 {11 subscription.OnSubscribe = channel =>12 {13 Console.WriteLine(String.Format(\"订阅频道:'{0'\" channel));14 ;15 subscription.OnUnSubscribe = channel =>16 {17 Console.WriteLine(String.Format(\"取消订阅频道:'{0'\" channel));18 ;19 subscription.OnMessage = (channel msg) =>20 {21 Console.WriteLine(String.Format(\"从频道:'{0'获取了消息:'{1'\" channel msg));22 23 if (++messagesReceived == maxMessage)24 {25 subscription.UnSubscribeFromAllChannels();26 27 ;28 29 ThreadPool.QueueUserWorkItem(x =>30 {31 Thread.Sleep(200);32 Console.WriteLine(\"开始发布消息\");33 34 using (var redisPublisher = new RedisClient())35 {36 for (var i = 1; i <= 5; i++)37 {38 var message = \"段光伟:\" + DateTime.Now;39 Console.WriteLine(String.Format(\"发布消息:'{0'到频道:'{1'\" message channelName));40 redisPublisher.PublishMessage(channelName message);41 42 43 );44 45 Console.WriteLine(String.Format(\"开始监听频道:'{0'\" channelName));46 subscription.SubscribeToChannels(channelName); //blocking47 48 49
- 京东云发布碳中和全景图 为企业提供能耗管理服务|碳中和在路
- 电子商务|网友:芝麻信用分700+花呗被关闭,问题到底是出在哪里呢?
- Apple Watch|重要功能解禁!淘宝正在起变化
- 笔记本电脑|关于魅族,黄章在15年讲过这样一段话
- 涨停|如何看待TikTok(抖音)在国外火爆?
- 佛山企业污水排水口PH电导率在线监测</...|佛山企业污水排水口PH电导率在线监测有哪些因子?来看看
- |现在购买千元机的人,为什么越来越多了?原来并不是变穷了
- 四川多地出现神秘巨响!玻璃都在抖动,可引发巨响的原因有哪些?
- 研发效能的坑:“效率至上”还是“以人为本”?|QCon
- 动视暴雪取消疫苗接种要求 旨在使员工快速回归岗位