ÔõÑùÔÚLinuxÉÏÉèÖø߿ÉÓõÄÐÂÎÅÖÐÐļþ
ÔõÑùÔÚlinuxÉÏÉèÖø߿ÉÓõÄÐÂÎÅÖÐÐļþ
СÐò£º
Ëæ×ÅÂþÑÜʽ¼Ü¹¹µÄÆÕ±éÓ¦Óã¬ÐÂÎÅÖÐÐļþÔÚϵͳÉè¼ÆÖÐÊ©Õ¹×ÅÖÁ¹ØÖ÷ÒªµÄ×÷Óá£Î¬³ÖÐÂÎÅÖÐÐļþµÄ¸ß¿ÉÓÃÐÔ¹ØÓÚϵͳµÄÎȹÌÔËÐÐÖÁ¹ØÖ÷Òª¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚlinuxÉÏÉèÖø߿ÉÓõÄÐÂÎÅÖÐÐļþ£¬²¢ÌṩÏìÓ¦µÄ´úÂëʾÀý¡£
Ò»¡¢Ê²Ã´ÊǸ߿ÉÓõÄÐÂÎÅÖÐÐļþ
¸ß¿ÉÓÃÐÔͨ³£ÊÇָϵͳ»òЧÀÍÄܹ»ÔÚ±¬·¢¹ÊÕÏʱ¼á³Ö¼ÌÐøÔËÐУ¬ÇÒ¿ÉÒÔ¾¡¿ÉÄܵػָ´µ½Õý³£ÔËÐÐ״̬¡£ÐÂÎÅÖÐÐļþ×÷ΪһÖÖÖ÷ÒªµÄÂþÑÜʽϵͳ×é¼þ£¬¸ß¿ÉÓÃÐÔµÄÉè¼ÆÊÇÈ·±£ÐÂÎÅÖÐÐļþÔÚÈκÎÇéÐÎ϶¼Äܼá³Ö¿ÉÓ㬲¢°ü¹ÜÐÂÎŵĿɿ¿×ª´ï¡£
¶þ¡¢LinuxÉϵÄÐÂÎÅÖÐÐļþ
ÔÚLinuxÉÏ£¬ÓÐÐí¶à³ÉÊìµÄÐÂÎÅÖÐÐļþ¿É¹©Ñ¡Ôñ£¬ÈçRabbitMQ¡¢Kafka¡¢ActiveMQµÈ¡£±¾ÎÄÒÔRabbitMQΪÀý£¬ÏÈÈÝÔÚLinuxÉÏÔõÑùÉèÖø߿ÉÓõÄÐÂÎÅÖÐÐļþ¡£
×°ÖÃRabbitMQ
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÔÚLinuxÉÏ×°ÖÃRabbitMQ¡£ÒÔUbuntuΪÀý£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁî¾ÙÐÐ×°Öãº
sudo apt-get install rabbitmq-server
µÇ¼ºó¸´ÖÆ
ÉèÖÃRabbitMQ¼¯Èº
ΪÁËʵÏָ߿ÉÓÃÐÔ£¬ÎÒÃÇÐèÒªÉèÖÃÒ»¸öRabbitMQ¼¯Èº£¬ÆäÖаüÀ¨¶à¸öRabbitMQ½Úµã¡£ÔÚÿ¸ö½ÚµãÉÏ£¬ÎÒÃÇÐèÒª¾ÙÐÐÈçÏÂÉèÖãº
2.1 ÐÞ¸ÄRabbitMQÉèÖÃÎļþ
ʹÓÃÒÔÏÂÏÂÁî±à¼RabbitMQÉèÖÃÎļþ£º
sudo nano /etc/rabbitmq/rabbitmq.conf
µÇ¼ºó¸´ÖÆ
ÔÚÉèÖÃÎļþÖÐÌí¼ÓÒÔÏÂÄÚÈÝ£º
cluster_formation.peer_discovery_backend = rabbit_peer_discovery_aws cluster_formation.aws.region = us-east-1 cluster_formation.aws.access_key_id = YOUR_ACCESS_KEY cluster_formation.aws.secret_access_key = YOUR_SECRET_KEY cluster_formation.aws.tag.Cluster = YOUR_CLUSTER_TAG cluster_formation.aws.back_off_base = 2 cluster_formation.aws.back_off_multiplier = 1.2
µÇ¼ºó¸´ÖÆ
ÕâЩÉèÖÃÏîÓÃÓÚÆôÓÃRabbitMQ¼¯Èº£¬²¢Ö¸¶¨AWS×÷Ϊ½Úµã·¢Ã÷µÄºó¶Ë¡£
2.2 Æô¶¯RabbitMQ½Úµã
ʹÓÃÒÔÏÂÏÂÁîÆô¶¯RabbitMQ½Úµã£º
sudo rabbitmq-server
µÇ¼ºó¸´ÖÆ
Æô¶¯Íê³Éºó£¬¿ÉÒÔÔÚä¯ÀÀÆ÷Öлá¼ûRabbitMQµÄÖÎÀí½çÃ棬ȷ±£½ÚµãÒÑÀÖ³ÉÆô¶¯¡£Ä¬ÈϵصãΪ£ºhttp://localhost:15672¡£
2.3 ¼ÓÈ뼯Ⱥ
½«ÆäËû½Úµã¼ÓÈëµ½¼¯ÈºÖУ¬Ê¹ÓÃÒÔÏÂÏÂÁ
sudo rabbitmqctl stop_app sudo rabbitmqctl join_cluster rabbit@node1 sudo rabbitmqctl start_app
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬node1ÊÇÒѾÆô¶¯µÄ½ÚµãÃû³Æ¡£
ÈÃÐÂÎÅ¿É¿¿×ª´ï
ΪÁË°ü¹ÜÐÂÎŵĿɿ¿×ª´ï£¬ÎÒÃÇ¿ÉÒÔʹÓÃRabbitMQÌṩµÄ³¤ÆÚ»¯ÐÂÎźÍÐû²¼È·ÈÏ»úÖÆ¡£
3.1 ³¤ÆÚ»¯ÐÂÎÅ
ÔÚ·¢ËÍÐÂÎÅʱ£¬¿ÉÒÔ½«ÐÂÎűê¼ÇΪ³¤ÆÚ»¯£¬È·±£ÐÂÎÅÔÚRabbitMQ½Úµãå´»úʱ²»»áɥʧ¡£Ê¾ÀýÈçÏ£º
import pika connection = pika.BlockingConnection(pika.ConnectionParameters('localhost')) channel = connection.channel() channel.queue_declare(queue='hello', durable=True) # ÉùÃ÷ÐÐÁÐΪ³¤ÆÚ»¯µÄ channel.basic_publish( exchange='', routing_key='hello', body='Hello World!', properties=pika.BasicProperties(delivery_mode=2) # ÉèÖÃÐÂÎų¤ÆÚ»¯ )
µÇ¼ºó¸´ÖÆ
3.2 Ðû²¼È·ÈÏ»úÖÆ
ͨ¹ýÆôÓÃÐû²¼È·ÈÏ»úÖÆ£¬¿ÉÒÔÈ·±£ÐÂÎÅÀֳɱ»RabbitMQÎüÊÕ¡£Ê¾ÀýÈçÏ£º
import pika connection = pika.BlockingConnection(pika.ConnectionParameters('localhost')) channel = connection.channel() channel.queue_declare(queue='hello') channel.confirm_delivery() # ÆôÓÃÐû²¼È·ÈÏ»úÖÆ def on_delivery_confirmation(frame): if frame.method.NAME == 'Basic.Ack': print('Message successfully delivered to RabbitMQ') else: print('Message failed to be delivered to RabbitMQ') channel.add_on_delivery_callback(on_delivery_confirmation) channel.basic_publish( exchange='', routing_key='hello', body='Hello World!' )
µÇ¼ºó¸´ÖÆ
Èý¡¢×ܽá
±¾ÎÄÏÈÈÝÁËÔõÑùÔÚlinuxÉÏÉèÖø߿ÉÓõÄÐÂÎÅÖÐÐļþ£¬²¢ÌṩÁËRabbitMQµÄʾÀý´úÂë¡£ÔÚÏÖʵӦÓÃÖУ¬»¹ÐèҪƾ֤ÏêϸµÄÐèÇó¾ÙÐнøÒ»²½ÉèÖúÍÓÅ»¯¡£Í¨¹ýºÏÀíµØʹÓø߿ÉÓõÄÐÂÎÅÖÐÐļþ£¬¿ÉÒÔÌáÉýϵͳµÄ½áʵÐԺͿɿ¿ÐÔ£¬ÔÚÂþÑÜʽÇéÐÎÏ°ü¹ÜÐÂÎŵĿɿ¿×ª´ï¡£
²Î¿¼ÎÄÏ×£º
RabbitMQ Documentation: https://www.rabbitmq.com/
Kafka Documentation: https://kafka.apache.org/
ActiveMQ Documentation: https://activemq.apache.org/
×¢£ºÒÔÉÏʾÀý´úÂë½öΪ²Î¿¼£¬ÏÖʵӦÓÃÖпÉÄÜÐèҪƾ֤ÏêϸÇéÐξÙÐÐÐ޸ġ£
ÒÔÉϾÍÊÇÔõÑùÔÚLinuxÉÏÉèÖø߿ÉÓõÄÐÂÎÅÖÐÐļþµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡