{"id":797,"date":"2020-04-13T22:20:02","date_gmt":"2020-04-13T14:20:02","guid":{"rendered":"https:\/\/www.zhuyanbin.com\/?p=797"},"modified":"2020-04-14T13:37:41","modified_gmt":"2020-04-14T05:37:41","slug":"rocketmq%e7%ac%94%e8%ae%b0","status":"publish","type":"post","link":"https:\/\/www.yanbin888.com\/?p=797","title":{"rendered":"RocketMQ\u7b14\u8bb0"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">1. <strong>RocketMQ\u6d88\u606f\u5199\u5165\u78c1\u76d8\u7684\u65b9\u5f0f\uff1a\u540c\u6b65\u5237\u76d8\u548c\u5f02\u6b65\u5237\u76d8<\/strong><\/h3>\n\n\n\n<p>\u2751 \u5f02\u6b65\u5237\u76d8\u65b9\u5f0f\uff1a\u5728\u8fd4\u56de\u5199\u6210\u529f\u72b6\u6001\u65f6\uff0c\u6d88\u606f\u53ef\u80fd\u53ea\u662f\u88ab\u5199\u5165\u4e86\u5185\u5b58\u7684PAGECACHE\uff0c\u5199\u64cd\u4f5c\u7684\u8fd4\u56de\u5feb\uff0c\u541e\u5410\u91cf\u5927\uff1b\u5f53\u5185\u5b58\u91cc\u7684\u6d88\u606f\u91cf\u79ef\u7d2f\u5230\u4e00\u5b9a\u7a0b\u5ea6\u65f6\uff0c\u7edf\u4e00\u89e6\u53d1\u5199\u78c1\u76d8\u52a8\u4f5c\uff0c\u5feb\u901f\u5199\u5165\u3002<\/p>\n\n\n\n<p>\u2751 \u540c\u6b65\u5237\u76d8\u65b9\u5f0f\uff1a\u5728\u8fd4\u56de\u5199\u6210\u529f\u72b6\u6001\u65f6\uff0c\u6d88\u606f\u5df2\u7ecf\u88ab\u5199\u5165\u78c1\u76d8\u3002\u5177\u4f53\u6d41\u7a0b\u662f\uff0c\u6d88\u606f\u5199\u5165\u5185\u5b58\u7684PAGECACHE\u540e\uff0c\u7acb\u523b\u901a\u77e5\u5237\u76d8\u7ebf\u7a0b\u5237\u76d8\uff0c\u7136\u540e\u7b49\u5f85\u5237\u76d8\u5b8c\u6210\uff0c\u5237\u76d8\u7ebf\u7a0b\u6267\u884c\u5b8c\u6210\u540e\u5524\u9192\u7b49\u5f85\u7684\u7ebf\u7a0b\uff0c\u8fd4\u56de\u6d88\u606f\u5199\u6210\u529f\u7684\u72b6\u6001\u3002<\/p>\n\n\n\n<p>\u540c\u6b65\u5237\u76d8\u8fd8\u662f\u5f02\u6b65\u5237\u76d8\uff0c\u662f\u901a\u8fc7Broker\u914d\u7f6e\u6587\u4ef6\u91cc\u7684flushDiskType\u53c2\u6570\u8bbe\u7f6e\u7684\uff0c\u8fd9\u4e2a\u53c2\u6570\u88ab\u914d\u7f6e\u6210SYNC_FLUSH\u3001ASYNC_FLUSH\u4e2d\u7684\u4e00\u4e2a\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>RocketMQ\u4e3b\u4ece\u540c\u6b65\u65b9\u5f0f\uff1a\u540c\u6b65\u590d\u5236\u548c\u5f02\u6b65\u590d\u5236<\/strong><\/h3>\n\n\n\n<p>\u5982\u679c\u4e00\u4e2aBroker\u7ec4\u6709Master\u548cSlave\uff0c\u6d88\u606f\u9700\u8981\u4eceMaster\u590d\u5236\u5230Slave\u4e0a\uff0c\u6709\u540c\u6b65\u548c\u5f02\u6b65\u4e24\u79cd\u590d\u5236\u65b9\u5f0f\u3002<\/p>\n\n\n\n<p>\u540c\u6b65\u590d\u5236\u65b9\u5f0f\u662f\u7b49Master\u548cSlave\u5747\u5199\u6210\u529f\u540e\u624d\u53cd\u9988\u7ed9\u5ba2\u6237\u7aef\u5199\u6210\u529f\u72b6\u6001\uff1b<\/p>\n\n\n\n<p>\u5f02\u6b65\u590d\u5236\u65b9\u5f0f\u662f\u53ea\u8981Master\u5199\u6210\u529f\u5373\u53ef\u53cd\u9988\u7ed9\u5ba2\u6237\u7aef\u5199\u6210\u529f\u72b6\u6001\u3002<\/p>\n\n\n\n<p>\u8fd9\u4e24\u79cd\u590d\u5236\u65b9\u5f0f\u5404\u6709\u4f18\u52a3\uff0c\u5728\u5f02\u6b65\u590d\u5236\u65b9\u5f0f\u4e0b\uff0c\u7cfb\u7edf\u62e5\u6709\u8f83\u4f4e\u7684\u5ef6\u8fdf\u548c\u8f83\u9ad8\u7684\u541e\u5410\u91cf\uff0c\u4f46\u662f\u5982\u679cMaster\u51fa\u4e86\u6545\u969c\uff0c\u6709\u4e9b\u6570\u636e\u56e0\u4e3a\u6ca1\u6709\u88ab\u5199\u5165Slave\uff0c\u6709\u53ef\u80fd\u4f1a\u4e22\u5931\uff1b\u5728\u540c\u6b65\u590d\u5236\u65b9\u5f0f\u4e0b\uff0c\u5982\u679cMaster\u51fa\u6545\u969c\uff0cSlave\u4e0a\u6709\u5168\u90e8\u7684\u5907\u4efd\u6570\u636e\uff0c\u5bb9\u6613\u6062\u590d\uff0c\u4f46\u662f\u540c\u6b65\u590d\u5236\u4f1a\u589e\u5927\u6570\u636e\u5199\u5165\u5ef6\u8fdf\uff0c\u964d\u4f4e\u7cfb\u7edf\u541e\u5410\u91cf\u3002<\/p>\n\n\n\n<p>\u540c\u6b65\u590d\u5236\u548c\u5f02\u6b65\u590d\u5236\u662f\u901a\u8fc7Broker\u914d\u7f6e\u6587\u4ef6\u91cc\u7684brokerRole\u53c2\u6570\u8fdb\u884c\u8bbe\u7f6e\u7684\uff0c\u8fd9\u4e2a\u53c2\u6570\u53ef\u4ee5\u88ab\u8bbe\u7f6e\u6210ASYNC_MASTER\u3001SYNC_MASTER\u3001SLAVE\u4e09\u4e2a\u503c\u4e2d\u7684\u4e00\u4e2a\u3002<\/p>\n\n\n\n<p>\u5b9e\u9645\u5e94\u7528\u4e2d\u8981\u7ed3\u5408\u4e1a\u52a1\u573a\u666f\uff0c\u5408\u7406\u8bbe\u7f6e\u5237\u76d8\u65b9\u5f0f\u548c\u4e3b\u4ece\u590d\u5236\u65b9\u5f0f\uff0c\u5c24\u5176\u662fSYNC_FLUSH\u65b9\u5f0f\uff0c\u7531\u4e8e\u9891\u7e41\u5730\u89e6\u53d1\u78c1\u76d8\u5199\u52a8\u4f5c\uff0c\u4f1a\u660e\u663e\u964d\u4f4e\u6027\u80fd\u3002<\/p>\n\n\n\n<p>\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u5e94\u8be5\u628aMaster\u548cSave\u914d\u7f6e\u6210ASYNC_FLUSH\u7684\u5237\u76d8\u65b9\u5f0f\uff0c\u4e3b\u4ece\u4e4b\u95f4\u914d\u7f6e\u6210SYNC_MASTER\u7684\u590d\u5236\u65b9\u5f0f\uff0c\u8fd9\u6837\u5373\u4f7f\u6709\u4e00\u53f0\u673a\u5668\u51fa\u6545\u969c\uff0c\u4ecd\u7136\u80fd\u4fdd\u8bc1\u6570\u636e\u4e0d\u4e22\uff0c\u662f\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>\u90e8\u5206\u987a\u5e8f\u6d88\u606f<\/strong><\/h3>\n\n\n\n<p>\u8981\u4fdd\u8bc1\u90e8\u5206\u6d88\u606f\u6709\u5e8f\uff0c\u9700\u8981\u53d1\u9001\u7aef\u548c\u6d88\u8d39\u7aef\u914d\u5408\u5904\u7406\u3002\u5728\u53d1\u9001\u7aef\uff0c\u8981\u505a\u5230\u628a\u540c\u4e00\u4e1a\u52a1ID\u7684\u6d88\u606f\u53d1\u9001\u5230\u540c\u4e00\u4e2aMessage Queue\uff1b\u5728\u6d88\u8d39\u8fc7\u7a0b\u4e2d\uff0c\u8981\u505a\u5230\u4ece\u540c\u4e00\u4e2aMessage Queue\u8bfb\u53d6\u7684\u6d88\u606f\u4e0d\u88ab\u5e76\u53d1\u5904\u7406\uff0c\u8fd9\u6837\u624d\u80fd\u8fbe\u5230\u90e8\u5206\u6709\u5e8f\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>\u6d88\u606f\u7684Tag\u548cKey<\/strong><\/h3>\n\n\n\n<p>\u5bf9\u4e00\u4e2a\u5e94\u7528\u6765\u8bf4\uff0c\u5c3d\u53ef\u80fd\u53ea\u7528\u4e00\u4e2aTopic\uff0c\u4e0d\u540c\u7684\u6d88\u606f\u5b50\u7c7b\u578b\u7528Tag\u6765\u6807\u8bc6\uff08\u6bcf\u6761\u6d88\u606f\u53ea\u80fd\u6709\u4e00\u4e2aTag\uff09\uff0c\u670d\u52a1\u5668\u7aef\u57fa\u4e8eTag\u8fdb\u884c\u8fc7\u6ee4\uff0c\u5e76\u4e0d\u9700\u8981\u8bfb\u53d6\u6d88\u606f\u4f53\u7684\u5185\u5bb9\uff0c\u6240\u4ee5\u6548\u7387\u5f88\u9ad8\u3002\u53d1\u9001\u6d88\u606f\u8bbe\u7f6e\u4e86Tag\u4ee5\u540e\uff0c\u6d88\u8d39\u65b9\u5728\u8ba2\u9605\u6d88\u606f\u65f6\uff0c\u624d\u53ef\u4ee5\u5229\u7528Tag\u5728Broker\u7aef\u505a\u6d88\u606f\u8fc7\u6ee4\u3002<\/p>\n\n\n\n<p>\u5176\u6b21\u662f\u6d88\u606f\u7684Key\u3002\u5bf9\u53d1\u9001\u7684\u6d88\u606f\u8bbe\u7f6e\u597dKey\uff0c\u4ee5\u540e\u53ef\u4ee5\u6839\u636e\u8fd9\u4e2aKey\u6765\u67e5\u627e\u6d88\u606f\u3002\u6240\u4ee5\u8fd9\u4e2aKey\u4e00\u822c\u7528\u6d88\u606f\u5728\u4e1a\u52a1\u5c42\u9762\u7684\u552f\u4e00\u6807\u8bc6\u7801\u6765\u8868\u793a\uff0c\u8fd9\u6837\u540e\u7eed\u67e5\u8be2\u6d88\u606f\u5f02\u5e38\uff0c\u6d88\u606f\u4e22\u5931\u7b49\u90fd\u5f88\u65b9\u4fbf\u3002Broker\u4f1a\u521b\u5efa\u4e13\u95e8\u7684\u7d22\u5f15\u6587\u4ef6\uff0c\u6765\u5b58\u50a8Key\u5230\u6d88\u606f\u7684\u6620\u5c04\uff0c\u7531\u4e8e\u662f\u54c8\u5e0c\u7d22\u5f15\uff0c\u5e94\u5c3d\u91cf\u4f7fKey\u552f\u4e00\uff0c\u907f\u514d\u6f5c\u5728\u7684\u54c8\u5e0c\u51b2\u7a81\u3002<\/p>\n\n\n\n<p>Tag\u548cKey\u7684\u4e3b\u8981\u5dee\u522b\u662f\u4f7f\u7528\u573a\u666f\u4e0d\u540c\uff0cTag\u7528\u5728Consumer\u7684\u4ee3\u7801\u4e2d\uff0c\u7528\u6765\u8fdb\u884c\u670d\u52a1\u7aef\u6d88\u606f\u8fc7\u6ee4\uff0cKey\u4e3b\u8981\u7528\u4e8e\u901a\u8fc7\u547d\u4ee4\u884c\u67e5\u8be2\u6d88\u606f\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5. <strong>Consumer\u7684\u8d1f\u8f7d\u5747\u8861<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>DefaultMQPushConsumer\u7684\u8d1f\u8f7d\u5747\u8861<\/li><\/ul>\n\n\n\n<p>DefaultMQPushConsumer\u7684\u8d1f\u8f7d\u5747\u8861\u8fc7\u7a0b\u4e0d\u9700\u8981\u4f7f\u7528\u8005\u64cd\u5fc3\uff0c\u5ba2\u6237\u7aef\u7a0b\u5e8f\u4f1a\u81ea\u52a8\u5904\u7406\uff0c\u6bcf\u4e2aDefaultMQPushConsumer\u542f\u52a8\u540e\uff0c\u4f1a\u9a6c\u4e0a\u4f1a\u89e6\u53d1\u4e00\u4e2adoRebalance\u52a8\u4f5c\uff1b\u800c\u4e14\u5728\u540c\u4e00\u4e2aConsumerGroup\u91cc\u52a0\u5165\u65b0\u7684DefaultMQPushConsumer\u65f6\uff0c\u5404\u4e2aConsumer\u90fd\u4f1a\u88ab\u89e6\u53d1doRebalance\u52a8\u4f5c\u3002<\/p>\n\n\n\n<p>\u4ee5AllocateMessageQueueAveragely\u7b56\u7565\u4e3a\u4f8b\uff0c\u5982\u679c\u521b\u5efaTopic\u7684\u65f6\u5019\uff0c\u628aMessage Queue\u6570\u8bbe\u4e3a3\uff0c\u5f53Consumer\u6570\u91cf\u4e3a2\u7684\u65f6\u5019\uff0c\u6709\u4e00\u4e2aConsumer\u9700\u8981\u5904\u7406Topic\u4e09\u5206\u4e4b\u4e8c\u7684\u6d88\u606f\uff0c\u53e6\u4e00\u4e2a\u5904\u7406\u4e09\u5206\u4e4b\u4e00\u7684\u6d88\u606f\uff1b\u5f53Consumer\u6570\u91cf\u4e3a4\u7684\u65f6\u5019\uff0c\u6709\u4e00\u4e2aConsumer\u65e0\u6cd5\u6536\u5230\u6d88\u606f\uff0c\u5176\u4ed63\u4e2aConsumer\u5404\u5904\u7406Topic\u4e09\u5206\u4e4b\u4e00\u7684\u6d88\u606f\u3002\u53ef\u89c1Message Queue\u6570\u91cf\u8bbe\u7f6e\u8fc7\u5c0f\u4e0d\u5229\u4e8e\u505a\u8d1f\u8f7d\u5747\u8861\uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u5e94\u628a\u4e00\u4e2aTopic\u7684Message Queue\u6570\u8bbe\u7f6e\u4e3a16\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>DefaultMQPullConsumer\u7684\u8d1f\u8f7d\u5747\u8861<\/li><\/ul>\n\n\n\n<p>Pull Consumer\u53ef\u4ee5\u770b\u5230\u6240\u6709\u7684Message Queue\uff0c\u800c\u4e14\u4ece\u54ea\u4e2aMessage Queue\u8bfb\u53d6\u6d88\u606f\uff0c\u8bfb\u6d88\u606f\u65f6\u7684Offset\u90fd\u7531\u4f7f\u7528\u8005\u63a7\u5236\uff0c\u4f7f\u7528\u8005\u53ef\u4ee5\u5b9e\u73b0\u4efb\u4f55\u7279\u6b8a\u65b9\u5f0f\u7684\u8d1f\u8f7d\u5747\u8861\u3002<\/p>\n\n\n\n<p>DefaultMQPullConsumer\u6709\u4e24\u4e2a\u8f85\u52a9\u65b9\u6cd5\u53ef\u4ee5\u5e2e\u52a9\u5b9e\u73b0\u8d1f\u8f7d\u5747\u8861\uff0c\u4e00\u4e2a\u662fregisterMessageQueueListener\u51fd\u6570\uff0cregisterMessageQueueListener\u51fd\u6570\u5728\u6709\u65b0\u7684Consumer\u52a0\u5165\u6216\u9000\u51fa\u65f6\u88ab\u89e6\u53d1\u3002\u53e6\u4e00\u4e2a\u8f85\u52a9\u5de5\u5177\u662fMQPullConsumerScheduleService\u7c7b\uff0c\u4f7f\u7528\u8fd9\u4e2aClass\u7c7b\u4f3c\u4f7f\u7528DefaultMQPushConsumer\uff0c\u4f46\u662f\u5b83\u628aPull\u6d88\u606f\u7684\u4e3b\u52a8\u6027\u7559\u7ed9\u4e86\u4f7f\u7528\u8005\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6. \u914d\u7f6e\u6587\u4ef6<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Property Name<\/th><th>Default value<\/th><th>Details<\/th><\/tr><\/thead><tbody><tr><td>listenPort<\/td><td>10911<\/td><td>listen port for client<\/td><\/tr><tr><td>namesrvAddr<\/td><td>null<\/td><td>name server address<\/td><\/tr><tr><td>brokerIP1<\/td><td>InetAddress for network interface<\/td><td>Should be configured if having multiple addresses<\/td><\/tr><tr><td>brokerName<\/td><td>null<\/td><td>broker name<\/td><\/tr><tr><td>brokerClusterName<\/td><td>DefaultCluster<\/td><td>this broker belongs to which cluster<\/td><\/tr><tr><td>brokerId<\/td><td>0<\/td><td>broker id, 0 means master, positive integers mean slave<\/td><\/tr><tr><td>storePathCommitLog<\/td><td>$HOME\/store\/commitlog\/<\/td><td>file path for commit log<\/td><\/tr><tr><td>storePathConsumerQueue<\/td><td>$HOME\/store\/consumequeue\/<\/td><td>file path for consume queue<\/td><\/tr><tr><td>mapedFileSizeCommitLog<\/td><td>1024 * 1024 * 1024(1G)<\/td><td>mapped file size for commit log<\/td><\/tr><tr><td>deleteWhen<\/td><td>04<\/td><td>When to delete the commitlog which is out of the reserve time<\/td><\/tr><tr><td>fileReserverdTime<\/td><td>72<\/td><td>The number of hours to keep a commitlog before deleting it<\/td><\/tr><tr><td>brokerRole<\/td><td>ASYNC_MASTER<\/td><td>SYNC_MASTER\/ASYNC_MASTER\/SLAVE<\/td><\/tr><tr><td>flushDiskType<\/td><td>ASYNC_FLUSH<\/td><td>{SYNC_FLUSH\/ASYNC_FLUSH}. Broker of SYNC_FLUSH mode flushes each message onto disk before acknowledging producer. Broker of ASYNC_FLUSH mode, on the other hand, takes advantage of group-committing, achieving better performance.<\/td><\/tr><\/tbody><\/table><figcaption>\u914d\u7f6e\u6587\u4ef6\u8be6\u60c5<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">\u53c2\u8003\u6587\u732e\uff1a<\/h3>\n\n\n\n<ol class=\"wp-block-list\"><li>\u6768\u5f00\u5143  2018 \u300a<em>RocketMQ\u5b9e\u6218\u4e0e\u539f\u7406\u89e3\u6790<\/em>\u300b \u673a\u68b0\u5de5\u4e1a\u51fa\u7248\u793e  ISBN\uff1a9787111600251<\/li><li>https:\/\/rocketmq.apache.org\/docs\/rmq-deployment\/<\/li><\/ol>\n","protected":false},"excerpt":{"rendered":"<p>1. RocketMQ\u6d88\u606f\u5199\u5165\u78c1\u76d8\u7684\u65b9\u5f0f\uff1a\u540c\u6b65\u5237\u76d8\u548c\u5f02\u6b65\u5237\u76d8 \u2751 \u5f02\u6b65\u5237\u76d8\u65b9\u5f0f\uff1a\u5728\u8fd4\u56de\u5199\u6210\u529f\u72b6\u6001\u65f6\uff0c\u6d88\u606f\u53ef\u80fd\u53ea <span class=\"ellipsis\">&hellip;<\/span> <span class=\"more-link-wrap\"><a href=\"https:\/\/www.yanbin888.com\/?p=797\" class=\"more-link\"><span>Read More &rarr;<\/span><\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69],"tags":[70],"class_list":["post-797","post","type-post","status-publish","format-standard","hentry","category-69","tag-rocketmq"],"_links":{"self":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts\/797","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=797"}],"version-history":[{"count":13,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts\/797\/revisions"}],"predecessor-version":[{"id":815,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=\/wp\/v2\/posts\/797\/revisions\/815"}],"wp:attachment":[{"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=797"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yanbin888.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}