RedisMqServer中的示例显示了如何订阅和取消订阅消息,例如:
using (var subscription = redisClient.CreateSubscription()){ subscription.onUnSubscribe = channel => Log.Debug("OnUnSubscribe: " + channel); subscription.onMessage = (channel, msg) => { if (msg == "STOP") { Log.Debug("Stop Command Issued"); Log.Debug("Unsubscribing from all Channels..."); subscription.UnSubscribeFromAllChannels(); //Unblocks thread. } }; subscription.SubscribeToChannels(QueueNames.TopicIn); //blocks thread}
它使用自定义控制消息来取消阻止后台线程,并取消订阅 OnMessage 处理程序的所有通道的订阅。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)