SwooleÓëConsulµÄÍêÉÆÍŽ᣺¹¹½¨¸ßÐÔÄܵÄЧÀÍ×¢²áÓë·¢Ã÷ϵͳ
Ëæ×Å»¥ÁªÍøÊÖÒյĿìËÙÉú³¤£¬Ô½À´Ô½¶àµÄÆóÒµ×îÏȽ«×ÔÉíЧÀÍÏòÔƶËÒƶ¯£¬½ÓÄÉ΢ЧÀͼܹ¹À´Ìá¸ßϵͳµÄ¿ÉÀ©Õ¹ÐÔ¡¢¿Éά»¤ÐԺͿɿ¿ÐÔ¡£Ð§ÀÍ×¢²áÓë·¢Ã÷ÊÇ΢ЧÀͼܹ¹ÖеĽ¹µã×é³É²¿·Ö£¬Ò²ÊÇʵÏÖ΢ЧÀÍÖ®¼äͨѶµÄÖ÷Òª»ù´¡¡£
ÔÚЧÀÍ×¢²áÓë·¢Ã÷µÄÁìÓò£¬ConsulÊÇÒ»¿î¿ªÔ´µÄ¸ß¿ÉÓÃÂþÑÜʽЧÀÍ·¢Ã÷ÓëÉèÖù¤¾ß£¬¾ßÓÐÂþÑÜʽ¡¢¸ß¿ÉÓᢴ󶼾ÝÖÐÑë¡¢¿ÉÀ©Õ¹ÐÔµÈÌص㡣¶øSwooleÔòÊÇÒ»¿î»ùÓÚPHPÓïÑÔ¿ª·¢µÄ¸ßÐÔÄܵÄÒì²½ÍøÂçͨѶ¿ò¼Ü£¬Ö§³ÖTCP/UDP¡¢WebSocketµÈ¶àÖÖÐÒ飬¿ÉÒÔÓÐÓÃÌá¸ß΢ЧÀͼܹ¹ÖеÄͨѶЧÂÊ¡£
±¾ÎĽ«ÏÈÈÝÔõÑùÍŽáSwooleºÍConsul¹¹½¨¸ßÐÔÄܵÄЧÀÍ×¢²áÓë·¢Ã÷ϵͳ£¬ÒÔ±ãÓÚʵÏÖ΢ЧÀͼܹ¹ÖÐЧÀÍÖ®¼äµÄͨѶ¹¦Ð§¡£
ConsulÏÈÈÝ
ConsulÊÇÒ»¿îÓÉHashiCorp¹«Ë¾¿ª·¢µÄЧÀÍ·¢Ã÷ÓëÉèÖù¤¾ß£¬Äܹ»¼¯³ÉЧÀÍ·¢Ã÷¡¢¿µ½¡¼ì²é¡¢KV´æ´¢¡¢´ó¶¼¾ÝÖÐÑëµÈ¹¦Ð§£¬Ö§³ÖRESTful APIºÍDNSÐÒé½ÓÈë¡£ConsulÌṩÁ˸»ºñµÄAPI½Ó¿ÚºÍÓѺõÄWeb½çÃ棬¿ÉÒÔÀû±ã¿ì½ÝµØͨ¹ýHTTP API»òDNSÆÊÎö¾ÙÐÐЧÀ͵Ä×¢²á¡¢·¢Ã÷¡¢¿µ½¡¼ì²éµÈ²Ù×÷¡£±ðµÄ£¬ÔÚÊý¾ÝÖÐÑëµÄÉèÖ÷½Ã棬ConsulÖ§³ÖÎÞ·ì´ó¶¼¾ÝÖÐÑëµÄ°²ÅÅ£¬¿ÉÒÔʵÏÖ¿çÊý¾ÝÖÐÑëµÄЧÀÍ·¢Ã÷ºÍͬ²½¡£
SwooleÏÈÈÝ
SwooleÊÇÒ»¿î¸ßÐÔÄܵÄPHPÒì²½ÍøÂçͨѶ¿ò¼Ü£¬¿ÉÒÔÔÚPHPÖÐʹÓÃÀàËÆÓÚGoºÍNode.jsµÄÒì²½I/O±à³Ìģʽ£¬ÊµÏÖ¸ü¸ßЧµÄͨѶºÍ²¢·¢¡£SwooleÖ§³ÖTCP/UDP¡¢WebSocketµÈ¶àÖÖÐÒ飬ÌṩÁË»ùÓÚÊÂÎñÇý¶¯ºÍгÌÄ£×ӵıà³Ì·½·¨£¬¿ÉÒÔÔÚµ¥¸öÏß³ÌÄÚͬʱ´¦Àí´ó×ÚµÄI/O²Ù×÷ºÍÇëÇóÏìÓ¦¡£
SwooleÓëConsulµÄÍŽá
ÔÚ¹¹½¨¸ßÐÔÄܵÄЧÀÍ×¢²áÓë·¢Ã÷ϵͳʱ£¬¿ÉÒÔÍŽáSwooleºÍConsulÀ´ÊµÏÖ¡£ÏêϸʵÏÖÁ÷³ÌÈçÏ£º
3.1 ЧÀÍ×¢²á
µ±Ð§ÀÍÆô¶¯Ê±£¬Í¨¹ýSwooleµÄHTTP¿Í»§¶ËÏòConsulµÄHTTP API·¢ËÍЧÀÍ×¢²áÇëÇó£¬ÇëÇóÄÚÈÝ°üÀ¨Ð§ÀÍÃû¡¢IPµØµã¡¢¶Ë¿ÚºÅµÈ¡£ConsulÎüÊÕµ½×¢²áÇëÇóºó£¬½«Ð§ÀÍÐÅÏ¢´æ´¢ÔÚConsulµÄKV´æ´¢ÖУ¬Í¬Ê±½«Ð§ÀÍÐÅÏ¢¹ã²¥µ½Õû¸öЧÀͼ¯ÈºÖУ¬¹©ÆäËûЧÀÍʹÓá£Í¨¹ýʹÓÃConsulÌṩµÄ¿µ½¡¼ì²é»úÖÆ£¬¿ÉÒÔ°´ÆÚ¼ì²é×¢²áµÄЧÀÍÊÇ·ñ¿ÉÓ㬲¢ÊµÊ±¸üÐÂЧÀÍ״̬¡£
3.2 ЧÀÍ·¢Ã÷
µ±Ð§ÀÍÐèÒªÓëÆäËûЧÀÍͨѶʱ£¬Í¨¹ýSwooleµÄHTTP¿Í»§¶ËÏòConsulµÄHTTP API·¢ËÍЧÀÍ·¢Ã÷ÇëÇó£¬ÇëÇóÄÚÈÝ°üÀ¨Ð§ÀÍÃû¡¢°æ±¾ºÅµÈÐÅÏ¢¡£Consulƾ֤ÇëÇóÐÅÏ¢´ÓKV´æ´¢ÖвéÕÒÇкÏÌõ¼þµÄЧÀÍÁÐ±í£¬²¢Æ¾Ö¤Ô¤¶¨µÄ¸ºÔØƽºâÕ½ÂÔ·µ»Ø¿ÉÓÃЧÀ͵ÄIPµØµãºÍ¶Ë¿ÚºÅ¡£Ð§ÀÍͨ¹ýIPµØµãºÍ¶Ë¿ÚºÅÓëÄ¿µÄЧÀ;ÙÐÐͨѶ¡£
3.3 ЧÀÍ¿µ½¡¼ì²é
ͨ¹ýConsulÌṩµÄ¿µ½¡¼ì²é»úÖÆ£¬¿ÉÒÔ°´ÆÚ¼ì²é×¢²áµÄЧÀÍÊÇ·ñ¿ÉÓá£Ð§ÀÍ¿ÉÒÔͨ¹ýÏòConsul·¢ËÍÐÄÌøÇëÇóÀ´Í¨ÖªConsul×Ô¼ºµÄ¿µ½¡×´Ì¬¡£ÈôÊÇЧÀÍ·ºÆð¹ÊÕÏ»òÕßÎÞ·¨ÏìÓ¦ÐÄÌøÇëÇó£¬Consul»á½«¸ÃЧÀͱê¼ÇΪ²»¿ÉÓÃ״̬£¬²¢ÊµÊ±½«Ð§ÀÍÁбí¸üиøÆäËûЧÀÍ¡£
½áÂÛ
SwooleÊÇÒ»¿î¸ßÐÔÄܵÄÒì²½ÍøÂçͨѶ¿ò¼Ü£¬¿ÉÒÔÔÚPHPÖÐʵÏÖ¸ßЧµÄͨѶºÍ²¢·¢¡£ÍŽáConsulµÄÓÅÒìЧÀÍ·¢Ã÷ºÍÉèÖù¤¾ß£¬¿ÉÒÔ¹¹½¨¸ßÐÔÄܵÄЧÀÍ×¢²áÓë·¢Ã÷ϵͳ£¬Àû±ã΢ЧÀͼܹ¹ÖеÄЧÀÍͨѶºÍÖÎÀí¡£Î´À´£¬Ð§ÀÍ×¢²áÓë·¢Ã÷½«³ÉΪ¿ªÔ´ÊÖÒÕµÄÈÈÃÅÁìÓò£¬¸ü¶àµÄÁ¢ÒìºÍÉú³¤½«»áÔÚ´Ë»ù´¡ÉÏÕö¿ª¡£
ÒÔÉϾÍÊÇSwooleÓëConsulµÄÍêÉÆÍŽ᣺¹¹½¨¸ßÐÔÄܵÄЧÀÍ×¢²áÓë·¢Ã÷ϵͳµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡