public void Stop(string exchangeName) { SubThread thd = this[exchangeName]; if (thd != null) { try { ZeroLog.LogInfo("consumer stop...."); thd.TogglePause(true); //TODO //线程销毁和重入 //thd.Interrupt(); } catch (Exception ex) { ZeroLog.LogInfo("consumer stop...." + ex.Message); } finally { } } }
public void Start() { ZeroLog.LogInfo("thread start...."); if (this.thread.ThreadState != ThreadState.Running) { this.thread.Start(); } }
public void Start(string exchangeName) { ZeroLog.LogInfo("consumer start...." + exchangeName); SubThread thd = this[exchangeName]; thd.TogglePause(false); thd.Start(); }
public override void Bind(ZmqSocket socket, ZeroRoute config) { ZeroLog.LogInfo("push bind...."); foreach (var endPoint in config.ConnectEndPoints()) { socket.Connect(endPoint); ZeroLog.LogInfo("push bind...."); } }
public void Abort() { try { ZeroLog.LogInfo("thread abort...."); this.thread.Abort(); } finally { } }
public void Close(string exchangeName) { ZeroLog.LogInfo("producer close...."); ZmqContext context = contexts[exchangeName]; ZmqSocket socket = sockets[exchangeName]; ZmqMonitor monitor = monitors[exchangeName]; monitor.Dispose(); socket.Dispose(); context.Dispose(); contexts.Remove(exchangeName); sockets.Remove(exchangeName); monitors.Remove(exchangeName); }
public override void Run() { ZeroLog.LogInfo("thread run...."); using (var context = ZmqContext.Create()) { using (ZmqSocket socket = context.CreateSocket(SocketType.SUB)) { if (Config.SubscriptionPrefixes() == null || Config.SubscriptionPrefixes().Count == 0) { socket.SubscribeAll(); } else { foreach (var subscriptionPrefix in Config.SubscriptionPrefixes()) { socket.Subscribe(Encoding.UTF8.GetBytes(subscriptionPrefix)); } } foreach (var endPoint in Config.ConnectEndPoints()) { socket.Connect(endPoint); } while (!this.Halted) { if (this.Halted) { break; } //3 ZeroLog.LogInfo("thread receive...." + DateTime.Now.ToLongTimeString()); var msg = socket.Receive(Encoding.UTF8, new TimeSpan(0, 0, Config.SendTimeout)); if (!string.IsNullOrEmpty(msg)) { ZeroLog.LogInfo("thread receive...." + msg); } } } } }
public void Declare() { if (!this.inited) { ZeroLog.LogInfo("producer inited...."); contexts = new Dictionary <string, ZmqContext>(); sockets = new Dictionary <string, ZmqSocket>(); monitors = new Dictionary <string, ZmqMonitor>(); List <ZeroRoute> rules = XMLExchange.GetInstance().Configs; routes = new Dictionary <string, ZeroRoute>(rules.Count); foreach (var config in rules) { ZmqContext context = ZmqContext.Create(); ZmqSocket socket = context.CreateSocket(PreSocketType()); ZmqMonitor monitor = context.CreateMonitor(); socket.SendTimeout = new TimeSpan(0, 0, config.SendTimeout); socket.MaxMessageSize = config.MaxMessageSize; contexts.Add(config.ExchangeName, context); sockets.Add(config.ExchangeName, socket); monitors.Add(config.ExchangeName, monitor); routes.Add(config.ExchangeName, config); Bind(socket, config); Connect(socket, config); ZeroLog.LogInfo("producer inited...." + config.ExchangeName); } processor = new Processor(contexts, sockets, monitors, routes); this.inited = true; } }
public void Declare() { if (!this.inited) { ZeroLog.LogInfo("consumer inited...."); List <ZeroRoute> rules = XMLExchange.GetInstance().Configs; foreach (var config in rules) { SubThread processor = new SubThread(); processor.Config = config; processor.ExchangeName = config.ExchangeName; pools.Add(config.ExchangeName, processor); ZeroLog.LogInfo("consumer inited...." + config.ExchangeName); } this.inited = true; } }
public void Join() { ZeroLog.LogInfo("thread join...."); this.thread.Join(); }
public void Interrupt() { ZeroLog.LogInfo("thread interrupt...."); this.thread.Interrupt(); }