{"id":3586,"date":"2017-09-02T08:12:52","date_gmt":"2017-09-02T00:12:52","guid":{"rendered":"https:\/\/ixyzero.com\/blog\/?p=3586"},"modified":"2017-09-02T08:12:52","modified_gmt":"2017-09-02T00:12:52","slug":"apache-storm%e5%85%a5%e9%97%a8%e5%ad%a6%e4%b9%a0","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/3586.html","title":{"rendered":"Apache Storm\u5165\u95e8\u5b66\u4e60"},"content":{"rendered":"<p>=Start=<\/p>\n<h4 id=\"id-\u6a21\u677f-\u7f18\u7531\uff1a\">\u7f18\u7531\uff1a<\/h4>\n<p>\u5b66\u4e60\u3001\u63d0\u9ad8\u9700\u8981<\/p>\n<h4 id=\"id-\u6a21\u677f-\u6b63\u6587\uff1a\">\u6b63\u6587\uff1a<\/h4>\n<h5 id=\"id-\u6a21\u677f-\u53c2\u8003\u89e3\u7b54\uff1a\">\u53c2\u8003\u89e3\u7b54\uff1a<\/h5>\n<h2>\u4e00\u3001\u4ec0\u4e48\u662fApache Storm\uff1f<\/h2>\n<p>Apache Storm\u662f\u4e00\u4e2a<strong>\u5206\u5e03\u5f0f<span style=\"color: #ff0000;\">\u5b9e\u65f6<\/span><\/strong>\u5927\u6570\u636e\u5904\u7406\u7cfb\u7edf\u3002Storm\u8bbe\u8ba1\u7528\u4e8e\u5728\u5bb9\u9519\u548c\u6c34\u5e73\u53ef\u6269\u5c55\u65b9\u6cd5\u4e2d\u5904\u7406\u5927\u91cf\u6570\u636e\u3002\u5b83\u662f\u4e00\u4e2a\u6d41\u6570\u636e\u6846\u67b6\uff0c\u5177\u6709\u5f88\u9ad8\u7684\u541e\u5410\u7387\u3002<span style=\"color: #0000ff;\"><strong>\u867d\u7136Storm\u662f\u65e0\u72b6\u6001\u7684\uff0c\u5b83\u901a\u8fc7Apache ZooKeeper\u7ba1\u7406\u5206\u5e03\u5f0f\u73af\u5883\u548c\u96c6\u7fa4\u72b6\u6001\u3002<\/strong><\/span>\u5b83\u5f88\u7b80\u5355\uff0c\u60a8\u53ef\u4ee5\u5e76\u884c\u5730\u5bf9\u5b9e\u65f6\u6570\u636e\u6267\u884c\u5404\u79cd\u64cd\u4f5c\u3002Apache Storm\u6613\u4e8e\u8bbe\u7f6e\u548c\u64cd\u4f5c\uff0c\u5e76\u4e14\u5b83\u4fdd\u8bc1\u6bcf\u4e2a\u6d88\u606f\u5c06\u901a\u8fc7\u62d3\u6251\u81f3\u5c11\u5904\u7406\u4e00\u6b21\u3002<\/p>\n<h2>\u4e8c\u3001Apache Storm vs. Hadoop<\/h2>\n<p>Hadoop\u548cStorm\u6846\u67b6\u90fd\u7528\u4e8e\u5206\u6790\u5927\u6570\u636e\u3002\u4e24\u8005\u4e92\u8865\uff0c\u5728\u67d0\u4e9b\u65b9\u9762\u6709\u6240\u4e0d\u540c\u3002<strong>Apache Storm\u6267\u884c\u9664\u6301\u4e45\u6027\u4e4b\u5916\u7684\u6240\u6709\u64cd\u4f5c\uff0c\u800cHadoop\u5728\u6240\u6709\u65b9\u9762\u90fd\u5f88\u597d\uff0c\u4f46\u6ede\u540e\u4e8e\u5b9e\u65f6\u8ba1\u7b97\u3002<\/strong>\u4e0b\u8868\u6bd4\u8f83\u4e86Storm\u548cHadoop\u7684\u5c5e\u6027\u3002<\/p>\n<table class=\"table table-bordered \">\n<tbody>\n<tr>\n<th>Storm<\/th>\n<th>Hadoop<\/th>\n<\/tr>\n<tr>\n<td>\u5b9e\u65f6\u6d41\u5904\u7406<\/td>\n<td>\u6279\u91cf\u5904\u7406<\/td>\n<\/tr>\n<tr>\n<td>\u65e0\u72b6\u6001<\/td>\n<td>\u6709\u72b6\u6001<\/td>\n<\/tr>\n<tr>\n<td>\u4e3b\/\u4ece\u67b6\u6784\u4e0e\u57fa\u4e8e<strong>ZooKeeper<\/strong>\u7684\u534f\u8c03\u3002\u4e3b\u8282\u70b9\u79f0\u4e3animbus\uff0c\u4ece\u5c5e\u8282\u70b9\u662f<strong>\u4e3b\u7ba1<\/strong>\u3002<\/td>\n<td>\u5177\u6709\/\u4e0d\u5177\u6709\u57fa\u4e8eZooKeeper\u7684\u534f\u8c03\u7684\u4e3b &#8211; \u4ece\u7ed3\u6784\u3002\u4e3b\u8282\u70b9\u662f<strong>\u4f5c\u4e1a\u8ddf\u8e2a\u5668<\/strong>\uff0c\u4ece\u8282\u70b9\u662f<strong>\u4efb\u52a1\u8ddf\u8e2a\u5668<\/strong>\u3002<\/td>\n<\/tr>\n<tr>\n<td>Storm\u6d41\u8fc7\u7a0b\u5728\u96c6\u7fa4\u4e0a\u6bcf\u79d2\u53ef\u4ee5\u8bbf\u95ee\u6570\u4e07\u6761\u6d88\u606f\u3002<\/td>\n<td>Hadoop\u5206\u5e03\u5f0f\u6587\u4ef6\u7cfb\u7edf\uff08HDFS\uff09\u4f7f\u7528MapReduce\u6846\u67b6\u6765\u5904\u7406\u5927\u91cf\u7684\u6570\u636e\uff0c\u9700\u8981\u51e0\u5206\u949f\u6216\u51e0\u5c0f\u65f6\u3002<\/td>\n<\/tr>\n<tr>\n<td>Storm\u62d3\u6251\u8fd0\u884c\u76f4\u5230\u7528\u6237\u5173\u95ed\u6216\u610f\u5916\u7684\u4e0d\u53ef\u6062\u590d\u6545\u969c\u3002<\/td>\n<td>MapReduce\u4f5c\u4e1a\u6309\u987a\u5e8f\u6267\u884c\u5e76\u6700\u7ec8\u5b8c\u6210\u3002<\/td>\n<\/tr>\n<tr>\n<td colspan=\"2\"><strong>\u4e24\u8005\u90fd\u662f\u5206\u5e03\u5f0f\u548c\u5bb9\u9519\u7684<\/strong><\/td>\n<\/tr>\n<tr>\n<td>\u5982\u679cnimbus \/ supervisor\u6b7b\u673a\uff0c\u91cd\u65b0\u542f\u52a8\u4f7f\u5b83\u4ece\u5b83\u505c\u6b62\u7684\u5730\u65b9\u7ee7\u7eed\uff0c\u56e0\u6b64\u6ca1\u6709\u4ec0\u4e48\u53d7\u5230\u5f71\u54cd\u3002<\/td>\n<td>\u5982\u679cJobTracker\u6b7b\u673a\uff0c\u6240\u6709\u6b63\u5728\u8fd0\u884c\u7684\u4f5c\u4e1a\u90fd\u4f1a\u4e22\u5931\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ul>\n<li><span style=\"color: #ff0000;\"><strong>Storm\uff1a \u00a0 \u5206\u5e03\u5f0f\u5b9e\u65f6\u8ba1\u7b97\uff0c\u5f3a\u8c03\u5b9e\u65f6\u6027<\/strong><\/span>\uff0c\u5e38\u7528\u4e8e\u5b9e\u65f6\u6027\u8981\u6c42\u8f83\u9ad8\u7684\u5730\u65b9\uff1b<\/li>\n<li><span style=\"color: #ff0000;\">Hadoop\uff1a\u5206\u5e03\u5f0f\u6279\u5904\u7406\u8ba1\u7b97\uff0c\u5f3a\u8c03\u6279\u5904\u7406\uff0c\u5e38\u7528\u4e8e\u5bf9\u5df2\u7ecf\u5728\u7684\u5927\u91cf\u6570\u636e\u8fdb\u884c\u6316\u6398\u3001\u5206\u6790<\/span>\uff1b<\/li>\n<\/ul>\n<h2>\u4e09\u3001Apache Storm\u7684\u6838\u5fc3\u6982\u5ff5<\/h2>\n<p>\u4e0b\u56fe\u63cf\u8ff0\u4e86Apache Storm\u7684\u6838\u5fc3\u6982\u5ff5\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.w3cschool.cn\/attachments\/tuploads\/apache_storm\/core_concept.jpg\" alt=\"\u6838\u5fc3\u7406\u5ff5\" \/><\/p>\n<p>Storm \u96c6\u7fa4\u7684\u8f93\u5165\u6d41\u7531\u4e00\u4e2a\u88ab\u79f0\u4f5c spout \u7684\u7ec4\u4ef6\u7ba1\u7406\uff0cspout \u628a\u6570\u636e\u4f20\u9012\u7ed9 bolt\uff0c bolt \u8981\u4e48\u628a\u6570\u636e\u4fdd\u5b58\u5230\u67d0\u79cd\u5b58\u50a8\u5668\uff0c\u8981\u4e48\u628a\u6570\u636e\u4f20\u9012\u7ed9\u5176\u5b83\u7684 bolt\u3002\u4f60\u53ef\u4ee5\u60f3\u8c61\u4e00\u4e0b\uff0c\u4e00\u4e2a Storm \u96c6\u7fa4\u5c31\u662f\u5728\u4e00\u8fde\u4e32\u7684 bolt \u4e4b\u95f4\u8f6c\u6362 spout \u4f20\u8fc7\u6765\u7684\u6570\u636e\uff1a<\/p>\n<p><code>data-source -&gt; spout -&gt; bolt[ -&gt; bolt ...] -&gt; data-storage<\/code><\/p>\n<p>\u73b0\u5728\u8ba9\u6211\u4eec\u4ed4\u7ec6\u770b\u770bApache Storm\u7684\u7ec4\u4ef6\uff1a<\/p>\n<table class=\"table table-bordered \">\n<tbody>\n<tr>\n<th>\u7ec4\u4ef6<\/th>\n<th>\u63cf\u8ff0<\/th>\n<\/tr>\n<tr>\n<td>Tuple<\/td>\n<td>Tuple\u662fStorm\u4e2d\u7684\u4e3b\u8981\u6570\u636e\u7ed3\u6784\u3002\u5b83\u662f\u6709\u5e8f\u5143\u7d20\u7684\u5217\u8868\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cTuple\u652f\u6301\u6240\u6709\u6570\u636e\u7c7b\u578b\u3002\u901a\u5e38\uff0c\u5b83\u88ab\u5efa\u6a21\u4e3a\u4e00\u7ec4\u9017\u53f7\u5206\u9694\u7684\u503c\uff0c\u5e76\u4f20\u9012\u5230Storm\u96c6\u7fa4\u3002<\/td>\n<\/tr>\n<tr>\n<td>Stream<\/td>\n<td>\u6d41\u662f\u5143\u7ec4\u7684\u65e0\u5e8f\u5e8f\u5217\u3002<\/td>\n<\/tr>\n<tr>\n<td>Spouts<\/td>\n<td>\u6d41\u7684\u6e90\u3002\u901a\u5e38\uff0cStorm\u4ece\u539f\u59cb\u6570\u636e\u6e90\uff08\u5982Twitter Streaming API\uff0cApache Kafka\u961f\u5217\uff0cKestrel\u961f\u5217\u7b49\uff09\u63a5\u53d7\u8f93\u5165\u6570\u636e\u3002\u5426\u5219\uff0c\u60a8\u53ef\u4ee5\u7f16\u5199spouts\u4ee5\u4ece\u6570\u636e\u6e90\u8bfb\u53d6\u6570\u636e\u3002\u201cISpout\u201d\u662f\u5b9e\u73b0spouts\u7684\u6838\u5fc3\u63a5\u53e3\uff0c\u4e00\u4e9b\u7279\u5b9a\u7684\u63a5\u53e3\u662fIRichSpout\uff0cBaseRichSpout\uff0cKafkaSpout\u7b49\u3002<\/td>\n<\/tr>\n<tr>\n<td>Bolts<\/td>\n<td>Bolts\u662f\u903b\u8f91\u5904\u7406\u5355\u5143\u3002Spouts\u5c06\u6570\u636e\u4f20\u9012\u5230Bolts\u548cBolts\u8fc7\u7a0b\uff0c\u5e76\u4ea7\u751f\u65b0\u7684\u8f93\u51fa\u6d41\u3002Bolts\u53ef\u4ee5\u6267\u884c\u8fc7\u6ee4\uff0c\u805a\u5408\uff0c\u52a0\u5165\uff0c\u4e0e\u6570\u636e\u6e90\u548c\u6570\u636e\u5e93\u4ea4\u4e92\u7684\u64cd\u4f5c\u3002Bolts\u63a5\u6536\u6570\u636e\u5e76\u53d1\u5c04\u5230\u4e00\u4e2a\u6216\u591a\u4e2aBolts\u3002 \u201cIBolt\u201d\u662f\u5b9e\u73b0Bolts\u7684\u6838\u5fc3\u63a5\u53e3\u3002\u4e00\u4e9b\u5e38\u89c1\u7684\u63a5\u53e3\u662fIRichBolt\uff0cIBasicBolt\u7b49\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\u62d3\u6251<\/h4>\n<p><span style=\"color: #ff0000;\"><strong>Spouts\u548cBolts\u8fde\u63a5\u5728\u4e00\u8d77\uff0c\u5f62\u6210\u62d3\u6251\u7ed3\u6784\u3002<\/strong><\/span>\u5b9e\u65f6\u5e94\u7528\u7a0b\u5e8f\u903b\u8f91\u5728Storm\u62d3\u6251\u4e2d\u6307\u5b9a\u3002\u7b80\u5355\u5730\u8bf4\uff0c\u62d3\u6251\u662f\u6709\u5411\u56fe\uff0c\u5176\u4e2d\u9876\u70b9\u662f\u8ba1\u7b97\uff0c\u8fb9\u7f18\u662f\u6570\u636e\u6d41\u3002<\/p>\n<p>\u7b80\u5355\u62d3\u6251\u4ecespouts\u5f00\u59cb\u3002Spouts\u5c06\u6570\u636e\u53d1\u5c04\u5230\u4e00\u4e2a\u6216\u591a\u4e2aBolts\u3002Bolt\u8868\u793a\u62d3\u6251\u4e2d\u5177\u6709\u6700\u5c0f\u5904\u7406\u903b\u8f91\u7684\u8282\u70b9\uff0c\u5e76\u4e14Bolts\u7684\u8f93\u51fa\u53ef\u4ee5\u53d1\u5c04\u5230\u53e6\u4e00\u4e2aBolts\u4f5c\u4e3a\u8f93\u5165\u3002<\/p>\n<p>Storm\u4fdd\u6301\u62d3\u6251\u59cb\u7ec8\u8fd0\u884c\uff0c\u76f4\u5230\u60a8\u7ec8\u6b62\u62d3\u6251\u3002Apache Storm\u7684\u4e3b\u8981\u5de5\u4f5c\u662f\u8fd0\u884c\u62d3\u6251\uff0c\u5e76\u5728\u7ed9\u5b9a\u65f6\u95f4\u8fd0\u884c\u4efb\u610f\u6570\u91cf\u7684\u62d3\u6251\u3002<\/p>\n<h4>\u4efb\u52a1<\/h4>\n<p>\u73b0\u5728\u4f60\u6709\u4e00\u4e2a\u5173\u4e8eSpouts\u548cBolts\u7684\u57fa\u672c\u60f3\u6cd5\u3002\u5b83\u4eec\u662f\u62d3\u6251\u7684\u6700\u5c0f\u903b\u8f91\u5355\u5143\uff0c\u5e76\u4e14\u4f7f\u7528\u5355\u4e2aSpout\u548cBolt\u9635\u5217\u6784\u5efa\u62d3\u6251\u3002\u5e94\u4ee5\u7279\u5b9a\u987a\u5e8f\u6b63\u786e\u6267\u884c\u5b83\u4eec\uff0c\u4ee5\u4f7f\u62d3\u6251\u6210\u529f\u8fd0\u884c\u3002Storm\u6267\u884c\u7684\u6bcf\u4e2aSpout\u548cBolt\u79f0\u4e3a\u201c\u4efb\u52a1\u201d\u3002\u7b80\u5355\u6765\u8bf4\uff0c\u4efb\u52a1\u662fSpouts\u6216Bolts\u7684\u6267\u884c\u3002\u5728\u7ed9\u5b9a\u65f6\u95f4\uff0c\u6bcf\u4e2aSpout\u548cBolt\u53ef\u4ee5\u5177\u6709\u5728\u591a\u4e2a\u5355\u72ec\u7684\u87ba\u7eb9\u4e2d\u8fd0\u884c\u7684\u591a\u4e2a\u5b9e\u4f8b\u3002<\/p>\n<h4>\u8fdb\u7a0b<\/h4>\n<p>\u62d3\u6251\u5728\u591a\u4e2a\u5de5\u4f5c\u8282\u70b9\u4e0a\u4ee5\u5206\u5e03\u5f0f\u65b9\u5f0f\u8fd0\u884c\u3002Storm\u5c06\u6240\u6709\u5de5\u4f5c\u8282\u70b9\u4e0a\u7684\u4efb\u52a1\u5747\u5300\u5206\u5e03\u3002\u5de5\u4f5c\u8282\u70b9\u7684\u89d2\u8272\u662f\u76d1\u542c\u4f5c\u4e1a\uff0c\u5e76\u5728\u65b0\u4f5c\u4e1a\u5230\u8fbe\u65f6\u542f\u52a8\u6216\u505c\u6b62\u8fdb\u7a0b\u3002<\/p>\n<h2>\u56db\u3001Apache Storm\u7684\u96c6\u7fa4\u67b6\u6784<\/h2>\n<p>Apache Storm\u7684\u4e3b\u8981\u4eae\u70b9\u662f\uff0c\u5b83\u662f\u4e00\u4e2a\u5bb9\u9519\uff0c\u5feb\u901f\uff0c\u6ca1\u6709\u201c\u5355\u70b9\u6545\u969c\u201d\uff08SPOF\uff09\u5206\u5e03\u5f0f\u5e94\u7528\u7a0b\u5e8f\u3002\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u9700\u8981\u5728\u591a\u4e2a\u7cfb\u7edf\u4e2d\u5b89\u88c5Apache Storm\uff0c\u4ee5\u589e\u52a0\u5e94\u7528\u7a0b\u5e8f\u7684\u5bb9\u91cf\u3002<\/p>\n<p>\u8ba9\u6211\u4eec\u770b\u770bApache Storm\u96c6\u7fa4\u5982\u4f55\u8bbe\u8ba1\u548c\u5176\u5185\u90e8\u67b6\u6784\u3002\u4e0b\u56fe\u63cf\u8ff0\u4e86\u96c6\u7fa4\u8bbe\u8ba1\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.w3cschool.cn\/attachments\/tuploads\/apache_storm\/zookeeper_framework.jpg\" alt=\"\u52a8\u7269\u56ed\u7ba1\u7406\u5458\u6846\u67b6\" \/><\/p>\n<p>Apache Storm\u6709\u4e24\u79cd\u7c7b\u578b\u7684\u8282\u70b9\uff0cNimbus\uff08\u4e3b\u8282\u70b9\uff09\u548cSupervisor\uff08\u5de5\u4f5c\u8282\u70b9\uff09\u3002Nimbus\u662fApache Storm\u7684\u6838\u5fc3\u7ec4\u4ef6\u3002Nimbus\u7684\u4e3b\u8981\u5de5\u4f5c\u662f\u8fd0\u884cStorm\u62d3\u6251\u3002Nimbus\u5206\u6790\u62d3\u6251\u5e76\u6536\u96c6\u8981\u6267\u884c\u7684\u4efb\u52a1\u3002\u7136\u540e\uff0c\u5b83\u5c06\u4efb\u52a1\u5206\u914d\u7ed9\u53ef\u7528\u7684supervisor\u3002<\/p>\n<p>Supervisor\u5c06\u6709\u4e00\u4e2a\u6216\u591a\u4e2a\u5de5\u4f5c\u8fdb\u7a0b\u3002Supervisor\u5c06\u4efb\u52a1\u59d4\u6d3e\u7ed9\u5de5\u4f5c\u8fdb\u7a0b\u3002\u5de5\u4f5c\u8fdb\u7a0b\u5c06\u6839\u636e\u9700\u8981\u4ea7\u751f\u5c3d\u53ef\u80fd\u591a\u7684\u6267\u884c\u5668\u5e76\u8fd0\u884c\u4efb\u52a1\u3002Apache Storm\u4f7f\u7528\u5185\u90e8\u5206\u5e03\u5f0f\u6d88\u606f\u4f20\u9012\u7cfb\u7edf\u6765\u8fdb\u884cNimbus\u548c\u7ba1\u7406\u7a0b\u5e8f\u4e4b\u95f4\u7684\u901a\u4fe1\u3002<\/p>\n<table class=\"table table-bordered \">\n<tbody>\n<tr>\n<th>\u7ec4\u4ef6<\/th>\n<th>\u63cf\u8ff0<\/th>\n<\/tr>\n<tr>\n<td>Nimbus\uff08\u4e3b\u8282\u70b9\uff09<\/td>\n<td>Nimbus\u662fStorm\u96c6\u7fa4\u7684\u4e3b\u8282\u70b9\u3002\u96c6\u7fa4\u4e2d\u7684\u6240\u6709\u5176\u4ed6\u8282\u70b9\u79f0\u4e3a\u5de5\u4f5c\u8282\u70b9\u3002\u4e3b\u8282\u70b9\u8d1f\u8d23\u5728\u6240\u6709\u5de5\u4f5c\u8282\u70b9\u4e4b\u95f4\u5206\u53d1\u6570\u636e\uff0c\u5411\u5de5\u4f5c\u8282\u70b9\u5206\u914d\u4efb\u52a1\u548c\u76d1\u89c6\u6545\u969c\u3002<\/td>\n<\/tr>\n<tr>\n<td>Supervisor\uff08\u5de5\u4f5c\u8282\u70b9\uff09<\/td>\n<td>\u9075\u5faa\u6307\u4ee4\u7684\u8282\u70b9\u88ab\u79f0\u4e3a<strong>Supervisors<\/strong>\u3002Supervisor\u6709\u591a\u4e2a\u5de5\u4f5c\u8fdb\u7a0b\uff0c\u5b83\u7ba1\u7406\u5de5\u4f5c\u8fdb\u7a0b\u4ee5\u5b8c\u6210\u7531nimbus\u5206\u914d\u7684\u4efb\u52a1\u3002<\/td>\n<\/tr>\n<tr>\n<td>Worker process\uff08\u5de5\u4f5c\u8fdb\u7a0b\uff09<\/td>\n<td>\u5de5\u4f5c\u8fdb\u7a0b\u5c06\u6267\u884c\u4e0e\u7279\u5b9a\u62d3\u6251\u76f8\u5173\u7684\u4efb\u52a1\u3002\u5de5\u4f5c\u8fdb\u7a0b\u4e0d\u4f1a\u81ea\u5df1\u8fd0\u884c\u4efb\u52a1\uff0c\u800c\u662f\u521b\u5efa\u6267\u884c\u5668\u5e76\u8981\u6c42\u4ed6\u4eec\u6267\u884c\u7279\u5b9a\u7684\u4efb\u52a1\u3002\u5de5\u4f5c\u8fdb\u7a0b\u5c06\u6709\u591a\u4e2a\u6267\u884c\u5668\u3002<\/td>\n<\/tr>\n<tr>\n<td>Executor\uff08\u6267\u884c\u8005\uff09<\/td>\n<td>\u6267\u884c\u5668\u53ea\u662f\u5de5\u4f5c\u8fdb\u7a0b\u4ea7\u751f\u7684\u5355\u4e2a\u7ebf\u7a0b\u3002\u6267\u884c\u5668\u8fd0\u884c\u4e00\u4e2a\u6216\u591a\u4e2a\u4efb\u52a1\uff0c\u4f46\u4ec5\u7528\u4e8e\u7279\u5b9a\u7684spout\u6216bolt\u3002<\/td>\n<\/tr>\n<tr>\n<td>Task\uff08\u4efb\u52a1\uff09<\/td>\n<td>\u4efb\u52a1\u6267\u884c\u5b9e\u9645\u7684\u6570\u636e\u5904\u7406\u3002\u6240\u4ee5\uff0c\u5b83\u662f\u4e00\u4e2aspout\u6216bolt\u3002<\/td>\n<\/tr>\n<tr>\n<td>ZooKeeper framework\uff08ZooKeeper\u6846\u67b6\uff09<\/td>\n<td>Apache\u7684ZooKeeper\u7684\u662f\u4f7f\u7528\u7fa4\u96c6\uff08\u8282\u70b9\u7ec4\uff09\u81ea\u5df1\u548c\u7ef4\u62a4\u5177\u6709\u5f3a\u5927\u7684\u540c\u6b65\u6280\u672f\u5171\u4eab\u6570\u636e\u4e4b\u95f4\u8fdb\u884c\u534f\u8c03\u7684\u670d\u52a1\u3002Nimbus\u662f\u65e0\u72b6\u6001\u7684\uff0c\u6240\u4ee5\u5b83\u4f9d\u8d56\u4e8eZooKeeper\u6765\u76d1\u89c6\u5de5\u4f5c\u8282\u70b9\u7684\u72b6\u6001\u3002<\/p>\n<p>ZooKeeper\u7684\u5e2e\u52a9supervisor\u4e0enimbus\u4ea4\u4e92\u3002\u5b83\u8d1f\u8d23\u7ef4\u6301nimbus\uff0csupervisor\u7684\u72b6\u6001\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Storm\u662f\u65e0\u72b6\u6001\u7684\u3002\u5373\u4f7f\u65e0\u72b6\u6001\u6027\u8d28\u6709\u5b83\u81ea\u5df1\u7684\u7f3a\u70b9\uff0c\u5b83\u5b9e\u9645\u4e0a\u5e2e\u52a9Storm\u4ee5\u6700\u597d\u7684\u53ef\u80fd\u548c\u6700\u5feb\u7684\u65b9\u5f0f\u5904\u7406\u5b9e\u65f6\u6570\u636e\u3002<\/p>\n<p>Storm\u867d\u7136\u4e0d\u662f\u5b8c\u5168\u65e0\u72b6\u6001\u7684\u3002\u5b83\u5c06\u5176\u72b6\u6001\u5b58\u50a8\u5728Apache ZooKeeper\u4e2d\u3002\u7531\u4e8e\u72b6\u6001\u5728Apache ZooKeeper\u4e2d\u53ef\u7528\uff0c\u6545\u969c\u7684\u7f51\u7edc\u53ef\u4ee5\u91cd\u65b0\u542f\u52a8\uff0c\u5e76\u4ece\u5b83\u79bb\u5f00\u7684\u5730\u65b9\u5de5\u4f5c\u3002\u901a\u5e38\uff0c\u50cfmonit\u8fd9\u6837\u7684\u670d\u52a1\u76d1\u89c6\u5de5\u5177\u5c06\u76d1\u89c6Nimbus\uff0c\u5e76\u5728\u51fa\u73b0\u4efb\u4f55\u6545\u969c\u65f6\u91cd\u65b0\u542f\u52a8\u5b83\u3002<\/p>\n<h2>\u4e94\u3001Apache Storm\u7684\u5165\u95e8\u5b9e\u4f8b<\/h2>\n<p>HelloWorldSpout.java<\/p>\n<pre class=\"lang:default decode:true\" title=\"HelloWorldSpout.java\">public class HelloWorldSpout extends BaseRichSpout{\r\n    private SpoutOutputCollector collector;\r\n    private int referenceRandom;\r\n    private static final int MAX_RANDOM = 10;\r\n\r\n    public HelloWorldSpout() {\r\n        final Random rand = new Random();\r\n        referenceRandom = rand.nextInt(MAX_RANDOM);\r\n    }\r\n\r\n    \/*\r\n     * declareOutputFields() =&gt; you need to tell the Storm cluster which fields this Spout emits within the\r\n     *  declareOutputFields method.\r\n     *\/\r\n    @Override\r\n    public void declareOutputFields(OutputFieldsDeclarer declarer) {\r\n        declarer.declare(new Fields(\"sentence\"));\r\n    }\r\n\r\n    \/*\r\n     * open() =&gt; The first method called in any spout is 'open'\r\n     *           TopologyContext =&gt; contains all our topology data\r\n     *           SpoutOutputCollector =&gt; enables us to emit the data that will be processed by the bolts\r\n     *           conf =&gt; created in the topology definition\r\n     *\/\r\n    @Override\r\n    public void open(Map conf, TopologyContext topologyContext, SpoutOutputCollector collector) {\r\n        this.collector = collector;\r\n    }\r\n\r\n    \/*\r\n     * nextTuple() =&gt; Storm cluster will repeatedly call the nextTuple method which will do all the work of the spout.\r\n     *  nextTuple() must release the control of the thread when there is no work to do so that the other methods have\r\n     *  a chance to be called.\r\n     *\/\r\n    @Override\r\n    public void nextTuple() {\r\n        final Random rand = new Random();\r\n        int instanceRandom = rand.nextInt(MAX_RANDOM);\r\n        if(instanceRandom == referenceRandom){\r\n            collector.emit(new Values(\"Hello World\"));\r\n        } else {\r\n            collector.emit(new Values(\"Other Random Word\"));\r\n        }\r\n    }\r\n}<\/pre>\n<hr \/>\n<p>HelloWorldBolt.java<\/p>\n<pre class=\"lang:default decode:true\" title=\"HelloWorldBolt.java\">public class HelloWorldBolt extends BaseRichBolt {\r\n    private int myCount = 0;\r\n\r\n    \/*\r\n     * prepare() =&gt; on create\r\n     *\/\r\n    @Override\r\n    public void prepare(Map map, TopologyContext topologyContext, OutputCollector outputCollector) {\r\n    }\r\n\r\n    \/*\r\n     * execute() =&gt; most important method in the bolt is execute(Tuple input), which is called once per tuple received\r\n     *  the bolt may emit several tuples for each tuple received\r\n     *\/\r\n    @Override\r\n    public void execute(Tuple tuple) {\r\n        String test = tuple.getStringByField(\"sentence\");\r\n        if(test == \"Hello World\"){\r\n            myCount++;\r\n            System.out.println(\"Found a Hello World! My Count is now: \" + Integer.toString(myCount));\r\n        }\r\n    }\r\n\r\n    \/*\r\n     * declareOutputFields =&gt; This bolt emits nothing hence no body for declareOutputFields()\r\n     *\/\r\n    @Override\r\n    public void declareOutputFields(OutputFieldsDeclarer outputFieldsDeclarer) {\r\n    }\r\n}<\/pre>\n<hr \/>\n<p>HelloWorldTopology.java<\/p>\n<pre class=\"lang:default decode:true\" title=\"HelloWorldTopology.java\">\/**\r\n * Author: ashrith\r\n * Desc: setup the topology and submit it to either a local of remote Storm cluster depending on the arguments\r\n *       passed to the main method.\r\n *\/\r\npublic class HelloWorldTopology {\r\n    \/*\r\n     * main class in which to define the topology and a LocalCluster object (enables you to test and debug the\r\n     * topology locally). In conjunction with the Config object, LocalCluster allows you to try out different\r\n     * cluster configurations.\r\n     *\r\n     * Create a topology using 'TopologyBuilder' (which will tell storm how the nodes area arranged and how they\r\n     * exchange data)\r\n     * The spout and the bolts are connected using 'ShuffleGroupings'\r\n     *\r\n     * Create a 'Config' object containing the topology configuration, which is merged with the cluster configuration\r\n     * at runtime and sent to all nodes with the prepare method\r\n     *\r\n     * Create and run the topology using 'createTopology' and 'submitTopology'\r\n     *\/\r\n    public static void main(String[] args) throws AlreadyAliveException, InvalidTopologyException {\r\n        TopologyBuilder builder = new TopologyBuilder();\r\n        builder.setSpout(\"randomHelloWorld\", new HelloWorldSpout(), 10);\r\n        builder.setBolt(\"HelloWorldBolt\", new HelloWorldBolt(), 1).shuffleGrouping(\"randomHelloWorld\");\r\n        Config conf = new Config();\r\n        conf.setDebug(true);\r\n        if(args!=null &amp;&amp; args.length &gt; 0) {\r\n            conf.setNumWorkers(3);\r\n            StormSubmitter.submitTopology(args[0], conf, builder.createTopology());\r\n        } else {\r\n            LocalCluster cluster = new LocalCluster();\r\n            cluster.submitTopology(\"test\", conf, builder.createTopology());\r\n            Utils.sleep(10000);\r\n            cluster.killTopology(\"test\");\r\n            cluster.shutdown();\r\n        }\r\n    }\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<h5 id=\"id-\u6a21\u677f-\u53c2\u8003\u94fe\u63a5\uff1a\">\u53c2\u8003\u94fe\u63a5\uff1a<\/h5>\n<ul>\n<li>Apache Storm\u6838\u5fc3\u6982\u5ff5<br \/>\n<a href=\"https:\/\/www.w3cschool.cn\/apache_storm\/apache_storm_core_concepts.html\">https:\/\/www.w3cschool.cn\/apache_storm\/apache_storm_core_concepts.html<\/a><br \/>\nApache Storm\u96c6\u7fa4\u67b6\u6784<br \/>\n<a href=\"https:\/\/www.w3cschool.cn\/apache_storm\/apache_storm_cluster_architecture.html\">https:\/\/www.w3cschool.cn\/apache_storm\/apache_storm_cluster_architecture.html<\/a><br \/>\nApache Storm\u5de5\u4f5c\u5b9e\u4f8b<br \/>\n<a href=\"https:\/\/www.w3cschool.cn\/apache_storm\/apache_storm_working_example.html\">https:\/\/www.w3cschool.cn\/apache_storm\/apache_storm_working_example.html<\/a><\/li>\n<li>Storm\u6559\u7a0b<br \/>\n<a href=\"http:\/\/www.tianshouzhi.com\/api\/tutorials\/storm\">http:\/\/www.tianshouzhi.com\/api\/tutorials\/storm<\/a><\/li>\n<li>sample hello world topology with pom<br \/>\n<a href=\"https:\/\/github.com\/ashrithr\/storm-helloworld\">https:\/\/github.com\/ashrithr\/storm-helloworld<\/a><\/li>\n<li>Storm \u5165\u95e8\u6559\u7a0b<br \/>\n<a href=\"http:\/\/www.dahouduan.com\/2015\/11\/10\/storm-tutorial\/\">http:\/\/www.dahouduan.com\/2015\/11\/10\/storm-tutorial\/<\/a><\/li>\n<\/ul>\n<p>=END=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>=Start= \u7f18\u7531\uff1a \u5b66\u4e60\u3001\u63d0\u9ad8\u9700\u8981 \u6b63\u6587\uff1a \u53c2\u8003\u89e3\u7b54\uff1a \u4e00\u3001\u4ec0\u4e48\u662fApache Storm\uff1f Apache [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[935,933,934,932,936],"class_list":["post-3586","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","tag-bolt","tag-hadoop","tag-spout","tag-storm","tag-topo"],"views":22866,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/3586","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=3586"}],"version-history":[{"count":1,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/3586\/revisions"}],"predecessor-version":[{"id":3587,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/3586\/revisions\/3587"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=3586"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=3586"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=3586"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}