/// <summary> /// 订阅 Redis的消息队列, 实现消息队列对爬虫的控制 /// </summary> /// <param name="spider">爬虫</param> protected void RegisterControl(ISpider spider) { if (RedisConnection.Default == null) { return; } try { RedisConnection.Default.Subscriber.Subscribe($"{spider.Identity}", (c, m) => { switch (m) { case "PAUSE": { spider.Pause(); break; } case "CONTINUE": { spider.Continue(); break; } case "RUNASYNC": { spider.RunAsync(); break; } case "EXIT": { spider.Exit(); break; } } }); } catch (Exception e) { Logger.LogError($"Register control failed:{e}"); } }