/// <summary> /// 注册从节点的端口到主控节点 /// </summary> /// <param name="slaveIdentity"></param> /// <returns></returns> protected virtual IDataContainer RegisterSlavePort(string slaveIdentity) { var result = new DataContainer(); result.Status = 0; result.Result = "-1"; if (!string.IsNullOrEmpty(slaveIdentity)) { var port = MasterRemoteServer.AddSlavePort(slaveIdentity); if (port > 0) { result.Result = port.ToString(); result.Status = 1; } } return(result); }
public override IDataContainer ProcessMessage(int SCBID, EndPoint RemoteIPEndPoint, NTCPMessage.MessageFlag Flag, ushort CableId, uint Channel, uint Event, SoapMessage objMsg) { if (null == objMsg) { return(DataContainer.CreateNullDataContainer()); } IDataContainer result = null; try { //如果不是集群,那么主节点处理消息 PeekerClusterNode slaveNode = null; var cmdHead = objMsg.Head; if (false == GlobalContext.IsConfigClusteringMode ||//是否开启集群模式 cmdHead.Equals(CommandConstants.CMD_RegisterSlavePort) ||//注册从节点端口 MasterRemoteServer.GetOneSlavePort(out slaveNode) == false ||//是否注册从节点端口)//注册从节点端口 slaveNode.Port == GlobalContext.MasterSocketPort //分配到了主节点工作 ) { result = base.ProcessMessage(SCBID, RemoteIPEndPoint, Flag, CableId, Channel, Event, objMsg); } else { //转发到从节点 result = this.TransferMsgToSlave(slaveNode, objMsg); } if (null != slaveNode) { slaveNode.ConnectedCount -= 1;//设置连接 减量 } } catch (Exception ex) { Logger.Error(ex); } return(result); }
/// <summary> /// 查询服务端是信息 /// </summary> /// <returns></returns> protected virtual string ScanServerInfo() { var sb_info = new StringBuilder(); #region Server sb_info.Append("# Server").AppendLine(); sb_info.Append("tcp_port:").Append(GlobalContext.MasterSocketPort).AppendLine(); sb_info.Append("process_id").Append(System.Diagnostics.Process.GetCurrentProcess().Id).AppendLine(); sb_info.Append(" ").AppendLine(); sb_info.Append(" ").AppendLine(); #endregion #region Cluster sb_info.Append("# Cluster").AppendLine(); sb_info.Append("cluster_mode:").Append(GlobalContext.IsConfigClusteringMode).AppendLine(); //查询集群节点信息 var slaveNodes = MasterRemoteServer.GetAllActiveSlaveNodes(); int couner = 0; foreach (var item in slaveNodes) { sb_info.AppendFormat("cluster-{0}:", couner).Append(item).AppendLine(); couner += 1; } sb_info.Append(" ").AppendLine(); sb_info.Append(" ").AppendLine(); #endregion return(sb_info.ToString()); }
private static void Main(string[] args) { //破解淘宝客加密的链接 //string url = "http://s.click.taobao.com/t?spm=1002.8113010.1999451588.1.197829d2xOjGWY&e=m%3D2%26s%3DmP8QGUZCl18cQipKwQzePOeEDrYVVa64LKpWJ%2Bin0XK3bLqV5UHdqU7FFcTKJEXpBuky%2F0Sep%2BFpvEi8xmC0PQfgGrPFD%2FD7ItsJf7xhZUukOrdzMLy3g0C9MWo3ZAy5ZtvIAOb0yL8buZkKjgqa4LRqys2RxTiLmiP8wiUuCvFDEV8PXh1a5UciGQ2l2vvBJoe7ipwP0MtRLBgaW5udaw%3D%3D"; //string content = new Http.HttpServerProxy().GetRequestTransfer(url,null); //var rl = TaobaoWebPageService.GetTaobaoUnionOfficalUrl(url); // return; try { //初始化CEF运行时 等操作 InitApp.Init(args); } catch (Exception ex) { // CefRuntime.PostTask(CefThreadId.IO, new MySomeTask()); // Clean up CEF. CefRuntime.Shutdown(); MasterRemoteServer.Stop(); Logger.Error(new Exception("未能正确启动CEF爬行蜘蛛!异常信息如下:")); Logger.Error(ex); return; } //var locker1 = RunningLocker.CreateNewLock(); //locker1.CancelAfter(20000); //BaseWebPageService etaoWeb = new TaobaoWebPageService(); //var paras = new NTCPMessage.EntityPackage.Arguments.TaobaoFetchWebPageArgument { KeyWord = "洗面奶男" }; //var con = etaoWeb.QuerySearchContent(paras); //System.Diagnostics.Debug.WriteLine(con.Result); //etaoWeb = new JingdongWebPageService(); // con = etaoWeb.QuerySearchContent(paras); //var headlessForm = new HeadLessMainForm(); //headlessForm.NavigateToUrl("https://pub.alimama.com/myunion.htm?spm=a219t.7900221/1.1998910419.dbb742793.21214865YeCJuR#!/promo/self/items"); Console.WriteLine("ShoppingWebCrawler.Host is started....."); if (null != args && string.Concat(args).Contains("slavemode")) { Console.WriteLine("SlaveRemoteServer is started....."); } //注册窗口关闭的时候 退出子进程 // we have to keep the handler routine alive during the execution of the program, // because the garbage collector will destroy it after any CTRL event GC.KeepAlive(cancelHandler); SetConsoleCtrlHandler(cancelHandler, true); var locker = RunningLocker.CreateNewLock(); locker.Pause(); //6 主进程退出的事件 }