»ùÓÚSwooleµÄ¸ßÐÔÄÜIMЧÀÍÉè¼Æ°¸Àý
Ëæ×Å»¥ÁªÍøµÄ¿ìËÙÉú³¤£¬ÈËÃÇÔ½À´Ô½ÒÀÀµÓÚÖÖÖÖ¼´Ê±Í¨Ñ¶¹¤¾ß¡£ÖÚËùÖÜÖª£¬¹Å°åµÄ¼´Ê±Í¨Ñ¶ÊÖÒÕ±£´æÑÏÖصÄÑӳٺͿ¨¶ÙÎÊÌ⣬ÎÞ·¨Öª×ãÓû§ÈÕÒæÔöÌíµÄÐèÇó¡£Òò´Ë£¬¸ßÐÔÄÜimЧÀͳÉΪÁËÐÐҵؽ´ý½â¾öµÄÎÊÌâ¡£swoole×÷ΪһÖÖ¸ßÐÔÄܵÄÍøÂçͨѶ¿ò¼Ü£¬ÎªimЧÀ͵ÄÉè¼ÆÌṩÁËÓÅÒìµÄÖ§³Ö¡£
±¾ÎĽ«ÏÈÈÝÒ»¸ö»ùÓÚSwooleµÄ¸ßÐÔÄÜIMЧÀ͵ÄÉè¼Æ°¸Àý£¬Ïêϸ˵Ã÷ÆäÉè¼ÆÔÀíºÍʵÏÖÀú³Ì¡£
¼Ü¹¹Éè¼Æ
¸Ã¸ßÐÔÄÜIMЧÀ͵ļܹ¹½ÓÄÉÁ˾µäµÄC/S¼Ü¹¹£¬¼´¿Í»§¶ËºÍЧÀÍÆ÷¶ËÊèÉ¢¡£ÆäÖУ¬Ð§ÀÍÆ÷¶Ë½ÓÄÉSwoole¿ò¼Ü¾ÙÐд£¬ÊµÏֵײãµÄÍøÂçͨѶºÍÊý¾Ý´«Ê䣬ÈÏÕæ´¦Àí¿Í»§¶Ë·¢Ë͹ýÀ´µÄÇëÇ󣬲¢½«Ð§¹û·µ»Ø¸ø¿Í»§¶Ë¡£
ÔÚЧÀÍÆ÷¶Ë£¬ÎÒÃÇʹÓÃÁËRedis×÷Ϊ»º´æÊý¾Ý¿â£¬Ö÷ÒªÈÏÕæ´æ´¢¿Í»§¶ËµÄÅþÁ¬ÐÅÏ¢ºÍÐÂÎżÍ¼¡£±ðµÄ£¬ÎÒÃÇ»¹Ê¹ÓÃÁËMySQL×÷Ϊ³¤ÆÚ»¯Êý¾Ý¿â£¬ÓÃÓÚ´æ´¢Óû§ÐÅÏ¢ºÍ̸Ìì¼Í¼¡£´ËÖÖÉè¼Æ¼Ü¹¹¿ÉÒÔ´ó´óÌá¸ßϵͳµÄ¿ÉÀ©Õ¹ÐÔºÍÎÞаÐÔ£¬Í¬Ê±¼õÇáЧÀÍÆ÷µÄѹÁ¦¡£
Êý¾Ý¿âÉè¼Æ
ΪÁËÖª×ãIMЧÀ͵ÄÐèÇó£¬ÎÒÃÇÐèÒª½¨ÉèÒÔϼ¸ÕÅ±í£º
user±í£º´æ´¢Óû§µÄ»ù±¾ÐÅÏ¢£¬ÈçÓû§Ãû¡¢ÃÜÂë¡¢×¢²áʱ¼äµÈ£»
friend±í£º´æ´¢Óû§µÄÖ¿ÓÑÁÐ±í£»
chat_group±í£º´æ´¢Ì¸ÌìȺµÄ»ù±¾ÐÅÏ¢£¬ÈçȺÃû¡¢ÈºÖ÷¡¢½¨Éèʱ¼äµÈ£»
group_member±í£º´æ´¢Ì¸ÌìȺ³ÉÔ±µÄÐÅÏ¢£¬ÈçȺ³ÉÔ±ID¡¢¼ÓÈëʱ¼äµÈ£»
chat_history±í£º´æ´¢Ì¸Ìì¼Í¼µÄÐÅÏ¢£¬Èç·¢ËÍÕßID¡¢ÎüÊÕÕßID¡¢ÐÂÎÅÄÚÈÝ¡¢·¢ËÍʱ¼äµÈ¡£
¹¦Ð§ÊµÏÖ
3.1 ÅþÁ¬ÖÎÀí
ÔÚIMЧÀÍÖУ¬ÅþÁ¬ÖÎÀíÊǺÜÊÇÖ÷ÒªµÄÒ»²¿·Ö¡£ÎÒÃÇÐèҪά»¤Ò»¸öÅþÁ¬³Ø£¬ÓÃÓÚ´æ´¢¿Í»§¶ËÓëЧÀÍÆ÷Ö®¼ä½¨ÉèµÄÅþÁ¬£¬Í¬Ê±°ü¹ÜÅþÁ¬µÄÎȹÌÐԺͳ¤ÆÚÐÔ¡£
Swoole¿ò¼ÜÌṩÁ˺ÜÊÇÀû±ãµÄÒì²½IOºÍгÌÖ§³Ö£¬¿ÉÒÔÇáËÉʵÏÖÅþÁ¬µÄ½¨Éè¡¢¹Ø±ÕºÍÖØÁ¬µÈ²Ù×÷¡£ÎªÁ˱ÜÃâÅþÁ¬³ØÖзºÆðÌ«¹ýÏÐÖõÄÅþÁ¬£¬ÎÒÃÇ»¹ÐèҪʵÏÖÒ»¸öÅþÁ¬³¬Ê±¼ì²â»úÖÆ£¬×Ô¶¯É¨³ý²»ÔÙʹÓõÄÅþÁ¬¡£
3.2 Óû§ÈÏÖ¤
Óû§ÈÏÖ¤ÊÇIMЧÀ͵ÄÒªº¦¹¦Ð§Ö®Ò»¡£ÎÒÃÇÐèÒª¶Ôÿ¸ö¿Í»§¶ËµÄÅþÁ¬¾ÙÐÐÉí·ÝÑéÖ¤£¬È·±£ÅþÁ¬µÄÕýµ±ÐÔ¡£ÈôÊÇ¿Í»§¶ËûÓÐͨ¹ýÈÏÖ¤£¬ÔòÎÞ·¨·¢ËͺÍÎüÊÕÐÂÎÅ¡£
ÔÚÓû§µÇ¼ʱ£¬Ð§ÀÍÆ÷ÐèÒªÑéÖ¤Óû§µÄÓû§ÃûºÍÃÜÂëµÄ׼ȷÐÔ¡£ÈôÊÇÈÏÖ¤Àֳɣ¬ÔòЧÀÍÆ÷·µ»ØÒ»¸öΨһµÄtoken¸ø¿Í»§¶Ë£¬¿Í»§¶Ë¿ÉÒÔͨ¹ýÕâ¸ötokenÓëЧÀÍÆ÷½¨ÉèWebSocketÅþÁ¬¡£
3.3 ˽ÁÄ
˽ÁÄÊÇIMЧÀÍ×î»ù±¾µÄ¹¦Ð§Ö®Ò»¡£µ±Óû§ÏëÒª·¢ËÍÒ»Ìõ˽ÁÄÐÂÎÅʱ£¬¿Í»§¶ËÊ×ÏÈÐèÒª¾ÓÉÉí·ÝÈÏÖ¤£¬Ö®ºó·¢ËÍÒ»ÌõÇëÇóµ½Ð§ÀÍÆ÷¡£Ð§ÀÍÆ÷ÎüÊÕµ½ÇëÇóºó£¬ÐèҪƾ֤ÎüÊÕÕßµÄIDÕÒµ½ÎüÊÕÕßËùÔÚµÄÅþÁ¬£¬²¢½«ÕâÌõÐÂÎÅ·¢ËÍÒÑÍù¡£
Swoole¿ò¼ÜÌṩÁËÐí¶à¹¤¾ßº¯Êý£¬¿ÉÒÔ×ÊÖúÎÒÃÇʵÏÖÕâ¸ö¹¦Ð§¡£ÎÒÃÇ¿ÉÒÔʹÓÿò¼Ü×Ô´øµÄг̵÷Àí»úÖÆʵÏÖÒì²½ÐÂÎÅ·¢ËÍ£¬×èÖ¹ÛÕ±ÕºÍÐÔÄÜÆ¿¾±¡£
3.4 ȺÁÄ
ȺÁÄÊÇIMЧÀ͵ÄÁíÒ»¸öÖ÷Òª¹¦Ð§¡£¿Í»§¶Ë¿ÉÒÔÑ¡Ôñ¼ÓÈëÒ»¸öÒÑÓеÄ̸ÌìȺ£¬»òÕß½¨ÉèÒ»¸öеÄ̸ÌìȺ¡£
µ±Óû§·¢ËÍÒ»ÌõȺÁÄÐÂÎÅʱ£¬Ð§ÀÍÆ÷ÐèÒª½«ÕâÌõÐÂÎŹ㲥µ½ËùÓмÓÈëÁ˸Ã̸ÌìȺµÄ¿Í»§¶Ë¡£ÎªÁËÌá¸ßÐÔÄÜ£¬ÎÒÃÇ¿ÉÒÔʹÓÃSwoole¿ò¼ÜµÄÊÂÎñÑ»·»úÖÆ£¬½«Òì²½ÐÂÎÅ·¢Ë͵½ÅþÁ¬³ØÖÐËùÓеÄÓÐÓÃÅþÁ¬ÉÏ¡£
×ܽá
±¾ÎÄÏÈÈÝÁËÒ»¸ö»ùÓÚSwooleµÄ¸ßÐÔÄÜIMЧÀ͵ÄÉè¼Æ°¸Àý¡£Í¨¹ý½ÓÄÉȺ¼¯¼Ü¹¹¡¢Òì²½IOºÍг̵÷ÀíµÈÊÖÒÕ£¬ÎÒÃÇÀÖ³ÉʵÏÖÁË˽ÁÄ¡¢ÈºÁĺÍÅþÁ¬ÖÎÀíµÈÖ÷Òª¹¦Ð§£¬¼«´óµØÌáÉýÁËϵͳµÄÐÔÄܺÍÎȹÌÐÔ¡£Î´À´£¬ÎÒÃǽ«¼ÌÐøÓÅ»¯Õâ¸öIMЧÀÍ£¬Ì½Ë÷¸ü¶àеÄÊÖÒÕºÍÒªÁ죬ΪÓû§Ìṩ¸üºÃµÄ¼´Ê±Í¨Ñ¶ÌåÑé¡£
ÒÔÉϾÍÊÇ»ùÓÚSwooleµÄ¸ßÐÔÄÜIMЧÀÍÉè¼Æ°¸ÀýµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡