{"id":232,"date":"2018-03-13T09:41:15","date_gmt":"2018-03-13T01:41:15","guid":{"rendered":"http:\/\/www.max-shu.com\/blog\/?p=232"},"modified":"2018-03-13T13:53:00","modified_gmt":"2018-03-13T05:53:00","slug":"storm%ef%bc%88%e5%ae%9e%e6%97%b6hadoop%ef%bc%89%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"http:\/\/www.max-shu.com\/blog\/?p=232","title":{"rendered":"Storm\uff08\u5b9e\u65f6Hadoop\uff09\u6307\u5357"},"content":{"rendered":"<div>\u00a0 \u00a0Storm\u8fd9\u662f\u4e00\u4e2a\u5206\u5e03\u5f0f\u7684\u3001\u5bb9\u9519\u7684\u5b9e\u65f6\u8ba1\u7b97\u7cfb\u7edf\uff0c\u5b83\u88ab\u6258\u7ba1\u5728<a href=\"https:\/\/github.com\/nathanmarz\/storm\" rel=\"nofollow\">GitHub<\/a>\u4e0a\uff0c\u9075\u5faa\u00a0<a href=\"http:\/\/opensource.org\/licenses\/eclipse-1.0.php\" rel=\"nofollow\">Eclipse Public License 1.0<\/a>\u3002Storm\u662f\u7531BackType\u5f00\u53d1\u7684\u5b9e\u65f6\u5904\u7406\u7cfb\u7edf\uff0cBackType\u73b0\u5728\u5df2\u5728Twitter\u9ebe\u4e0b\uff0c\u57fa\u672c\u662f\u7528Clojure\u5199\u7684\u3002<\/div>\n<div>\n<div>\u00a0\u00a0\u00a0\u00a0\u00a0Storm\u4e3a\u5206\u5e03\u5f0f\u5b9e\u65f6\u8ba1\u7b97\u63d0\u4f9b\u4e86\u4e00\u7ec4\u901a\u7528\u539f\u8bed\uff0c\u53ef\u88ab\u7528\u4e8e\u201c\u6d41\u5904\u7406\u201d\u4e4b\u4e2d\uff0c\u5b9e\u65f6\u5904\u7406\u6d88\u606f\u5e76\u66f4\u65b0\u6570\u636e\u5e93\u3002\u8fd9\u662f\u7ba1\u7406\u961f\u5217\u53ca\u5de5\u4f5c\u8005\u96c6\u7fa4\u7684\u53e6\u4e00\u79cd\u65b9\u5f0f\u3002 Storm\u4e5f\u53ef\u88ab\u7528\u4e8e\u201c\u8fde\u7eed\u8ba1\u7b97\u201d\uff08continuous computation\uff09\uff0c\u5bf9\u6570\u636e\u6d41\u505a\u8fde\u7eed\u67e5\u8be2\uff0c\u5728\u8ba1\u7b97\u65f6\u5c31\u5c06\u7ed3\u679c\u4ee5\u6d41\u7684\u5f62\u5f0f\u8f93\u51fa\u7ed9\u7528\u6237\u3002\u5b83\u8fd8\u53ef\u88ab\u7528\u4e8e\u201c\u5206\u5e03\u5f0fRPC\u201d\uff0c\u4ee5\u5e76\u884c\u7684\u65b9\u5f0f\u8fd0\u884c\u6602\u8d35\u7684\u8fd0\u7b97\u3002 Storm\u7684\u4e3b\u5de5\u7a0b\u5e08Nathan Marz\u8868\u793a\uff1a<\/div>\n<div><\/div>\n<div>\u00a0\u00a0\u00a0\u00a0\u00a0Storm\u53ef\u4ee5\u65b9\u4fbf\u5730\u5728\u4e00\u4e2a\u8ba1\u7b97\u673a\u96c6\u7fa4\u4e2d\u7f16\u5199\u4e0e\u6269\u5c55\u590d\u6742\u7684\u5b9e\u65f6\u8ba1\u7b97\uff0cStorm\u4e4b\u4e8e\u5b9e\u65f6\u5904\u7406\uff0c\u5c31\u597d\u6bd4Hadoop\u4e4b\u4e8e\u6279\u5904\u7406\u3002Storm\u4fdd\u8bc1\u6bcf\u4e2a\u6d88\u606f\u90fd\u4f1a\u5f97\u5230\u5904\u7406\uff0c\u800c\u4e14\u5b83\u5f88\u5feb\u2014\u2014\u5728\u4e00\u4e2a\u5c0f\u96c6\u7fa4\u4e2d\uff0c\u6bcf\u79d2\u53ef\u4ee5\u5904\u7406\u6570\u4ee5\u767e\u4e07\u8ba1\u7684\u6d88\u606f\u3002\u66f4\u68d2\u7684\u662f\u4f60\u53ef\u4ee5\u4f7f\u7528\u4efb\u610f\u7f16\u7a0b\u8bed\u8a00\u6765\u505a\u5f00\u53d1\u3002<\/div>\n<p>Storm\u7684\u4e3b\u8981\u7279\u70b9\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\u7b80\u5355\u7684\u7f16\u7a0b\u6a21\u578b\u3002\u7c7b\u4f3c\u4e8eMapReduce\u964d\u4f4e\u4e86\u5e76\u884c\u6279\u5904\u7406\u590d\u6742\u6027\uff0cStorm\u964d\u4f4e\u4e86\u8fdb\u884c\u5b9e\u65f6\u5904\u7406\u7684\u590d\u6742\u6027\u3002<\/li>\n<li>\u53ef\u4ee5\u4f7f\u7528\u5404\u79cd\u7f16\u7a0b\u8bed\u8a00\u3002\u4f60\u53ef\u4ee5\u5728Storm\u4e4b\u4e0a\u4f7f\u7528\u5404\u79cd\u7f16\u7a0b\u8bed\u8a00\u3002\u9ed8\u8ba4\u652f\u6301Clojure\u3001Java\u3001Ruby\u548cPython\u3002\u8981\u589e\u52a0\u5bf9\u5176\u4ed6\u8bed\u8a00\u7684\u652f\u6301\uff0c\u53ea\u9700\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5355\u7684Storm\u901a\u4fe1\u534f\u8bae\u5373\u53ef\u3002<\/li>\n<li>\u5bb9\u9519\u6027\u3002Storm\u4f1a\u7ba1\u7406\u5de5\u4f5c\u8fdb\u7a0b\u548c\u8282\u70b9\u7684\u6545\u969c\u3002<\/li>\n<li>\u6c34\u5e73\u6269\u5c55\u3002\u8ba1\u7b97\u662f\u5728\u591a\u4e2a\u7ebf\u7a0b\u3001\u8fdb\u7a0b\u548c\u670d\u52a1\u5668\u4e4b\u95f4\u5e76\u884c\u8fdb\u884c\u7684\u3002<\/li>\n<li>\u53ef\u9760\u7684\u6d88\u606f\u5904\u7406\u3002Storm\u4fdd\u8bc1\u6bcf\u4e2a\u6d88\u606f\u81f3\u5c11\u80fd\u5f97\u5230\u4e00\u6b21\u5b8c\u6574\u5904\u7406\u3002\u4efb\u52a1\u5931\u8d25\u65f6\uff0c\u5b83\u4f1a\u8d1f\u8d23\u4ece\u6d88\u606f\u6e90\u91cd\u8bd5\u6d88\u606f\u3002<\/li>\n<li>\u5feb\u901f\u3002\u7cfb\u7edf\u7684\u8bbe\u8ba1\u4fdd\u8bc1\u4e86\u6d88\u606f\u80fd\u5f97\u5230\u5feb\u901f\u7684\u5904\u7406\uff0c\u4f7f\u7528?MQ\u4f5c\u4e3a\u5176\u5e95\u5c42\u6d88\u606f\u961f\u5217\u3002<\/li>\n<li>\u672c\u5730\u6a21\u5f0f\u3002Storm\u6709\u4e00\u4e2a\u201c\u672c\u5730\u6a21\u5f0f\u201d\uff0c\u53ef\u4ee5\u5728\u5904\u7406\u8fc7\u7a0b\u4e2d\u5b8c\u5168\u6a21\u62dfStorm\u96c6\u7fa4\u3002\u8fd9\u8ba9\u4f60\u53ef\u4ee5\u5feb\u901f\u8fdb\u884c\u5f00\u53d1\u548c\u5355\u5143\u6d4b\u8bd5\u3002<\/li>\n<\/ol>\n<p>Storm\u96c6\u7fa4\u7531\u4e00\u4e2a\u4e3b\u8282\u70b9\u548c\u591a\u4e2a\u5de5\u4f5c\u8282\u70b9\u7ec4\u6210\u3002\u4e3b\u8282\u70b9\u8fd0\u884c\u4e86\u4e00\u4e2a\u540d\u4e3a\u201c<span style=\"color: #ff0000;\">Nimbus<\/span>\u201d\u7684\u5b88\u62a4\u8fdb\u7a0b\uff0c\u7528\u4e8e\u5206\u914d\u4ee3\u7801\u3001\u5e03\u7f6e\u4efb\u52a1\u53ca\u6545\u969c\u68c0\u6d4b\u3002\u6bcf\u4e2a\u5de5\u4f5c\u8282 \u70b9\u90fd\u8fd0\u884c\u4e86\u4e00\u4e2a\u540d\u4e3a\u201c<span style=\"color: #ff0000;\">Supervisor<\/span>\u201d\u7684\u5b88\u62a4\u8fdb\u7a0b\uff0c\u7528\u4e8e\u76d1\u542c\u5de5\u4f5c\uff0c\u5f00\u59cb\u5e76\u7ec8\u6b62\u5de5\u4f5c\u8fdb\u7a0b\u3002Nimbus\u548cSupervisor\u90fd\u80fd\u5feb\u901f\u5931\u8d25\uff0c\u800c\u4e14\u662f\u65e0 \u72b6\u6001\u7684\uff0c\u8fd9\u6837\u4e00\u6765\u5b83\u4eec\u5c31\u53d8\u5f97\u5341\u5206\u5065\u58ee\uff0c\u4e24\u8005\u7684\u534f\u8c03\u5de5\u4f5c\u662f\u7531<a href=\"http:\/\/zookeeper.apache.org\/\" rel=\"nofollow\">Apache ZooKeeper<\/a>\u6765\u5b8c\u6210\u7684\u3002<\/p>\n<p>Storm\u7684\u672f\u8bed\u5305\u62ecStream\u3001Spout\u3001Bolt\u3001Task\u3001Worker\u3001Stream Grouping\u548cTopology\u3002Stream\u662f\u88ab\u5904\u7406\u7684\u6570\u636e\u3002<span style=\"color: #ff0000;\">Sprout<\/span>\u662f\u6570\u636e\u6e90\u3002<span style=\"color: #ff0000;\">Bolt<\/span>\u5904\u7406\u6570\u636e\u3002<span style=\"color: #ff0000;\">Task<\/span>\u662f\u8fd0\u884c\u4e8eSpout\u6216Bolt\u4e2d\u7684\u7ebf\u7a0b\u3002<span style=\"color: #ff0000;\">Worker<\/span>\u662f\u8fd0\u884c\u8fd9\u4e9b\u7ebf\u7a0b\u7684\u8fdb\u7a0b\u3002<span style=\"color: #ff0000;\">Stream Grouping<\/span>\u89c4\u5b9a\u4e86Bolt\u63a5\u6536\u4ec0\u4e48\u4e1c\u897f\u4f5c\u4e3a\u8f93\u5165\u6570\u636e\u3002\u6570\u636e\u53ef\u4ee5\u968f\u673a\u5206\u914d\uff08\u672f\u8bed\u4e3a<span style=\"color: #ff0000;\">Shuffle<\/span>\uff09\uff0c\u6216\u8005\u6839\u636e\u5b57\u6bb5\u503c\u5206\u914d\uff08\u672f\u8bed\u4e3a<span style=\"color: #ff0000;\">Fields<\/span>\uff09\uff0c\u6216\u8005 \u5e7f\u64ad\uff08\u672f\u8bed\u4e3a<span style=\"color: #ff0000;\">All<\/span>\uff09\uff0c\u6216\u8005\u603b\u662f\u53d1\u7ed9\u4e00\u4e2aTask\uff08\u672f\u8bed\u4e3a<span style=\"color: #ff0000;\">Global<\/span>\uff09\uff0c\u4e5f\u53ef\u4ee5\u4e0d\u5173\u5fc3\u8be5\u6570\u636e\uff08\u672f\u8bed\u4e3a<span style=\"color: #ff0000;\">None<\/span>\uff09\uff0c\u6216\u8005\u7531\u81ea\u5b9a\u4e49\u903b\u8f91\u6765\u51b3\u5b9a\uff08\u672f\u8bed\u4e3a\u00a0<span style=\"color: #ff0000;\">Direct<\/span>\uff09\u3002<span style=\"color: #ff0000;\">Topology<\/span>\u662f\u7531Stream Grouping\u8fde\u63a5\u8d77\u6765\u7684Spout\u548cBolt\u8282\u70b9\u7f51\u7edc\u3002\u5728<a href=\"https:\/\/github.com\/nathanmarz\/storm\/wiki\/Concepts\" rel=\"nofollow\">Storm Concepts<\/a>\u9875\u9762\u91cc\u5bf9\u8fd9\u4e9b\u672f\u8bed\u6709\u66f4\u8be6\u7ec6\u7684\u63cf\u8ff0\u3002<\/p>\n<p>\u53ef\u4ee5\u548cStorm\u76f8\u63d0\u5e76\u8bba\u7684\u7cfb\u7edf\u6709<a href=\"http:\/\/esper.codehaus.org\/\" rel=\"nofollow\">Esper<\/a>\u3001<a href=\"http:\/\/www.streambase.com\/\" rel=\"nofollow\">Streambase<\/a>\u3001<a href=\"http:\/\/www.hstreaming.com\/\" rel=\"nofollow\">HStreaming<\/a>\u548c<a href=\"http:\/\/s4.io\/\" rel=\"nofollow\">Yahoo S4<\/a>\u3002\u5176\u4e2d\u548cStorm\u6700\u63a5\u8fd1\u7684\u5c31\u662fS4\u3002\u4e24\u8005\u6700\u5927\u7684\u533a\u522b\u5728\u4e8eStorm\u4f1a\u4fdd\u8bc1\u6d88\u606f\u5f97\u5230\u5904\u7406\u3002\u8fd9\u4e9b\u7cfb\u7edf\u4e2d\u6709\u7684\u62e5\u6709\u5185\u5efa\u6570\u636e\u5b58\u50a8\u5c42\uff0c\u8fd9\u662fStorm\u6240\u6ca1\u6709\u7684\uff0c\u5982\u679c\u9700\u8981\u6301\u4e45\u5316\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u7c7b\u4f3c\u4e8eCassandra\u6216Riak\u8fd9\u6837\u7684\u5916\u90e8\u6570\u636e\u5e93\u3002<\/p>\n<p>\u5165\u95e8\u7684\u6700\u4f73\u9014\u5f84\u662f\u9605\u8bfbGitHub\u4e0a\u7684\u5b98\u65b9<a href=\"https:\/\/github.com\/nathanmarz\/storm\/wiki\/Tutorial\" rel=\"nofollow\">\u300aStorm Tutorial\u300b<\/a>\u3002 \u5176\u4e2d\u8ba8\u8bba\u4e86\u591a\u79cdStorm\u6982\u5ff5\u548c\u62bd\u8c61\uff0c\u63d0\u4f9b\u4e86\u8303\u4f8b\u4ee3\u7801\u4ee5\u4fbf\u4f60\u53ef\u4ee5\u8fd0\u884c\u4e00\u4e2aStorm Topology\u3002\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u4ee5\u7528\u672c\u5730\u6a21\u5f0f\u6765\u8fd0\u884cStorm\uff0c\u8fd9\u6837\u5c31\u80fd\u5728\u672c\u5730\u5f00\u53d1\uff0c\u5728\u8fdb\u7a0b\u4e2d\u6d4b\u8bd5Topology\u3002\u4e00\u5207\u5c31\u7eea\u540e\uff0c\u4ee5\u8fdc\u7a0b\u6a21\u5f0f\u8fd0\u884c Storm\uff0c\u63d0\u4ea4\u7528\u4e8e\u5728\u96c6\u7fa4\u4e2d\u8fd0\u884c\u7684Topology\u3002Maven\u7528\u6237\u53ef\u4ee5\u4f7f\u7528clojars.org\u63d0\u4f9b\u7684Storm\u4f9d\u8d56\uff0c\u5730\u5740\u662f http:\/\/clojars.org\/repo\u3002<\/p>\n<div>\u8981\u8fd0\u884cStorm\u96c6\u7fa4\uff0c\u4f60\u9700\u8981<a href=\"http:\/\/zookeeper.apache.org\/\" rel=\"nofollow\">Apache Zookeeper<\/a>\u3001<a href=\"http:\/\/www.zeromq.org\/area:download\" rel=\"nofollow\">?MQ<\/a>\u3001<a href=\"https:\/\/github.com\/zeromq\/jzmq\" rel=\"nofollow\">JZMQ<\/a>\u3001Java 6\u548cPython 2.6.6\u3002ZooKeeper\u7528\u4e8e\u7ba1\u7406\u96c6\u7fa4\u4e2d\u7684\u4e0d\u540c\u7ec4\u4ef6\uff0c?MQ\u662f\u5185\u90e8\u6d88\u606f\u7cfb\u7edf\uff0cJZMQ\u662f?MQ\u7684Java Binding\u3002\u6709\u4e2a\u540d\u4e3a<a href=\"https:\/\/github.com\/nathanmarz\/storm-deploy\" rel=\"nofollow\">storm-deploy<\/a>\u7684\u5b50\u9879\u76ee\uff0c\u53ef\u4ee5\u5728AWS\u4e0a\u4e00\u952e\u90e8\u7f72Storm\u96c6\u7fa4\u3002<\/div>\n<\/div>\n<div><\/div>\n<div><b>Storm\u6307\u5357<\/b><\/div>\n<div><\/div>\n<div>\n<p>\u5728\u8fd9\u4e2a\u6559\u7a0b\u91cc\u9762\u6211\u4eec\u5c06\u5b66\u4e60\u5982\u4f55\u521b\u5efaTopologies, \u5e76\u4e14\u628atopologies\u90e8\u7f72\u5230storm\u7684\u96c6\u7fa4\u91cc\u9762\u53bb\u3002Java\u5c06\u662f\u6211\u4eec\u4e3b\u8981\u7684\u793a\u8303\u8bed\u8a00\uff0c \u4e2a\u522b\u4f8b\u5b50\u4f1a\u4f7f\u7528python\u4ee5\u6f14\u793astorm\u7684\u591a\u8bed\u8a00\u7279\u6027\u3002<\/p>\n<h2>\u51c6\u5907\u5de5\u4f5c<\/h2>\n<p>\u8fd9\u4e2a\u6559\u7a0b\u4f7f\u7528<a href=\"http:\/\/github.com\/nathanmarz\/storm-starter\" rel=\"nofollow\">storm-starter<\/a>\u9879\u76ee\u91cc\u9762\u7684\u4f8b\u5b50\u3002\u6211\u63a8\u8350\u4f60\u4eec\u4e0b\u8f7d\u8fd9\u4e2a\u9879\u76ee\u7684\u4ee3\u7801\u5e76\u4e14\u8ddf\u7740\u6559\u7a0b\u4e00\u8d77\u505a\u3002\u5148\u8bfb\u4e00\u4e0b\uff1a\u914d\u7f6estorm\u5f00\u53d1\u73af\u5883\u548c\u65b0\u5efa\u4e00\u4e2astrom\u9879\u76ee\u8fd9\u4e24\u7bc7\u6587\u7ae0\u628a\u4f60\u7684\u673a\u5668\u8bbe\u7f6e\u597d\u3002<\/p>\n<h2>\u4e00\u4e2aStorm\u96c6\u7fa4\u7684\u57fa\u672c\u7ec4\u4ef6<\/h2>\n<p>storm\u7684\u96c6\u7fa4\u8868\u9762\u4e0a\u770b\u548chadoop\u7684\u96c6\u7fa4\u975e\u5e38\u50cf\u3002\u4f46\u662f\u5728Hadoop\u4e0a\u9762\u4f60\u8fd0\u884c\u7684\u662fMapReduce\u7684Job, \u800c\u5728Storm\u4e0a\u9762\u4f60\u8fd0\u884c\u7684\u662fTopology\u3002\u5b83\u4eec\u662f\u975e\u5e38\u4e0d\u4e00\u6837\u7684 \u2014 \u4e00\u4e2a\u5173\u952e\u7684\u533a\u522b\u662f\uff1a \u4e00\u4e2aMapReduce Job\u6700\u7ec8\u4f1a\u7ed3\u675f\uff0c \u800c\u4e00\u4e2aTopology\u8fd0\u6c38\u8fdc\u8fd0\u884c\uff08\u9664\u975e\u4f60\u663e\u5f0f\u7684\u6740\u6389\u4ed6\uff09\u3002<\/p>\n<p>\u5728Storm\u7684\u96c6\u7fa4\u91cc\u9762\u6709\u4e24\u79cd\u8282\u70b9\uff1a \u63a7\u5236\u8282\u70b9(master node)\u548c\u5de5\u4f5c\u8282\u70b9(worker node)\u3002\u63a7\u5236\u8282\u70b9\u4e0a\u9762\u8fd0\u884c\u4e00\u4e2a\u540e\u53f0\u7a0b\u5e8f\uff1a Nimbus\uff0c \u5b83\u7684\u4f5c\u7528\u7c7b\u4f3cHadoop\u91cc\u9762\u7684JobTracker\u3002Nimbus\u8d1f\u8d23\u5728\u96c6\u7fa4\u91cc\u9762\u5206\u5e03\u4ee3\u7801\uff0c\u5206\u914d\u5de5\u4f5c\u7ed9\u673a\u5668\uff0c \u5e76\u4e14\u76d1\u63a7\u72b6\u6001\u3002<\/p>\n<p>\u6bcf\u4e00\u4e2a\u5de5\u4f5c\u8282\u70b9\u4e0a\u9762\u8fd0\u884c\u4e00\u4e2a\u53eb\u505aSupervisor\u7684\u8282\u70b9\u3002Supervisor\u4f1a\u76d1\u542c\u5206\u914d\u7ed9\u5b83\u90a3\u53f0\u673a\u5668\u7684\u5de5\u4f5c\uff0c\u6839\u636e\u9700\u8981 \u542f\u52a8\/\u5173\u95ed\u5de5\u4f5c\u8fdb\u7a0b\u3002\u6bcf\u4e00\u4e2a\u5de5\u4f5c\u8fdb\u7a0b\u6267\u884c\u4e00\u4e2aTopology\u7684\u4e00\u4e2a\u5b50\u96c6\uff1b\u4e00\u4e2a\u8fd0\u884c\u7684Topology\u7531\u8fd0\u884c\u5728\u5f88\u591a\u673a\u5668\u4e0a\u7684\u5f88\u591a\u5de5\u4f5c\u8fdb\u7a0b\u7ec4\u6210\u3002<\/p>\n<div>\n<div><img decoding=\"async\" src=\"https:\/\/github.com\/nathanmarz\/storm\/wiki\/images\/storm-cluster.png\" alt=\"Storm\uff08\u5b9e\u65f6Hadoop\uff09\u6307\u5357 - \u89c1\u9f99\u5728\u5929 - \u89c1\u9f99\u5728\u5929\" \/><\/div>\n<p>storm topology\u7ed3\u6784<\/p>\n<\/div>\n<p>Nimbus\u548cSupervisor\u4e4b\u95f4\u7684\u6240\u6709\u534f\u8c03\u5de5\u4f5c\u90fd\u662f\u901a\u8fc7\u4e00\u4e2aZookeeper\u96c6\u7fa4\u6765\u5b8c\u6210\u3002\u5e76\u4e14\uff0cnimbus\u8fdb\u7a0b\u548csupervisor \u7ecf\u5e38\u90fd\u662f\u5feb\u901f\u5931\u8d25\uff08fail-fast)\u548c\u65e0\u72b6\u6001\u7684\u3002\u6240\u6709\u7684\u72b6\u6001\u8981\u4e48\u5728Zookeeper\u91cc\u9762\uff0c \u8981\u4e48\u5728\u672c\u5730\u78c1\u76d8\u4e0a\u3002\u8fd9\u4e5f\u5c31\u610f\u5473\u7740\u4f60\u53ef\u4ee5\u7528kill -9\u6765\u6740\u6b7bnimbus\u548csupervisor\u8fdb\u7a0b\uff0c \u7136\u540e\u518d\u91cd\u542f\u5b83\u4eec\uff0c\u5b83\u4eec\u53ef\u4ee5\u7ee7\u7eed\u5de5\u4f5c\uff0c \u5c31\u597d\u50cf\u4ec0\u4e48\u90fd\u6ca1\u6709\u53d1\u751f\u8fc7\u4f3c\u7684\u3002\u8fd9\u4e2a\u8bbe\u8ba1\u4f7f\u5f97storm\u4e0d\u53ef\u601d\u8bae\u7684\u7a33\u5b9a\u3002<\/p>\n<h2>Topologies<\/h2>\n<p>\u4e3a\u4e86\u5728storm\u4e0a\u9762\u505a\u5b9e\u65f6\u8ba1\u7b97\uff0c \u4f60\u8981\u53bb\u5efa\u7acb\u4e00\u4e9btopologies\u3002\u4e00\u4e2atopology\u5c31\u662f\u4e00\u4e2a\u8ba1\u7b97\u8282\u70b9\u6240\u7ec4\u6210\u7684\u56fe\u3002Topology\u91cc\u9762\u7684\u6bcf\u4e2a\u5904\u7406\u8282\u70b9\u90fd\u5305\u542b\u5904\u7406\u903b\u8f91\uff0c \u800c\u8282\u70b9\u4e4b\u95f4\u7684\u8fde\u63a5\u5219\u8868\u793a\u6570\u636e\u6d41\u52a8\u7684\u65b9\u5411\u3002<\/p>\n<p>\u8fd0\u884c\u4e00\u4e2aTopology\u662f\u5f88\u7b80\u5355\u7684\u3002\u9996\u5148\uff0c\u628a\u4f60\u6240\u6709\u7684\u4ee3\u7801\u5df2\u7ecf\u6240\u4f9d\u8d56\u7684jar\u6253\u8fdb\u4e00\u4e2ajar\u5305\u3002\u7136\u540e\u8fd0\u884c\u7c7b\u4f3c\u4e0b\u9762\u7684\u8fd9\u4e2a\u547d\u4ee4\u3002<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><\/pre>\n<\/td>\n<td>\n<pre>strom jar all-your-code.jar backtype.storm.MyTopology arg1 arg2<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u8fd0\u884c\u4e3b\u7c7b: backtype.strom.MyTopology, \u53c2\u6570\u662farg1, arg2\u3002\u8fd9\u4e2a\u7c7b\u7684main\u51fd\u6570\u5b9a\u4e49\u8fd9\u4e2atopology\u5e76\u4e14\u628a\u5b83\u63d0\u4ea4\u7ed9Nimbus\u3002storm jar\u8d1f\u8d23\u8fde\u63a5\u5230nimbus\u5e76\u4e14\u4e0a\u4f20jar\u6587\u4ef6\u3002<\/p>\n<p>\u56e0\u4e3atopology\u7684\u5b9a\u4e49\u5176\u5b9e\u5c31\u662f\u4e00\u4e2aThrift\u7ed3\u6784\u5e76\u4e14nimbus\u5c31\u662f\u4e00\u4e2aThrift\u670d\u52a1\uff0c \u6709\u53ef\u4ee5\u7528\u4efb\u4f55\u8bed\u8a00\u521b\u5efa\u5e76\u4e14\u63d0\u4ea4topology\u3002\u4e0a\u9762\u7684\u65b9\u9762\u662f\u7528JVM<br \/>\n-based\u8bed\u8a00\u63d0\u4ea4\u7684\u6700\u7b80\u5355\u7684\u65b9\u6cd5, \u770b\u4e00\u4e0b\u6587\u7ae0: Running topologies on a production cluster\u53bb\u770b\u770b\u600e\u4e48\u542f\u52a8\u548c\u505c\u6b62topologies\u3002<\/p>\n<h2>Stream<\/h2>\n<p>Stream\u662fstorm\u91cc\u9762\u7684\u5173\u952e\u62bd\u8c61\u3002\u4e00\u4e2astream\u662f\u4e00\u4e2a\u6ca1\u6709\u8fb9\u754c\u7684tuple\u5e8f\u5217\u3002storm\u63d0\u4f9b\u4e00\u4e9b\u8bed\u8a00\u6765\u4ee5\u5206\u5e03\u5f0f\u5730\uff0c\u53ef\u9760\u5730\u628a\u4e00\u4e2astream\u4f20\u8f93\u8fdb\u4e00\u4e2a\u65b0\u7684stream\u3002\u6bd4\u5982\uff1a \u4f60\u53ef\u4ee5\u628a\u4e00\u4e2atweets\u6d41\u4f20\u8f93\u5230\u70ed\u95e8\u8bdd\u9898\u7684\u6d41\u3002<\/p>\n<p>storm\u63d0\u4f9b\u7684\u6700\u57fa\u672c\u7684\u5904\u7406stream\u7684\u539f\u8bed\u662fspout\u548cbolt\u3002Spout\u548cbolt\u6709\u63a5\u53e3\u53ef\u4ee5\u5b9e\u73b0\u4ee5\u8ba9\u4f60\u5b9e\u73b0\u4f60\u7684\u5e94\u7528\u7684\u903b\u8f91\u3002<\/p>\n<p>spout\u7684\u6d41\u7684\u6e90\u5934\u3002\u6bd4\u5982\u4e00\u4e2aspout\u53ef\u80fd\u4eceKestrel\u961f\u5217\u91cc\u9762\u8bfb\u53d6\u6d88\u606f\u5e76\u4e14\u628a\u8fd9\u4e9b\u6d88\u606f\u53d1\u5c04\u6210\u4e00\u4e2a\u6d41\u3002\u53c8\u6bd4\u5982\u4e00\u4e2aspout\u53ef\u4ee5\u8c03\u7528twitter\u7684\u4e00\u4e2aapi\u5e76\u4e14\u628a\u8fd4\u56de\u7684tweets\u53d1\u5c04\u6210\u4e00\u4e2a\u6d41\u3002<\/p>\n<p>bolt\u53ef\u4ee5\u63a5\u6536\u4efb\u610f\u591a\u4e2a\u8f93\u5165stream\uff0c \u4f5c\u4e00\u4e9b\u5904\u7406\uff0c \u6709\u4e9bbolt\u53ef\u80fd\u8fd8\u4f1a\u53d1\u5c04\u4e00\u4e9b\u65b0\u7684stream\u3002\u4e00\u4e9b\u590d\u6742\u7684\u6d41\u8f6c\u6362\uff0c \u6bd4\u5982\u4ece\u4e00\u4e9btweet\u91cc\u9762\u8ba1\u7b97\u51fa\u70ed\u95e8\u8bdd\u9898\uff0c \u9700\u8981\u591a\u4e2a\u6b65\u9aa4\uff0c \u4ece\u800c\u4e5f\u5c31\u9700\u8981\u591a\u4e2abolt\u3002 Bolt\u53ef\u4ee5\u505a\u4efb\u4f55\u4e8b\u60c5: \u8fd0\u884c\u51fd\u6570\uff0c \u8fc7\u6ee4tuple, \u505a\u4e00\u4e9b\u805a\u5408\uff0c \u505a\u4e00\u4e9b\u5408\u5e76\u4ee5\u53ca\u8bbf\u95ee\u6570\u636e\u5e93\u7b49\u7b49\u3002<\/p>\n<p>spout\u548cbolt\u6240\u7ec4\u6210\u4e00\u4e2a\u7f51\u7edc\u4f1a\u88ab\u6253\u5305\u6210topology\uff0c topology\u662fstorm\u91cc\u9762\u6700\u9ad8\u4e00\u7ea7\u7684\u62bd\u8c61\uff0c \u4f60\u53ef\u4ee5\u628atopology\u63d0\u4ea4\u7ed9storm\u7684\u96c6\u7fa4\u6765\u8fd0\u884c\u3002topology\u7684\u7ed3\u6784\u5728Topology\u90a3\u4e00\u6bb5\u5df2\u7ecf\u8bf4\u8fc7\u4e86\uff0c\u8fd9\u91cc\u5c31\u4e0d\u518d\u8d58\u8ff0\u4e86\u3002<\/p>\n<div>\n<div><img decoding=\"async\" src=\"https:\/\/github.com\/nathanmarz\/storm\/wiki\/images\/topology.png\" alt=\"Storm\uff08\u5b9e\u65f6Hadoop\uff09\u6307\u5357 - \u89c1\u9f99\u5728\u5929 - \u89c1\u9f99\u5728\u5929\" \/><\/div>\n<p>topology\u7ed3\u6784<\/p>\n<\/div>\n<p>topology\u91cc\u9762\u7684\u6bcf\u4e00\u4e2a\u8282\u70b9\u90fd\u662f\u5e76\u884c\u8fd0\u884c\u7684\u3002 \u5728\u4f60\u7684topology\u91cc\u9762\uff0c \u4f60\u53ef\u4ee5\u6307\u5b9a\u6bcf\u4e2a\u8282\u70b9\u7684\u5e76\u884c\u5ea6\uff0c storm\u5219\u4f1a\u5728\u96c6\u7fa4\u91cc\u9762\u5206\u914d\u90a3\u4e48\u591a\u7ebf\u7a0b\u6765\u540c\u65f6\u8ba1\u7b97\u3002<\/p>\n<p>\u4e00\u4e2atopology\u4f1a\u4e00\u76f4\u8fd0\u884c\u76f4\u5230\u4f60\u6740\u6b7b\u5b83\u3002storm\u81ea\u52a8\u91cd\u65b0\u5206\u914d\u4e00\u4e9b\u8fd0\u884c\u5931\u8d25\u7684\u4efb\u52a1\uff0c \u5e76\u4e14storm\u4fdd\u8bc1\u4f60\u4e0d\u4f1a\u6709\u6570\u636e\u4e22\u5931\uff0c \u5373\u4f7f\u5728\u4e00\u4e9b\u673a\u5668\u610f\u5916\u505c\u673a\u5e76\u4e14\u6d88\u606f\u88ab\u4e22\u6389\u7684\u60c5\u51b5\u4e0b\u3002<\/p>\n<h2>\u6570\u636e\u6a21\u578b(Data Model)<\/h2>\n<p>storm\u4f7f\u7528tuple\u6765\u4f5c\u4e3a\u5b83\u7684\u6570\u636e\u6a21\u578b\u3002\u6bcf\u4e2atuple\u662f\u4e00\u5806\u503c\uff0c\u6bcf\u4e2a\u503c\u6709\u4e00\u4e2a\u540d\u5b57\uff0c\u5e76\u4e14\u6bcf\u4e2a\u503c\u53ef\u4ee5\u662f\u4efb\u4f55\u7c7b\u578b\uff0c \u5728\u6211\u7684\u7406\u89e3\u91cc\u9762\u4e00\u4e2atuple\u53ef\u4ee5\u770b\u4f5c\u4e00\u4e2a\u6ca1\u6709\u65b9\u6cd5\u7684java\u5bf9\u8c61\u3002\u603b\u4f53\u6765\u770b\uff0cstorm\u652f\u6301\u6240\u6709\u7684\u57fa\u672c\u7c7b\u578b\uff0c\u5b57\u7b26\u4e32\u4ee5\u53ca\u5b57\u8282\u6570\u7ec4\u4f5c\u4e3atuple\u7684\u503c\u7c7b \u578b\u3002\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528\u4f60\u81ea\u5df1\u5b9a\u4e49\u7684\u7c7b\u578b\u6765\u4f5c\u4e3a\u503c\u7c7b\u578b\uff0c \u53ea\u8981\u4f60\u5b9e\u73b0\u5bf9\u5e94\u7684\u5e8f\u5217\u5316\u5668(serializer)\u3002<\/p>\n<p>topology\u91cc\u9762\u7684\u6bcf\u4e2a\u8282\u70b9\u5fc5\u987b\u5b9a\u4e49\u5b83\u8981\u53d1\u5c04\u7684tuple\u7684\u6bcf\u4e2a\u5b57\u6bb5\u3002 \u6bd4\u5982\u4e0b\u9762\u8fd9\u4e2abolt\u5b9a\u4e49\u5b83\u9501\u53d1\u5c04\u7684tuple\u5305\u542b\u4e24\u4e2a\u5b57\u6bb5\uff0c\u7c7b\u578b\u5206\u522b\u662f: doble\u548ctriple\u3002<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><\/pre>\n<\/td>\n<td>\n<pre>public class DoubleAndTripleBolt implements IRichBolt {<\/pre>\n<pre>    private OutputCollectorBase _collector;<\/pre>\n<pre>     @Override<\/pre>\n<pre>    public void prepare(Map conf, TopologyContext context, OutputCollectorBase collector) {<\/pre>\n<pre>        _collector = collector;<\/pre>\n<pre>    }<\/pre>\n<pre>     @Override<\/pre>\n<pre>    public void execute(Tuple input) {<\/pre>\n<pre>        int val = input.getInteger(0);<\/pre>\n<pre>        _collector.emit(input, new Values(val*2, val*3));<\/pre>\n<pre>        _collector.ack(input);<\/pre>\n<pre>    }<\/pre>\n<pre>     @Override<\/pre>\n<pre>    public void cleanup() {<\/pre>\n<pre>    }<\/pre>\n<pre>     @Override<\/pre>\n<pre>    public void declareOutputFields(OutputFieldsDeclarer declarer) {<\/pre>\n<pre>        declarer.declare(new Fields(\"double\", \"triple\"));<\/pre>\n<pre>    }<\/pre>\n<pre>}<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>declareOutputFields\u65b9\u6cd5\u5b9a\u4e49\u8981\u8f93\u51fa\u7684\u5b57\u6bb5 \uff1a [&#8220;double&#8221;, &#8220;triple&#8221;]\u3002\u8fd9\u4e2abolt\u7684\u5176\u5b83\u90e8\u5206\u6211\u4eec\u63a5\u4e0b\u6765\u4f1a\u89e3\u91ca\u3002<\/p>\n<h2>\u4e00\u4e2a\u7b80\u5355\u7684Topology<\/h2>\n<p>\u8ba9\u6211\u4eec\u6765\u770b\u4e00\u4e2a\u7b80\u5355\u7684topology\u7684\u4f8b\u5b50\uff0c \u6211\u4eec\u770b\u4e00\u4e0bstorm-starter\u91cc\u9762\u7684ExclamationTopology:<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><\/pre>\n<\/td>\n<td>\n<pre>TopologyBuilder builder = new TopologyBuilder();<\/pre>\n<pre>builder.setSpout(1, new TestWordSpout(), 10);<\/pre>\n<pre>builder.setBolt(2, new ExclamationBolt(), 3)<\/pre>\n<pre>        .shuffleGrouping(1);<\/pre>\n<pre>builder.setBolt(3, new ExclamationBolt(), 2)<\/pre>\n<pre>        .shuffleGrouping(2);<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u8fd9\u4e2aTopology\u5305\u542b\u4e00\u4e2aSpout\u548c\u4e24\u4e2aBolt\u3002Spout\u53d1\u5c04\u5355\u8bcd\uff0c \u6bcf\u4e2abolt\u5728\u6bcf\u4e2a\u5355\u8bcd\u540e\u9762\u52a0\u4e2a\u201d!!!\u201d\u3002\u8fd9\u4e09\u4e2a\u8282\u70b9\u88ab\u6392\u6210\u4e00\u6761\u7ebf: spout\u53d1\u5c04\u5355\u8bcd\u7ed9\u7b2c\u4e00\u4e2abolt\uff0c \u7b2c\u4e00\u4e2abolt\u7136\u540e\u628a\u5904\u7406\u597d\u7684\u5355\u8bcd\u53d1\u5c04\u7ed9\u7b2c\u4e8c\u4e2abolt\u3002\u5982\u679cspout\u53d1\u5c04\u7684\u5355\u8bcd\u662f[&#8220;bob&#8221;]\u548c[&#8220;john&#8221;], \u90a3\u4e48\u7b2c\u4e8c\u4e2abolt\u4f1a\u53d1\u5c04[&#8220;bolt!!!!!!&#8221;]\u548c[&#8220;john!!!!!!&#8221;]\u51fa\u6765\u3002<\/p>\n<p>\u6211\u4eec\u4f7f\u7528setSpout\u548csetBolt\u6765\u5b9a\u4e49Topology\u91cc\u9762\u7684\u8282\u70b9\u3002\u8fd9\u4e9b\u65b9\u6cd5\u63a5\u6536\u6211\u4eec\u6307\u5b9a\u7684\u4e00\u4e2aid\uff0c \u4e00\u4e2a\u5305\u542b\u5904\u7406\u903b\u8f91\u7684\u5bf9\u8c61(spout\u6216\u8005bolt), \u4ee5\u53ca\u4f60\u6240\u9700\u8981\u7684\u5e76\u884c\u5ea6\u3002<\/p>\n<p>\u8fd9\u4e2a\u5305\u542b\u5904\u7406\u7684\u5bf9\u8c61\u5982\u679c\u662fspout\u90a3\u4e48\u8981\u5b9e\u73b0IRichSpout\u7684\u63a5\u53e3\uff0c \u5982\u679c\u662fbolt\uff0c\u90a3\u4e48\u5c31\u8981\u5b9e\u73b0IRichBolt\u63a5\u53e3.<br \/>\n\u6700\u540e\u4e00\u4e2a\u6307\u5b9a\u5e76\u884c\u5ea6\u7684\u53c2\u6570\u662f\u53ef\u9009\u7684\u3002\u5b83\u8868\u793a\u96c6\u7fa4\u91cc\u9762\u9700\u8981\u591a\u5c11\u4e2athread\u6765\u4e00\u8d77\u6267\u884c\u8fd9\u4e2a\u8282\u70b9\u3002\u5982\u679c\u4f60\u5ffd\u7565\u5b83\u90a3\u4e48storm\u4f1a\u5206\u914d\u4e00\u4e2a\u7ebf\u7a0b\u6765\u6267\u884c\u8fd9\u4e2a\u8282\u70b9\u3002<\/p>\n<p>setBolt\u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2aInputDeclarer\u5bf9\u8c61\uff0c \u8fd9\u4e2a\u5bf9\u8c61\u662f\u7528\u6765\u5b9a\u4e49Bol\u7684\u8f93\u5165\u3002 \u8fd9\u91cc\u7b2c\u4e00\u4e2aBolt\u58f0\u660e\u5b83\u8981\u8bfb\u53d6spout\u6240\u53d1\u5c04\u7684\u6240\u6709\u7684tuple \u2014 \u4f7f\u7528shuffle grouping\u3002\u800c\u7b2c\u4e8c\u4e2abolt\u58f0\u660e\u5b83\u8bfb\u53d6\u7b2c\u4e00\u4e2abolt\u6240\u53d1\u5c04\u7684tuple\u3002shuffle grouping\u8868\u793a\u6240\u6709\u7684tuple\u4f1a\u88ab\u968f\u673a\u7684\u5206\u53d1\u7ed9bolt\u7684\u6240\u6709task\u3002\u7ed9task\u5206\u53d1tuple\u7684\u7b56\u7565\u6709\u5f88\u591a\u79cd\uff0c\u540e\u9762\u4f1a\u4ecb\u7ecd\u3002<\/p>\n<p>\u5982\u679c\u4f60\u60f3\u7b2c\u4e8c\u4e2abolt\u8bfb\u53d6spout\u548c\u7b2c\u4e00\u4e2abolt\u6240\u53d1\u5c04\u7684\u6240\u6709\u7684tuple\uff0c \u90a3\u4e48\u4f60\u5e94\u8be5\u8fd9\u6837\u5b9a\u4e49\u7b2c\u4e8c\u4e2abolt:<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><\/pre>\n<\/td>\n<td>\n<pre>builder.setBolt(3, new ExclamationBolt(), 5)<\/pre>\n<pre>            .shuffleGrouping(1)<\/pre>\n<pre>            .shuffleGrouping(2);<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u8ba9\u6211\u4eec\u6df1\u5165\u5730\u770b\u4e00\u4e0b\u8fd9\u4e2atopology\u5398\u7c73\u7684spout\u548cbolt\u662f\u600e\u4e48\u5b9e\u73b0\u7684\u3002Spout\u8d1f\u8d23\u53d1\u5c04\u65b0\u7684tuple\u5230\u8fd9\u4e2atopology\u91cc\u9762 \u6765\u3002TestWordSpout\u4ece[&#8220;nathan&#8221;, &#8220;mike&#8221;, &#8220;jackson&#8221;, &#8220;golda&#8221;, &#8220;bertels&#8221;]\u91cc\u9762\u968f\u673a\u9009\u62e9\u4e00\u4e2a\u5355\u8bcd\u53d1\u5c04\u51fa\u6765\u3002TestWordSpout\u91cc\u9762\u7684nextTuple()\u65b9\u6cd5\u662f\u8fd9\u6837\u5b9a\u4e49\u7684\uff1a<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><\/pre>\n<\/td>\n<td>\n<pre>public void nextTuple() {<\/pre>\n<pre>    Utils.sleep(100);<\/pre>\n<pre>    final String[] words = new String[] {\"nathan\", \"mike\", \"jackson\", \"golda\", \"bertels\"};<\/pre>\n<pre>    final Random rand = new Random();<\/pre>\n<pre>    final String word = words[rand.nextInt(words.length)];<\/pre>\n<pre>    _collector.emit(new Values(word));<\/pre>\n<pre>}<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u5b9e\u73b0\u5f88\u7b80\u5355\u3002<br \/>\nExclamationBolt\u628a\u201d!!!\u201d\u62fc\u63a5\u5230\u8f93\u5165tuple\u540e\u9762\u3002\u6211\u4eec\u6765\u770b\u4e0bExclamationBolt\u7684\u5b8c\u6574\u5b9e\u73b0\u3002<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><\/pre>\n<\/td>\n<td>\n<pre>public static class ExclamationBolt implements IRichBolt {<\/pre>\n<pre>    OutputCollector _collector;<\/pre>\n<pre>     public void prepare(Map conf, TopologyContext context, OutputCollector collector) {<\/pre>\n<pre>        _collector = collector;<\/pre>\n<pre>    }<\/pre>\n<pre>     public void execute(Tuple tuple) {<\/pre>\n<pre>        _collector.emit(tuple, new Values(tuple.getString(0) + \"!!!\"));<\/pre>\n<pre>        _collector.ack(tuple);<\/pre>\n<pre>    }<\/pre>\n<pre>     public void cleanup() {<\/pre>\n<pre>    }<\/pre>\n<pre>     public void declareOutputFields(OutputFieldsDeclarer declarer) {<\/pre>\n<pre>        declarer.declare(new Fields(\"word\"));<\/pre>\n<pre>    }<\/pre>\n<pre>}<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>prepare\u65b9\u6cd5\u63d0\u4f9b\u7ed9bolt\u4e00\u4e2aOutputcollector\u7528\u6765\u53d1\u5c04tuple\u3002Bolt\u53ef\u4ee5\u5728\u4efb\u4f55\u65f6\u5019\u53d1\u5c04tuple \u2014 \u5728prepare, execute\u6216\u8005cleanup\u65b9\u6cd5\u91cc\u9762, \u6216\u8005\u751a\u81f3\u5728\u53e6\u4e00\u4e2a\u7ebf\u7a0b\u91cc\u9762\u5f02\u6b65\u53d1\u5c04\u3002\u8fd9\u91ccprepare\u65b9\u6cd5\u53ea\u662f\u7b80\u5355\u5730\u628aOutputCollector\u4f5c\u4e3a\u4e00\u4e2a\u7c7b\u5b57\u6bb5\u4fdd\u5b58\u4e0b\u6765\u7ed9\u540e\u9762execute\u65b9\u6cd5 \u4f7f\u7528\u3002<\/p>\n<p>execute\u65b9\u6cd5\u4ecebolt\u7684\u4e00\u4e2a\u8f93\u5165\u63a5\u6536tuple(\u4e00\u4e2abolt\u53ef\u80fd\u6709\u591a\u4e2a\u8f93\u5165\u6e90). ExclamationBolt\u83b7\u53d6tuple\u7684\u7b2c\u4e00\u4e2a\u5b57\u6bb5\uff0c\u52a0\u4e0a\u201d!!!\u201d\u4e4b\u540e\u518d\u53d1\u5c04\u51fa\u53bb\u3002\u5982\u679c\u4e00\u4e2abolt\u6709\u591a\u4e2a\u8f93\u5165\u6e90\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u8c03\u7528 Tuple#getSourceComponent\u65b9\u6cd5\u6765\u77e5\u9053\u5b83\u662f\u6765\u81ea\u54ea\u4e2a\u8f93\u5165\u6e90\u7684\u3002<\/p>\n<p>execute\u65b9\u6cd5\u91cc\u9762\u8fd8\u6709\u5176\u5b83\u4e00\u4e9b\u4e8b\u60c5\u503c\u5f97\u4e00\u63d0\uff1a \u8f93\u5165tuple\u88ab\u4f5c\u4e3aemit\u65b9\u6cd5\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\uff0c\u5e76\u4e14\u8f93\u5165tuple\u5728\u6700\u540e\u4e00\u884c\u88aback\u3002\u8fd9\u4e9b\u5462\u90fd\u662fStorm\u53ef\u9760\u6027API\u7684\u4e00\u90e8\u5206\uff0c\u540e\u9762\u4f1a\u89e3\u91ca\u3002<\/p>\n<p>cleanup\u65b9\u6cd5\u5728bolt\u88ab\u5173\u95ed\u7684\u65f6\u5019\u8c03\u7528\uff0c \u5b83\u5e94\u8be5\u6e05\u7406\u6240\u6709\u88ab\u6253\u5f00\u7684\u8d44\u6e90\u3002\u4f46\u662f\u96c6\u7fa4\u4e0d\u4fdd\u8bc1\u8fd9\u4e2a\u65b9\u6cd5\u4e00\u5b9a\u4f1a\u88ab\u6267\u884c\u3002\u6bd4\u5982\u6267\u884ctask\u7684\u673a\u5668down\u6389\u4e86\uff0c\u90a3\u4e48\u6839\u672c\u5c31\u6ca1\u6709\u529e\u6cd5\u6765\u8c03\u7528\u90a3\u4e2a\u65b9\u6cd5\u3002 cleanup\u8bbe\u8ba1\u7684\u65f6\u5019\u662f\u88ab\u7528\u6765\u5728local mode\u7684\u65f6\u5019\u624d\u88ab\u8c03\u7528(\u4e5f\u5c31\u662f\u8bf4\u5728\u4e00\u4e2a\u8fdb\u7a0b\u91cc\u9762\u6a21\u62df\u6574\u4e2astorm\u96c6\u7fa4), \u5e76\u4e14\u4f60\u60f3\u5728\u5173\u95ed\u4e00\u4e9btopology\u7684\u65f6\u5019\u907f\u514d\u8d44\u6e90\u6cc4\u6f0f\u3002<\/p>\n<p>\u6700\u540e\uff0cdeclareOutputFields\u5b9a\u4e49\u4e00\u4e2a\u53eb\u505a\u201dword\u201d\u7684\u5b57\u6bb5\u7684tuple\u3002<\/p>\n<p>\u4ee5local mode\u8fd0\u884cExclamationTopology<br \/>\n\u8ba9\u6211\u4eec\u770b\u770b\u600e\u4e48\u4ee5local mode\u8fd0\u884cExclamationToplogy\u3002<\/p>\n<p>storm\u7684\u8fd0\u884c\u6709\u4e24\u79cd\u6a21\u5f0f: \u672c\u5730\u6a21\u5f0f\u548c\u5206\u5e03\u5f0f\u6a21\u5f0f. \u5728\u672c\u5730\u6a21\u5f0f\u4e2d\uff0c storm\u7528\u4e00\u4e2a\u8fdb\u7a0b\u91cc\u9762\u7684\u7ebf\u7a0b\u6765\u6a21\u62df\u6240\u6709\u7684spout\u548cbolt. \u672c\u5730\u6a21\u5f0f\u5bf9\u5f00\u53d1\u548c\u6d4b\u8bd5\u6765\u8bf4\u6bd4\u8f83\u6709\u7528\u3002 \u4f60\u8fd0\u884cstorm-starter\u91cc\u9762\u7684topology\u7684\u65f6\u5019\u5b83\u4eec\u5c31\u662f\u4ee5\u672c\u5730\u6a21\u5f0f\u8fd0\u884c\u7684\uff0c \u4f60\u53ef\u4ee5\u770b\u5230topology\u91cc\u9762\u7684\u6bcf\u4e00\u4e2a\u7ec4\u4ef6\u5728\u53d1\u5c04\u4ec0\u4e48\u6d88\u606f\u3002<\/p>\n<p>\u5728\u5206\u5e03\u5f0f\u6a21\u5f0f\u4e0b\uff0c storm\u7531\u4e00\u5806\u673a\u5668\u7ec4\u6210\u3002\u5f53\u4f60\u63d0\u4ea4topology\u7ed9master\u7684\u65f6\u5019\uff0c \u4f60\u540c\u65f6\u4e5f\u628atopology\u7684\u4ee3\u7801\u63d0\u4ea4\u4e86\u3002master\u8d1f\u8d23\u5206\u53d1\u4f60\u7684\u4ee3\u7801\u5e76\u4e14\u8d1f\u8d23\u7ed9\u4f60\u7684topolgoy\u5206\u914d\u5de5\u4f5c\u8fdb\u7a0b\u3002\u5982\u679c\u4e00\u4e2a\u5de5\u4f5c\u8fdb\u7a0b\u6302\u6389\u4e86\uff0c master\u8282\u70b9\u4f1a\u628a\u8ba4\u4e3a\u91cd\u65b0\u5206\u914d\u5230\u5176\u5b83\u8282\u70b9\u3002\u5173\u4e8e\u5982\u4f55\u5728\u4e00\u4e2a\u96c6\u7fa4\u4e0a\u9762\u8fd0\u884ctopology\uff0c \u4f60\u53ef\u4ee5\u770b\u770bRunning topologies on a production cluster\u6587\u7ae0\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u4ee5\u672c\u5730\u6a21\u5f0f\u8fd0\u884cExclamationTopology\u7684\u4ee3\u7801:<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><\/pre>\n<\/td>\n<td>\n<pre>Config conf = new Config();<\/pre>\n<pre>conf.setDebug(true);conf.setNumWorkers(2);<\/pre>\n<pre>LocalCluster cluster = new LocalCluster();<\/pre>\n<pre>cluster.submitTopology(\"test\", conf, builder.createTopology());<\/pre>\n<pre>Utils.sleep(10000);<\/pre>\n<pre>cluster.killTopology(\"test\");<\/pre>\n<pre>cluster.shutdown();<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u9996\u5148\uff0c \u8fd9\u4e2a\u4ee3\u7801\u5b9a\u4e49\u901a\u8fc7\u5b9a\u4e49\u4e00\u4e2aLocalCluster\u5bf9\u8c61\u6765\u5b9a\u4e49\u4e00\u4e2a\u8fdb\u7a0b\u5185\u7684\u96c6\u7fa4\u3002\u63d0\u4ea4topology\u7ed9\u8fd9\u4e2a\u865a\u62df\u7684\u96c6\u7fa4\u548c\u63d0\u4ea4topology\u7ed9\u5206\u5e03\u5f0f\u96c6 \u7fa4\u662f\u4e00\u6837\u7684\u3002\u901a\u8fc7\u8c03\u7528submitTopology\u65b9\u6cd5\u6765\u63d0\u4ea4topology\uff0c \u5b83\u63a5\u53d7\u4e09\u4e2a\u53c2\u6570\uff1a\u8981\u8fd0\u884c\u7684topology\u7684\u540d\u5b57\uff0c\u4e00\u4e2a\u914d\u7f6e\u5bf9\u8c61\u4ee5\u53ca\u8981\u8fd0\u884c\u7684topology\u672c\u8eab\u3002<\/p>\n<p>topology\u7684\u540d\u5b57\u662f\u7528\u6765\u552f\u4e00\u533a\u522b\u4e00\u4e2atopology\u7684\uff0c\u8fd9\u6837\u4f60\u7136\u540e\u53ef\u4ee5\u7528\u8fd9\u4e2a\u540d\u5b57\u6765\u6740\u6b7b\u8fd9\u4e2atopology\u7684\u3002\u524d\u9762\u5df2\u7ecf\u8bf4\u8fc7\u4e86\uff0c \u4f60\u5fc5\u987b\u663e\u5f0f\u7684\u6740\u6389\u4e00\u4e2atopology\uff0c \u5426\u5219\u5b83\u4f1a\u4e00\u76f4\u8fd0\u884c\u3002<\/p>\n<p>Conf\u5bf9\u8c61\u53ef\u4ee5\u914d\u7f6e\u5f88\u591a\u4e1c\u897f\uff0c \u4e0b\u9762\u4e24\u4e2a\u662f\u6700\u5e38\u89c1\u7684\uff1a<br \/>\n1. TOPOLOGY_WORKERS(setNumWorkers) \u5b9a\u4e49\u4f60\u5e0c\u671b\u96c6\u7fa4\u5206\u914d\u591a\u5c11\u4e2a\u5de5\u4f5c\u8fdb\u7a0b\u7ed9\u4f60\u6765\u6267\u884c\u8fd9\u4e2atopology. topology\u91cc\u9762\u7684\u6bcf\u4e2a\u7ec4\u4ef6\u4f1a\u88ab\u9700\u8981\u7ebf\u7a0b\u6765\u6267\u884c\u3002\u6bcf\u4e2a\u7ec4\u4ef6\u5230\u5e95\u7528\u591a\u5c11\u4e2a\u7ebf\u7a0b\u662f\u901a\u8fc7setBolt\u548csetSpout\u6765\u6307\u5b9a\u7684\u3002\u8fd9\u4e9b\u7ebf\u7a0b\u90fd\u8fd0\u884c\u5728\u5de5\u4f5c\u8fdb \u7a0b\u91cc\u9762. \u6bcf\u4e00\u4e2a\u5de5\u4f5c\u8fdb\u7a0b\u5305\u542b\u4e00\u4e9b\u8282\u70b9\u7684\u4e00\u4e9b\u5de5\u4f5c\u7ebf\u7a0b\u3002\u6bd4\u5982\uff0c \u5982\u679c\u4f60\u6307\u5b9a300\u4e2a\u7ebf\u7a0b\uff0c60\u4e2a\u8fdb\u7a0b\uff0c \u90a3\u4e48\u6bcf\u4e2a\u5de5\u4f5c\u8fdb\u7a0b\u91cc\u9762\u8981\u6267\u884c6\u4e2a\u7ebf\u7a0b\uff0c \u800c\u8fd96\u4e2a\u7ebf\u7a0b\u53ef\u80fd\u5c5e\u4e8e\u4e0d\u540c\u7684\u7ec4\u4ef6(Spout, Bolt)\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574\u6bcf\u4e2a\u7ec4\u4ef6\u7684\u5e76\u884c\u5ea6\u4ee5\u53ca\u8fd9\u4e9b\u7ebf\u7a0b\u6240\u5728\u7684\u8fdb\u7a0b\u6570\u91cf\u6765\u8c03\u6574topology\u7684\u6027\u80fd\u3002<\/p>\n<p>2.TOPOLOGY_DEBUG(setDebug), \u5f53\u5b83\u88ab\u8bbe\u7f6e\u6210true\u7684\u8bdd\uff0c storm\u4f1a\u8bb0\u5f55\u4e0b\u6bcf\u4e2a\u7ec4\u4ef6\u6240\u53d1\u5c04\u7684\u6bcf\u6761\u6d88\u606f\u3002\u8fd9\u5728\u672c\u5730\u73af\u5883\u8c03\u8bd5topology\u5f88\u6709\u7528\uff0c \u4f46\u662f\u5728\u7ebf\u4e0a\u8fd9\u4e48\u505a\u7684\u8bdd\u4f1a\u5f71\u54cd\u6027\u80fd\u7684\u3002<\/p>\n<p>\u611f\u5174\u8da3\u7684\u8bdd\u53ef\u4ee5\u53bb\u770b\u770b<a href=\"http:\/\/nathanmarz.github.com\/storm\/doc\/backtype\/storm\/Config.html\" rel=\"nofollow\">Conf\u5bf9\u8c61\u7684Javadoc<\/a>\u53bb\u770b\u770btopology\u7684\u6240\u6709\u914d\u7f6e\u3002<br \/>\n\u53ef\u4ee5\u770b\u770b\u521b\u5efa\u4e00\u4e2a\u65b0storm\u9879\u76ee\u53bb\u770b\u770b\u600e\u4e48\u914d\u7f6e\u5f00\u53d1\u73af\u5883\u4ee5\u4f7f\u4f60\u80fd\u591f\u4ee5\u672c\u5730\u6a21\u5f0f\u8fd0\u884ctopology.<\/p>\n<h2>Stream grouping<\/h2>\n<p>Stream grouping\u544a\u8bc9topology\u5982\u4f55\u5728\u4e24\u4e2a\u7ec4\u4ef6\u4e4b\u95f4\u53d1\u9001tuple\u3002 \u8981\u8bb0\u4f4f\uff0c spouts\u548cbolts\u4ee5\u5f88\u591atask\u7684\u5f62\u5f0f\u5728topology\u91cc\u9762\u540c\u6b65\u6267\u884c\u3002\u5982\u4f55\u4ecetask\u7c92\u5ea6\u6765\u770b\u4e00\u4e2a\u8fd0\u884c\u7684topology\uff0c \u5b83\u5e94\u8be5\u662f\u8fd9\u6837\u7684:<\/p>\n<div>\n<div><img decoding=\"async\" src=\"https:\/\/github.com\/nathanmarz\/storm\/wiki\/images\/topology-tasks.png\" alt=\"Storm\uff08\u5b9e\u65f6Hadoop\uff09\u6307\u5357 - \u89c1\u9f99\u5728\u5929 - \u89c1\u9f99\u5728\u5929\" \/><\/div>\n<p>\u4ecetask\u89d2\u5ea6\u6765\u770btopology<\/p>\n<\/div>\n<p>\u5f53Bolt A\u7684\u4e00\u4e2atask\u8981\u53d1\u9001\u4e00\u4e2atuple\u7ed9Bolt B\uff0c \u5b83\u5e94\u8be5\u53d1\u9001\u7ed9Bolt B\u7684\u54ea\u4e2atask\u5462\uff1f<br \/>\nstream grouping\u4e13\u95e8\u56de\u7b54\u8fd9\u79cd\u95ee\u9898\u7684\u3002\u5728\u6211\u4eec\u6df1\u5165\u7814\u7a76\u4e0d\u540c\u7684stream grouping\u4e4b\u524d\uff0c \u8ba9\u6211\u4eec\u770b\u4e00\u4e0b<a href=\"http:\/\/github.com\/nathanmarz\/storm-starter\" rel=\"nofollow\">storm-starter<\/a>\u91cc\u9762\u7684\u53e6\u5916\u4e00\u4e2atopology\u3002WordCountTopology\u8bfb\u53d6\u4e00\u4e9b\u53e5\u5b50\uff0c \u8f93\u51fa\u53e5\u5b50\u91cc\u9762\u6bcf\u4e2a\u5355\u8bcd\u51fa\u73b0\u7684\u6b21\u6570.<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><\/pre>\n<\/td>\n<td>\n<pre>TopologyBuilder builder = new TopologyBuilder();<\/pre>\n<pre>builder.setSpout(1, new RandomSentenceSpout(), 5);<\/pre>\n<pre>builder.setBolt(2, new SplitSentence(), 8)<\/pre>\n<pre>        .shuffleGrouping(1);<\/pre>\n<pre>builder.setBolt(3, new WordCount(), 12)<\/pre>\n<pre>        .fieldsGrouping(2, new Fields(\"word\"));<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>SplitSentence\u5bf9\u4e8e\u53e5\u5b50\u91cc\u9762\u7684\u6bcf\u4e2a\u5355\u8bcd\u53d1\u5c04\u4e00\u4e2a\u65b0\u7684tuple, WordCount\u5728\u5185\u5b58\u91cc\u9762\u7ef4\u62a4\u4e00\u4e2a\u5355\u8bcd-&gt;\u6b21\u6570\u7684mapping\uff0c WordCount\u6bcf\u6536\u5230\u4e00\u4e2a\u5355\u8bcd\uff0c \u5b83\u5c31\u66f4\u65b0\u5185\u5b58\u91cc\u9762\u7684\u7edf\u8ba1\u72b6\u6001\u3002<\/p>\n<p>\u6709\u597d\u51e0\u79cd\u4e0d\u540c\u7684stream grouping:<\/p>\n<p>\u6700\u7b80\u5355\u7684grouping\u662fshuffle grouping, \u5b83\u968f\u673a\u53d1\u7ed9\u4efb\u4f55\u4e00\u4e2atask\u3002\u4e0a\u9762\u4f8b\u5b50\u91cc\u9762RandomSentenceSpout\u548cSplitSentence\u4e4b\u95f4\u7528\u7684\u5c31\u662fshuffle grouping, shuffle grouping\u5bf9\u5404\u4e2atask\u7684tuple\u5206\u914d\u7684\u6bd4\u8f83\u5747\u5300\u3002<\/p>\n<p>\u4e00\u79cd\u66f4\u6709\u8da3\u7684grouping\u662ffields grouping, SplitSentence\u548cWordCount\u4e4b\u95f4\u4f7f\u7528\u7684\u5c31\u662ffields grouping, \u8fd9\u79cdgrouping\u673a\u5236\u4fdd\u8bc1\u76f8\u540cfield\u503c\u7684tuple\u4f1a\u53bb\u540c\u4e00\u4e2atask\uff0c \u8fd9\u5bf9\u4e8eWordCount\u6765\u8bf4\u975e\u5e38\u5173\u952e\uff0c\u5982\u679c\u540c\u4e00\u4e2a\u5355\u8bcd\u4e0d\u53bb\u540c\u4e00\u4e2atask\uff0c \u90a3\u4e48\u7edf\u8ba1\u51fa\u6765\u7684\u5355\u8bcd\u6b21\u6570\u5c31\u4e0d\u5bf9\u4e86\u3002<\/p>\n<p>fields grouping\u662fstream\u5408\u5e76\uff0cstream\u805a\u5408\u4ee5\u53ca\u5f88\u591a\u5176\u5b83\u573a\u666f\u7684\u57fa\u7840\u3002\u5728\u80cc\u540e\u5462\uff0c fields grouping\u4f7f\u7528\u7684\u4e00\u81f4\u6027\u54c8\u5e0c\u6765\u5206\u914dtuple\u7684\u3002<\/p>\n<p>\u8fd8\u6709\u4e00\u4e9b\u5176\u5b83\u7c7b\u578b\u7684stream grouping. \u4f60\u53ef\u4ee5\u5728Concepts\u4e00\u7ae0\u91cc\u66f4\u8be6\u7ec6\u7684\u4e86\u89e3\u3002<\/p>\n<h2>\u4f7f\u7528\u522b\u7684\u8bed\u8a00\u6765\u5b9a\u4e49Bolt<\/h2>\n<p>Bolt\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u8bed\u8a00\u6765\u5b9a\u4e49\u3002\u7528\u5176\u5b83\u8bed\u8a00\u5b9a\u4e49\u7684bolt\u4f1a\u88ab\u5f53\u4f5csubprocess\u6765\u6267\u884c\uff0c storm\u4f7f\u7528JSON\u6d88\u606f\u901a\u8fc7stdin\/stdout\u6765\u548c\u8fd9\u4e9bsubprocess\u901a\u4fe1\u3002\u8fd9\u4e2a\u901a\u4fe1\u534f\u8bae\u662f\u4e00\u4e2a\u53ea\u6709100\u884c\u7684\u5e93\uff0c storm\u56e2\u961f\u7ed9\u8fd9\u4e9b\u5e93\u5f00\u53d1\u4e86\u5bf9\u5e94\u7684Ruby, Python\u548cFancy\u7248\u672c\u3002<\/p>\n<p>\u4e0b\u9762\u662fWordCountTopology\u91cc\u9762\u7684SplitSentence\u7684\u5b9a\u4e49:<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><\/pre>\n<\/td>\n<td>\n<pre>public static class SplitSentence extends ShellBolt implements IRichBolt {<\/pre>\n<pre>    public SplitSentence() {<\/pre>\n<pre>        super(\"python\", \"splitsentence.py\");<\/pre>\n<pre>    }<\/pre>\n<pre>     public void declareOutputFields(OutputFieldsDeclarer declarer) {<\/pre>\n<pre>        declarer.declare(new Fields(\"word\"));<\/pre>\n<pre>    }<\/pre>\n<pre>}<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>SplitSentence\u7ee7\u627f\u81eaShellBolt\u5e76\u4e14\u58f0\u660e\u8fd9\u4e2aBolt\u7528python\u6765\u8fd0\u884c\uff0c\u5e76\u4e14\u53c2\u6570\u662f: splitsentence.py\u3002\u4e0b\u9762\u662fsplitsentence.py\u7684\u5b9a\u4e49:<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><\/pre>\n<\/td>\n<td>\n<pre>import storm<\/pre>\n<pre>class SplitSentenceBolt(storm.BasicBolt):<\/pre>\n<pre>    def process(self, tup):<\/pre>\n<pre>        words = tup.values[0].split(\" \")<\/pre>\n<pre>        for word in words:<\/pre>\n<pre>          storm.emit([word])<\/pre>\n<pre>SplitSentenceBolt().run()<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u66f4\u591a\u6709\u5173\u7528\u5176\u5b83\u8bed\u8a00\u5b9a\u4e49Spout\u548cBolt\u7684\u4fe1\u606f\uff0c \u4ee5\u53ca\u7528\u5176\u5b83\u8bed\u8a00\u6765\u521b\u5efatopology\u7684 \u4fe1\u606f\u53ef\u4ee5\u53c2\u89c1: Using non-JVm languages with Storm.<\/p>\n<h2>\u53ef\u9760\u7684\u6d88\u606f\u5904\u7406<\/h2>\n<p>\u5728\u8fd9\u4e2a\u6559\u7a0b\u7684\u524d\u9762\uff0c\u6211\u4eectuple\u53d1\u5c04\u7684\u4e00\u4e9b\u65b9\u9762\u3002\u8fd9\u4e9b\u65b9\u9762\u5c31\u662fstorm\u7684\u53ef\u9760\u6027API\uff1a storm\u5982\u679c\u4fdd\u8bc1spout\u53d1\u51fa\u7684\u6bcf\u4e00\u4e2atuple\u90fd\u88ab\u5b8c\u6574\u5904\u7406\u3002\u770b\u770b\u300astorm\u5982\u4f55\u4fdd\u8bc1\u6d88\u606f\u4e0d\u4e22\u5931\u300b\u4ee5\u66f4\u6df1\u5165\u4e86\u89e3storm\u7684\u53ef\u9760\u6027API.<\/p>\n<h2>\u7ed3\u8bba<\/h2>\n<p>\u8fd9\u4e2a\u5165\u95e8\u6559\u7a0b\u6bd4\u8f83\u5e7f\u6cdb\u7684\u4ecb\u7ecd\u4e86\u4ece\u5f00\u53d1\uff0c\u6d4b\u8bd5\u548c\u90e8\u7f72\u4e00\u4e2atopology. \u6587\u6863\u7684\u5176\u5b83\u90e8\u5206\u4f1a\u6df1\u5165\u4ecb\u7ecd\u4f7f\u7528storm\u7684\u5404\u4e2a\u65b9\u9762\u3002<\/p>\n<\/div>\n<div>Storm\u5982\u4f55\u4fdd\u8bc1\u6d88\u606f\u4e0d\u4e22\u5931<\/div>\n<div>\n<p>storm\u4fdd\u8bc1\u4ecespout\u53d1\u51fa\u7684\u6bcf\u4e2atuple\u90fd\u4f1a\u88ab\u5b8c\u5168\u5904\u7406\u3002\u8fd9\u7bc7\u6587\u7ae0\u4ecb\u7ecdstorm\u662f\u600e\u4e48\u505a\u5230\u8fd9\u4e2a\u4fdd\u8bc1\u7684\uff0c\u4ee5\u53ca\u6211\u4eec\u4f7f\u7528\u8005\u600e\u4e48\u505a\u624d\u80fd\u5145\u5206\u5229\u7528storm\u7684\u53ef\u9760\u6027\u7279\u70b9\u3002<\/p>\n<h2>\u4e00\u4e2atuple\u88ab\u201d\u5b8c\u5168\u5904\u7406\u201d\u662f\u4ec0\u4e48\u610f\u601d\uff1f<\/h2>\n<p>\u5c31\u5982\u540c\u8774\u8776\u6548\u5e94\u4e00\u6837\uff0c\u4ecespout\u53d1\u5c04\u7684\u4e00\u4e2atuple\u53ef\u4ee5\u5f15\u8d77\u5176\u5b83\u6210\u5343\u4e0a\u4e07\u4e2atuple\u56e0\u5b83\u800c\u4ea7\u751f\uff0c \u60f3\u60f3\u90a3\u4e2a\u8ba1\u7b97\u4e00\u7bc7\u6587\u7ae0\u4e2d\u6bcf\u4e2a\u5355\u8bcd\u51fa\u73b0\u6b21\u6570\u7684topology.<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><\/pre>\n<\/td>\n<td>\n<pre>TopologyBuilder builder = new TopologyBuilder();<\/pre>\n<pre>builder.setSpout(1, new KestrelSpout(\"kestrel.backtype.com\",<\/pre>\n<pre>                                     22133,<\/pre>\n<pre>                                     \"sentence_queue\",<\/pre>\n<pre>                                     new StringScheme()));<\/pre>\n<pre>builder.setBolt(2, new SplitSentence(), 10)<\/pre>\n<pre>        .shuffleGrouping(1);<\/pre>\n<pre>builder.setBolt(3, new WordCount(), 20)<\/pre>\n<pre>        .fieldsGrouping(2, new Fields(\"word\"));<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u8fd9\u4e2atopology\u4ece\u4e00\u4e2aKestrel\u961f\u5217\u8bfb\u53d6\u53e5\u5b50\uff0c \u628a\u6bcf\u4e2a\u53e5\u5b50\u5206\u5272\u6210\u4e00\u4e2a\u4e2a\u5355\u8bcd\uff0c \u7136\u540e\u53d1\u5c04\u8fd9\u4e00\u4e2a\u4e2a\u5355\u8bcd\uff1a \u4e00\u4e2a\u6e90tuple\uff08\u4e00\u4e2a\u53e5\u5b50\uff09\u5f15\u8d77\u540e\u9762\u5f88\u591atuple\u7684\u4ea7\u751f(\u4e00\u4e2a\u4e2a\u5355\u8bcd\uff09\uff0c \u8fd9\u4e2a\u6d88\u606f\u6d41\u5927\u6982\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<div>\n<div><img decoding=\"async\" src=\"https:\/\/github.com\/nathanmarz\/storm\/wiki\/images\/tuple_tree.png\" alt=\"Storm\uff08\u5b9e\u65f6Hadoop\uff09\u6307\u5357 - \u89c1\u9f99\u5728\u5929 - \u89c1\u9f99\u5728\u5929\" \/><\/div>\n<p>\u7edf\u8ba1\u5355\u8bcd\u51fa\u73b0\u6b21\u6570\u7684tuple\u6811<\/p>\n<\/div>\n<p>\u5728storm\u91cc\u9762\u4e00\u4e2atuple\u88ab\u5b8c\u5168\u5904\u7406\u7684\u610f\u601d\u662f\uff1a \u8fd9\u4e2atuple\u4ee5\u53ca\u7531\u8fd9\u4e2atuple\u6240\u5bfc\u81f4\u7684\u6240\u6709\u7684tuple\u90fd\u88ab\u6210\u529f\u5904\u7406\u3002\u800c\u4e00\u4e2atuple\u4f1a\u88ab\u8ba4\u4e3a\u5904\u7406\u5931\u8d25\u4e86\u5982\u679c\u8fd9\u4e2a\u6d88\u606f\u5728timeout\u6240\u6307\u5b9a\u7684\u65f6\u95f4\u5185\u6ca1\u6709\u6210\u529f\u5904\u7406\u3002 \u800c\u8fd9\u4e2atimetout\u53ef\u4ee5\u901a\u8fc7<a href=\"http:\/\/nathanmarz.github.com\/storm\/doc\/backtype\/storm\/Config.html#TOPOLOGY_MESSAGE_TIMEOUT_SECS\" rel=\"nofollow\">Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS<\/a>\u6765\u6307\u5b9a\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u5982\u679c\u4e00\u4e2a\u6d88\u606f\u5904\u7406\u6210\u529f\u4e86\u6216\u8005\u5931\u8d25\u4e86\u4f1a\u53d1\u751f\u4ec0\u4e48\uff1f<\/h2>\n<p>FYI\u3002 \u4e0b\u9762\u8fd9\u4e2a\u662fspout\u8981\u5b9e\u73b0\u7684\u63a5\u53e3:<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><\/pre>\n<\/td>\n<td>\n<pre>public interface ISpout extends Serializable {<\/pre>\n<pre>    void open(Map conf, TopologyContext context, SpoutOutputCollector collector);<\/pre>\n<pre>    void close();<\/pre>\n<pre>    void nextTuple();<\/pre>\n<pre>    void ack(Object msgId);<\/pre>\n<pre>    void fail(Object msgId);<\/pre>\n<pre>}<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u9996\u5148storm\u901a\u8fc7\u8c03\u7528spout\u7684nextTuple\u65b9\u6cd5\u6765\u83b7\u53d6\u4e0b\u4e00\u4e2atuple, Spout\u901a\u8fc7open\u65b9\u6cd5\u53c2\u6570\u91cc\u9762\u63d0\u4f9b\u7684SpoutOutputCollector\u6765\u53d1\u5c04\u65b0tuple\u5230\u5b83\u7684\u5176\u4e2d\u4e00\u4e2a\u8f93\u51fa\u6d88\u606f\u6d41, \u53d1\u5c04tuple\u7684\u65f6\u5019spout\u4f1a\u63d0\u4f9b\u4e00\u4e2amessage-id, \u540e\u9762\u6211\u4eec\u901a\u8fc7\u8fd9\u4e2atuple-id\u6765\u8ffd\u8e2a\u8fd9\u4e2atuple\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c KestrelSpout\u4ecekestrel\u961f\u5217\u91cc\u9762\u8bfb\u53d6\u4e00\u4e2a\u6d88\u606f\uff0c\u5e76\u4e14\u628akestrel\u63d0\u4f9b\u7684\u6d88\u606fid\u4f5c\u4e3amessage-id, \u770b\u4f8b\u5b50\uff1a<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><\/pre>\n<\/td>\n<td>\n<pre>_collector.emit(new Values(\"field1\", \"field2\", 3) , msgId);<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u63a5\u4e0b\u6765\uff0c \u8fd9\u4e2a\u53d1\u5c04\u7684tuple\u88ab\u4f20\u9001\u5230\u6d88\u606f\u5904\u7406\u8005bolt\u90a3\u91cc\uff0c storm\u4f1a\u8ddf\u8e2a\u7531\u6b64\u6240\u4ea7\u751f\u7684\u8fd9\u8bfetuple\u6811\u3002\u5982\u679cstorm\u68c0\u6d4b\u5230\u4e00\u4e2atuple\u88ab\u5b8c\u5168\u5904\u7406\u4e86\uff0c \u90a3\u4e48storm\u4f1a\u4ee5\u6700\u5f00\u59cb\u7684\u90a3\u4e2amessage-id\u4f5c\u4e3a\u53c2\u6570\u53bb\u8c03\u7528\u6d88\u606f\u6e90\u7684ack\u65b9\u6cd5\uff1b\u53cd\u4e4bstorm\u4f1a\u8c03\u7528spout\u7684fail\u65b9\u6cd5\u3002\u503c\u5f97\u6ce8\u610f\u7684\u4e00\u70b9 \u662f\uff0c storm\u8c03\u7528ack\u6216\u8005fail\u7684task\u59cb\u7ec8\u662f\u4ea7\u751f\u8fd9\u4e2atuple\u7684\u90a3\u4e2atask\u3002\u6240\u4ee5\u5982\u679c\u4e00\u4e2aspout\u88ab\u5206\u6210\u5f88\u591a\u4e2atask\u6765\u6267\u884c\uff0c \u6d88\u606f\u6267\u884c\u7684\u6210\u529f\u5931\u8d25\u4e0e\u5426\u59cb\u7ec8\u4f1a\u901a\u77e5\u6700\u5f00\u59cb\u53d1\u51fatuple\u7684\u90a3\u4e2atask\u3002<\/p>\n<p>\u6211\u4eec\u518d\u4ee5KestrelSpout\u4e3a\u4f8b\u6765\u770b\u770bspout\u9700\u8981\u505a\u4e9b\u4ec0\u4e48\u624d\u80fd\u4fdd\u8bc1\u201c\u4e00\u4e2a\u6d88\u606f\u59cb\u7ec8\u88ab\u5b8c\u5168\u5904\u7406\u201d, \u5f53KestrelSpout\u4eceKestrel\u91cc\u9762\u8bfb\u51fa\u4e00\u6761\u6d88\u606f\uff0c \u9996\u5148\u5b83\u201c\u6253\u5f00\u201d\u8fd9\u6761\u6d88\u606f\uff0c \u8fd9\u610f\u5473\u7740\u8fd9\u6761\u6d88\u606f\u8fd8\u5728kestrel\u961f\u5217\u91cc\u9762\uff0c \u4e0d\u8fc7\u8fd9\u6761\u6d88\u606f\u4f1a\u88ab\u6807\u793a\u6210\u201c\u5904\u7406\u4e2d\u201d\u76f4\u5230ack\u6216\u8005fail\u88ab\u8c03\u7528\u3002\u5904\u4e8e\u201c\u5904\u7406\u4e2d\u201c\u72b6\u6001\u7684\u6d88\u606f\u4e0d\u4f1a\u88ab\u53d1\u7ed9\u5176\u4ed6\u6d88\u606f\u5904\u7406\u8005\u4e86\uff1b\u5e76\u4e14\u5982\u679c\u8fd9\u4e2aspout\u201c\u65ad\u7ebf\u201d \u4e86\uff0c \u90a3\u4e48\u6240\u6709\u5904\u4e8e\u201c\u5904\u7406\u4e2d\u201d\u72b6\u6001\u7684\u6d88\u606f\u4f1a\u88ab\u91cd\u65b0\u6807\u793a\u6210\u201c\u7b49\u5f85\u5904\u7406\u201d.<\/p>\n<h2>Storm\u7684\u53ef\u9760\u6027API<\/h2>\n<p>\u4f5c\u4e3astorm\u7684\u4f7f\u7528\u8005\uff0c\u6709\u4e24\u4ef6\u4e8b\u60c5\u8981\u505a\u4ee5\u66f4\u597d\u7684\u5229\u7528storm\u7684\u53ef\u9760\u6027\u7279\u5f81\u3002 \u9996\u5148\uff0c\u5728\u4f60\u751f\u6210\u4e00\u4e2a\u65b0\u7684tuple\u7684\u65f6\u5019\u8981\u901a\u77e5storm; \u5176\u6b21\uff0c\u5b8c\u6210\u5904\u7406\u4e00\u4e2atuple\u4e4b\u540e\u8981\u901a\u77e5storm\u3002 \u8fd9\u6837storm\u5c31\u53ef\u4ee5\u68c0\u6d4b\u6574\u4e2atuple\u6811\u6709\u6ca1\u6709\u5b8c\u6210\u5904\u7406\uff0c\u5e76\u4e14\u901a\u77e5\u6e90spout\u5904\u7406\u7ed3\u679c\u3002storm\u63d0\u4f9b\u4e86\u4e00\u4e9b\u7b80\u6d01\u7684api\u6765\u505a\u8fd9\u4e9b\u4e8b\u60c5\u3002<\/p>\n<p>\u7531\u4e00\u4e2atuple\u4ea7\u751f\u4e00\u4e2a\u65b0\u7684tuple\u79f0\u4e3a\uff1a anchoring\u3002\u4f60\u53d1\u5c04\u4e00\u4e2a\u65b0tuple\u7684\u540c\u65f6\u4e5f\u5c31\u5b8c\u6210\u4e86\u4e00\u6b21anchoring\u3002\u770b\u4e0b\u9762\u8fd9\u4e2a\u4f8b\u5b50\uff1a \u8fd9\u4e2abolt\u628a\u4e00\u4e2a\u5305\u542b\u4e00\u4e2a\u53e5\u5b50\u7684tuple\u5206\u5272\u6210\u6bcf\u4e2a\u5355\u8bcd\u4e00\u4e2atuple\u3002<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><\/pre>\n<\/td>\n<td>\n<pre>public class SplitSentence implements IRichBolt {<\/pre>\n<pre>        OutputCollector _collector;<\/pre>\n<pre>         public void prepare(Map conf, TopologyContext context, OutputCollector collector) {<\/pre>\n<pre>            _collector = collector;<\/pre>\n<pre>        }<\/pre>\n<pre>         public void execute(Tuple tuple) {<\/pre>\n<pre>            String sentence = tuple.getString(0);<\/pre>\n<pre>            for(String word: sentence.split(\" \")) {<\/pre>\n<pre>                _collector.emit(tuple, new Values(word));<\/pre>\n<pre>            }<\/pre>\n<pre>            _collector.ack(tuple);<\/pre>\n<pre>        }<\/pre>\n<pre>         public void cleanup() {<\/pre>\n<pre>        }<\/pre>\n<pre>         public void declareOutputFields(OutputFieldsDeclarer declarer) {<\/pre>\n<pre>            declarer.declare(new Fields(\"word\"));<\/pre>\n<pre>        }<\/pre>\n<pre>    }<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u770b\u4e00\u4e0b\u8fd9\u4e2aexecute\u65b9\u6cd5\uff0c emit\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u8f93\u5165tuple\uff0c \u7b2c\u4e8c\u4e2a\u53c2\u6570\u5219\u662f\u8f93\u51fatuple\uff0c \u8fd9\u5176\u5b9e\u5c31\u662f\u901a\u8fc7\u8f93\u5165tuple anchoring\u4e86\u4e00\u4e2a\u65b0\u7684\u8f93\u51fatuple\u3002\u56e0\u4e3a\u8fd9\u4e2a\u201c\u5355\u8bcdtuple\u201d\u88abanchoring\u5728\u201c\u53e5\u5b50tuple\u201d\u4e00\u8d77\uff0c \u5982\u679c\u5176\u4e2d\u4e00\u4e2a\u5355\u8bcd\u5904\u7406\u51fa\u9519\uff0c\u90a3\u4e48\u8fd9\u6574\u4e2a\u53e5\u5b50\u4f1a\u88ab\u91cd\u65b0\u5904\u7406\u3002\u4f5c\u4e3a\u5bf9\u6bd4\uff0c \u6211\u4eec\u770b\u770b\u5982\u679c\u901a\u8fc7\u4e0b\u9762\u8fd9\u884c\u4ee3\u7801\u6765\u53d1\u5c04\u4e00\u4e2a\u65b0\u7684tuple\u7684\u8bdd\u4f1a\u6709\u4ec0\u4e48\u7ed3\u679c\u3002<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><\/pre>\n<\/td>\n<td>\n<pre>_collector.emit(new Values(word));<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u7528\u8fd9\u79cd\u65b9\u6cd5\u53d1\u5c04\u4f1a\u5bfc\u81f4\u65b0\u53d1\u5c04\u7684\u8fd9\u4e2atuple\u8131\u79bb\u539f\u6765\u7684tuple\u6811(unanchoring), \u5982\u679c\u8fd9\u4e2atuple\u5904\u7406\u5931\u8d25\u4e86\uff0c \u6574\u4e2a\u53e5\u5b50\u4e0d\u4f1a\u88ab\u91cd\u65b0\u5904\u7406\u3002\u5230\u5e95\u8981anchoring\u8fd8\u662f\u8981 unanchoring\u5219\u5b8c\u5168\u53d6\u51b3\u4e8e\u4f60\u7684\u4e1a\u52a1\u9700\u6c42\u3002<\/p>\n<p>\u4e00\u4e2a\u8f93\u51fatuple\u53ef\u4ee5\u88abanchoring\u5230\u591a\u4e2a\u8f93\u5165tuple\u3002\u8fd9\u79cd\u65b9\u5f0f\u5728stream\u5408\u5e76\u6216\u8005stream\u805a\u5408\u7684\u65f6\u5019\u5f88\u6709\u7528\u3002\u4e00\u4e2a\u591a\u5165\u53e3tuple\u5904\u7406\u5931\u8d25\u7684\u8bdd\uff0c\u90a3\u4e48\u5b83\u5bf9\u5e94\u7684\u6240\u6709\u8f93\u5165tuple\u90fd\u8981\u91cd\u65b0\u6267\u884c\u3002\u770b\u770b\u4e0b\u9762\u6f14\u793a\u600e\u4e48\u6307\u5b9a\u591a\u4e2a\u8f93\u5165tuple:<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><\/pre>\n<\/td>\n<td>\n<pre>List &lt;Tuple&gt; anchors = new ArrayList<span style=\"color: #339933;\">&lt;<\/span>Tuple<span style=\"color: #339933;\">&gt;<\/span>();<\/pre>\n<pre>anchors.add(tuple1);<\/pre>\n<pre>anchors.add(tuple2);<\/pre>\n<pre>_collector.emit(anchors, new Values(1, 2, 3));<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u591a\u5165\u53e3tuple\u628a\u8fd9\u4e2a\u65b0tuple\u52a0\u5230\u4e86\u591a\u4e2atuple\u6811\u91cc\u9762\u53bb\u4e86\u3002<\/p>\n<p>\u6211\u4eec\u901a\u8fc7anchoring\u6765\u6784\u9020\u8fd9\u4e2atuple\u6811\uff0c\u6700\u540e\u4e00\u4ef6\u8981\u505a\u7684\u4e8b\u60c5\u662f\u5728\u4f60\u5904\u7406\u5b8c\u5f53\u4e2atuple\u7684\u65f6\u5019\u544a\u8bc9storm, \u00a0\u901a\u8fc7OutputCollector\u7c7b\u7684ack\u548cfail\u65b9\u6cd5\u6765\u505a\uff0c\u5982\u679c\u4f60\u56de\u8fc7\u5934\u6765\u770b\u770b<code>SplitSentence<\/code>\u7684\u4f8b\u5b50\uff0c \u4f60\u53ef\u4ee5\u770b\u5230\u201c\u53e5\u5b50tuple\u201d\u5728\u6240\u6709\u201c\u5355\u8bcdtuple\u201d\u88ab\u53d1\u51fa\u4e4b\u540e\u8c03\u7528\u4e86ack\u3002<\/p>\n<p>\u4f60\u53ef\u4ee5\u8c03\u7528<code>OutputCollector<\/code>\u00a0\u7684fail\u65b9\u6cd5\u53bb\u7acb\u5373\u5c06\u4ece\u6d88\u606f\u6e90\u5934\u53d1\u51fa\u7684\u90a3\u4e2atuple\u6807\u8bb0\u4e3afail\uff0c \u6bd4\u5982\u4f60\u67e5\u8be2\u4e86\u6570\u636e\u5e93\uff0c\u53d1\u73b0\u4e00\u4e2a\u9519\u8bef\uff0c\u4f60\u53ef\u4ee5\u9a6c\u4e0afail\u90a3\u4e2a\u8f93\u5165tuple\uff0c \u8fd9\u6837\u53ef\u4ee5\u8ba9\u8fd9\u4e2atuple\u88ab\u5feb\u901f\u7684\u91cd\u65b0\u5904\u7406\uff0c \u56e0\u4e3a\u4f60\u4e0d\u9700\u8981\u7b49\u90a3\u4e2atimeout\u65f6\u95f4\u6765\u8ba9\u5b83\u81ea\u52a8fail\u3002<\/p>\n<p>\u6bcf\u4e2a\u4f60\u5904\u7406\u7684tuple\uff0c \u5fc5\u987b\u88aback\u6216\u8005fail\u3002\u56e0\u4e3astorm\u8ffd\u8e2a\u6bcf\u4e2atuple\u8981\u5360\u7528\u5185\u5b58\u3002\u6240\u4ee5\u5982\u679c\u4f60\u4e0dack\/fail\u6bcf\u4e00\u4e2atuple\uff0c \u90a3\u4e48\u6700\u7ec8\u4f60\u4f1a\u770b\u5230OutOfMemory\u9519\u8bef\u3002<\/p>\n<p>\u5927\u591a\u6570Bolt\u9075\u5faa\u8fd9\u6837\u7684\u89c4\u5f8b\uff1a\u8bfb\u53d6\u4e00\u4e2atuple\uff1b\u53d1\u5c04\u4e00\u4e9b\u65b0\u7684tuple\uff1b\u5728execute\u7684\u7ed3\u675f\u7684\u65f6\u5019ack\u8fd9\u4e2atuple\u3002\u8fd9\u4e9bBolt\u5f80 \u5f80\u662f\u4e00\u4e9b\u8fc7\u6ee4\u5668\u6216\u8005\u7b80\u5355\u51fd\u6570\u3002Storm\u4e3a\u8fd9\u7c7b\u89c4\u5f8b\u5c01\u88c5\u4e86\u4e00\u4e2aBasicBolt\u7c7b\u3002\u5982\u679c\u7528BasicBolt\u6765\u505a\uff0c \u4e0a\u9762\u90a3\u4e2aSplitSentence\u53ef\u4ee5\u6539\u5199\u6210\u8fd9\u6837\uff1a<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre><\/pre>\n<\/td>\n<td>\n<pre>public class SplitSentence implements IBasicBolt {<\/pre>\n<pre>        public void prepare(Map conf, TopologyContext context) {<\/pre>\n<pre>        }<\/pre>\n<pre>         public void execute(Tuple tuple, BasicOutputCollector collector) {<\/pre>\n<pre>            String sentence = tuple.getString(0);<\/pre>\n<pre>            for(String word: sentence.split(\" \")) {<\/pre>\n<pre>                collector.emit(new Values(word));<\/pre>\n<pre>            }<\/pre>\n<pre>        }<\/pre>\n<pre>         public void cleanup() {<\/pre>\n<pre>        }<\/pre>\n<pre>         public void declareOutputFields(OutputFieldsDeclarer declarer) {<\/pre>\n<pre><\/pre>\n<pre>            declarer.declare(new Fields(\"word\"));<\/pre>\n<pre>        }<\/pre>\n<pre>    }<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u8fd9\u4e2a\u5b9e\u73b0\u6bd4\u4e4b\u524d\u7684\u5b9e\u73b0\u7b80\u5355\u591a\u4e86\uff0c \u4f46\u662f\u529f\u80fd\u4e0a\u662f\u4e00\u6837\u7684\u3002\u53d1\u9001\u5230BasicOutputCollector\u7684tuple\u4f1a\u81ea\u52a8\u548c\u8f93\u5165tuple\u76f8\u5173\u8054\uff0c\u800c\u5728execute\u65b9\u6cd5\u7ed3\u675f\u7684\u65f6\u5019\u90a3\u4e2a\u8f93\u5165tuple\u4f1a\u88ab\u81ea\u52a8ack\u7684\u3002<br \/>\n\u4f5c\u4e3a\u5bf9\u6bd4\uff0c\u5904\u7406\u805a\u5408\u548c\u5408\u5e76\u7684bolt\u5f80\u5f80\u8981\u5904\u7406\u4e00\u5927\u5806\u7684tuple\u4e4b\u540e\u624d\u80fd\u88aback\uff0c \u800c\u8fd9\u7c7btuple\u901a\u5e38\u90fd\u662f\u591a\u8f93\u5165\u7684tuple\uff0c \u6240\u4ee5\u8fd9\u4e2a\u5df2\u7ecf\u4e0d\u662fIBasicBolt\u53ef\u4ee5\u7f69\u5f97\u4f4f\u7684\u4e86\u3002<\/p>\n<h2>storm\u662f\u600e\u4e48\u5b9e\u73b0\u9ad8\u6548\u7387\u7684\u53ef\u9760\u6027\u7684\uff1f<\/h2>\n<p>storm\u91cc\u9762\u6709\u4e00\u7c7b\u7279\u6b8a\u7684task\u79f0\u4e3a\uff1aacker\uff0c \u4ed6\u4eec\u8d1f\u8d23\u8ddf\u8e2aspout\u53d1\u51fa\u7684\u6bcf\u4e00\u4e2atuple\u7684tuple\u6811\u3002\u5f53acker\u53d1\u73b0\u4e00\u4e2atuple\u6811\u5df2\u7ecf\u5904\u7406\u5b8c\u6210\u4e86\u3002\u5b83\u4f1a\u53d1\u9001\u4e00\u4e2a\u6d88\u606f\u7ed9\u4ea7\u751f\u8fd9\u4e2atuple \u7684\u90a3\u4e2atask\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7Config.TOPOLOGY_ACKERS\u6765\u8bbe\u7f6e\u4e00\u4e2atopology\u91cc\u9762\u7684acker\u7684\u6570\u91cf\uff0c \u9ed8\u8ba4\u503c\u662f\u4e00\u3002 \u5982\u679c\u4f60\u7684topology\u91cc\u9762\u7684tuple\u6bd4\u8f83\u591a\u7684\u8bdd\uff0c \u90a3\u4e48\u628aacker\u7684\u6570\u91cf\u8bbe\u7f6e\u591a\u4e00\u70b9\uff0c\u6548\u7387\u4f1a\u9ad8\u4e00\u70b9\u3002<\/p>\n<p>\u7406\u89e3storm\u7684\u53ef\u9760\u6027\u7684\u6700\u597d\u7684\u65b9\u6cd5\u662f\u6765\u770b\u770btuple\u548ctuple\u6811\u7684\u751f\u547d\u5468\u671f\uff0c \u5f53\u4e00\u4e2atuple\u88ab\u521b\u5efa\uff0c \u4e0d\u7ba1\u662fspout\u8fd8\u662fbolt\u521b\u5efa\u7684\uff0c \u5b83\u4f1a\u88ab\u8d4b\u4e88\u4e00\u4e2a64\u4f4d\u7684id\uff0c\u800cacker\u5c31\u662f\u5229\u7528\u8fd9\u4e2aid\u53bb\u8ddf\u8e2a\u6240\u6709\u7684tuple\u7684\u3002\u6bcf\u4e2atuple\u77e5\u9053\u5b83\u7684\u7956\u5b97\u7684id(\u4ecespout\u53d1\u51fa\u6765\u7684\u90a3\u4e2a tuple\u7684id), \u6bcf\u5f53\u4f60\u65b0\u53d1\u5c04\u4e00\u4e2atuple\uff0c \u5b83\u7684\u7956\u5b97id\u90fd\u4f1a\u4f20\u7ed9\u8fd9\u4e2a\u65b0\u7684tuple\u3002\u6240\u4ee5\u5f53\u4e00\u4e2atuple\u88aback\u7684\u65f6\u5019\uff0c\u6240\u4ee5\u5f53\u4e00\u4e2atuple\u88ab\u5904\u7406\u5b8c\u7684\u65f6\u5019\uff0c\u5b83\u4f1a\u53d1\u4e00\u4e2a\u6d88\u606f\u7ed9acker\uff0c\u544a\u8bc9 \u5b83\u8fd9\u4e2atuple\u6811\u53d1\u751f\u4e86\u600e\u4e48\u6837\u7684\u53d8\u5316\u3002\u5177\u4f53\u6765\u8bf4\u5c31\u662f\uff1a\u5b83\u544a\u8bc9acker\uff1a \u6211\u5462\u5df2\u7ecf\u5b8c\u6210\u4e86\uff0c \u6211\u6709\u8fd9\u4e9b\u513f\u5b50tuple, \u4f60\u8ddf\u8e2a\u4e00\u4e0b\u4ed6\u4eec\u5427\u3002\u4e0b\u9762\u8fd9\u4e2a\u56fe\u6f14\u793a\u4e86C\u88aback\u4e86\u4e4b\u540e\uff0c\u8fd9\u4e2atuple\u6811\u6240\u53d1\u751f\u7684\u53d8\u5316\u3002<\/p>\n<div>\n<div><img decoding=\"async\" src=\"https:\/\/github.com\/nathanmarz\/storm\/wiki\/images\/ack_tree.png\" alt=\"Storm\uff08\u5b9e\u65f6Hadoop\uff09\u6307\u5357 - \u89c1\u9f99\u5728\u5929 - \u89c1\u9f99\u5728\u5929\" \/><\/div>\n<p>tuple ack\u793a\u4f8b<\/p>\n<\/div>\n<p>\u5173\u4e8estorm\u600e\u4e48\u8ddf\u8e2atuple\u8fd8\u6709\u4e00\u4e9b\u7ec6\u8282\uff0c \u524d\u9762\u5df2\u7ecf\u63d0\u5230\u8fc7\u4e86\uff0c \u4f60\u53ef\u4ee5\u81ea\u5df1\u8bbe\u5b9a\u4f60\u7684topology\u91cc\u9762\u6709\u591a\u5c11\u4e2aacker\u3002\u800c\u8fd9\u53c8\u7ed9\u6211\u4eec\u5e26\u6765\u4e00\u4e2a\u95ee\u9898\uff0c \u5f53\u4e00\u4e2atuple\u9700\u8981ack\u7684\u65f6\u5019\uff0c\u5b83\u5230\u5e95\u9009\u62e9\u54ea\u4e2atuple\u6765ack\u5462\uff1f<\/p>\n<p>storm\u4f7f\u7528\u4e00\u81f4\u6027\u54c8\u5e0c\u6765\u628a\u4e00\u4e2aspout-tuple-id\u5bf9\u5e94\u5230acker\uff0c \u56e0\u4e3a\u6bcf\u4e00\u4e2atuple\u77e5\u9053\u5b83\u6240\u6709\u7684\u7956\u5b97\u7684tuple-id\uff0c \u6240\u4ee5\u5b83\u81ea\u7136\u53ef\u4ee5\u7b97\u51fa\u8981\u901a\u77e5\u54ea\u4e2aacker\u6765ack\u3002<\/p>\n<p>storm\u7684\u53e6\u4e00\u4e2a\u7ec6\u8282\u662facker\u662f\u600e\u4e48\u77e5\u9053\u6bcf\u4e00\u4e2aspout tuple\u5e94\u8be5\u4ea4\u7ed9\u54ea\u4e2atask\u6765\u5904\u7406\u3002\u5f53\u4e00\u4e2aspout\u53d1\u5c04\u4e00\u4e2a\u65b0\u7684tuple\uff0c \u5b83\u4f1a\u7b80\u5355\u7684\u53d1\u4e00\u4e2a\u6d88\u606f\u7ed9\u4e00\u4e2a\u5408\u9002\u7684acker\uff0c\u5e76\u4e14\u544a\u8bc9acker\u5b83\u81ea\u5df1\u7684id(taskid)\uff0c \u8fd9\u6837storm\u5c31\u6709\u4e86taskid-tupleid\u7684\u5bf9\u5e94\u5173\u7cfb\u3002 \u5f53acker\u53d1\u73b0\u4e00\u4e2a\u6811\u5b8c\u6210\u5904\u7406\u4e86\uff0c \u5b83\u77e5\u9053\u7ed9\u54ea\u4e2atask\u53d1\u9001\u6210\u529f\u7684\u6d88\u606f\u3002<\/p>\n<p>acker task\u5e76\u4e0d\u663e\u5f0f\u7684\u8ddf\u8e2atuple\u6811\u3002\u5bf9\u4e8e\u90a3\u4e9b\u6709\u6210\u5343\u4e0a\u4e07\u4e2a\u8282\u70b9\u7684tuple\u6811\uff0c\u628a\u8fd9\u4e48\u591a\u7684tuple\u4fe1\u606f\u90fd\u8ddf\u8e2a\u8d77\u6765\u4f1a\u8017\u8d39\u592a\u591a\u7684\u5185\u5b58\u3002\u76f8\u53cd\uff0c acker\u7528\u4e86\u4e00\u79cd\u4e0d\u540c\u7684\u65b9\u5f0f\uff0c \u4f7f\u5f97\u5bf9\u4e8e\u6bcf\u4e2aspout tuple\u6240\u9700\u8981\u7684\u5185\u5b58\u91cf\u662f\u6052\u5b9a\u7684\uff0820 bytes) . \u00a0\u8fd9\u4e2a\u8ddf\u8e2a\u7b97\u6cd5\u662fstorm\u5982\u4f55\u5de5\u4f5c\u7684\u5173\u952e\uff0c\u5e76\u4e14\u4e5f\u662f\u5b83\u7684\u4e3b\u8981\u7a81\u7834\u3002<\/p>\n<p>\u4e00\u4e2aacker task\u5b58\u50a8\u4e86\u4e00\u4e2aspout-tuple-id\u5230\u4e00\u5bf9\u503c\u7684\u4e00\u4e2amapping\u3002\u8fd9\u4e2a\u5bf9\u5b50\u7684\u7b2c\u4e00\u4e2a\u503c\u662f\u521b\u5efa\u8fd9\u4e2atuple\u7684taskid\uff0c \u8fd9\u4e2a\u662f\u7528\u6765\u5728\u5b8c\u6210\u5904\u7406tuple\u7684\u65f6\u5019\u53d1\u9001\u6d88\u606f\u7528\u7684\u3002 \u7b2c\u4e8c\u4e2a\u503c\u662f\u4e00\u4e2a64\u4f4d\u7684\u6570\u5b57\u79f0\u4f5c\uff1a\u201dack val\u201d, ack val\u662f\u6574\u4e2atuple\u6811\u7684\u72b6\u6001\u7684\u4e00\u4e2a\u8868\u793a\uff0c\u4e0d\u7ba1\u8fd9\u68f5\u6811\u591a\u5927\u3002\u5b83\u53ea\u662f\u7b80\u5355\u5730\u628a\u8fd9\u68f5\u6811\u4e0a\u7684\u6240\u6709\u521b\u5efa\u7684tupleid\/ack\u7684tuple\u4e00\u8d77\u5f02\u6216 (XOR)\u3002<\/p>\n<p>\u5f53\u4e00\u4e2aacker task \u53d1\u73b0\u4e00\u4e2a ack val\u53d8\u62100\u4e86\uff0c \u5b83\u77e5\u9053\u8fd9\u68f5\u6811\u5df2\u7ecf\u5904\u7406\u5b8c\u6210\u4e86\u3002 \u56e0\u4e3atupleid\u662f\u968f\u673a\u768464\u4f4d\u6570\u5b57\uff0c \u6240\u4ee5\uff0c ack val\u78b0\u5de7\u53d8\u62100(\u800c\u4e0d\u662f\u56e0\u4e3a\u6240\u6709\u521b\u5efa\u7684tuple\u90fd\u5b8c\u6210\u4e86)\u7684\u51e0\u7387\u6781\u5c0f\u3002\u7b97\u4e00\u4e0b\u5c31\u77e5\u9053\u4e86\uff0c \u5c31\u7b97\u6bcf\u79d2\u53d1\u751f10000\u4e2aack\uff0c \u90a3\u4e48\u9700\u898150000000\u4e07\u5e74\u624d\u53ef\u80fd\u78b0\u5230\u4e00\u4e2a\u9519\u8bef\u3002\u800c\u4e14\u5c31\u7b97\u78b0\u5230\u4e86\u4e00\u4e2a\u9519\u8bef\uff0c \u4e5f\u53ea\u6709\u5728\u8fd9\u4e2atuple\u5931\u8d25\u7684\u65f6\u5019\u624d\u4f1a\u9020\u6210\u6570\u636e\u4e22\u5931\u3002<\/p>\n<p>\u65e2\u7136\u4f60\u5df2\u7ecf\u7406\u89e3\u4e86storm\u7684\u53ef\u9760\u6027\u7b97\u6cd5\uff0c \u8ba9\u6211\u4eec\u4e00\u8d77\u8fc7\u4e00\u904d\u6240\u6709\u53ef\u80fd\u7684\u5931\u8d25\u573a\u666f\uff0c\u5e76\u770b\u770bstorm\u5728\u6bcf\u79cd\u60c5\u51b5\u4e0b\u662f\u600e\u4e48\u907f\u514d\u6570\u636e\u4e22\u5931\u7684\u3002<\/p>\n<p><strong>1. \u4e00\u4e2atuple\u6ca1\u6709ack\uff1a<\/strong>\u00a0\u56e0\u4e3a\u5904\u7406\u4ed6\u7684task\u6302\u6389\u4e86\u3002storm\u7684\u8d85\u65f6\u673a\u5236\u5728\u8d85\u65f6\u4e4b\u540e\u4f1a\u628a\u8fd9\u4e2atuple\u6807\u8bb0\u4e3a\u5931\u8d25\uff0c\u4ece\u800c\u53ef\u4ee5\u91cd\u65b0\u5904\u7406\u3002<\/p>\n<p><strong>2. Acker\u6302\u6389\u4e86\uff1a<\/strong>\u00a0\u8fd9\u79cd\u60c5\u51b5\u4e0b\u7531\u8fd9\u4e2aacker\u6240\u8ddf\u8e2a\u7684\u6240\u6709spout tuple\u90fd\u4f1a\u8d85\u65f6\uff0c\u4e5f\u5c31\u4f1a\u88ab\u91cd\u65b0\u5904\u7406\u3002<\/p>\n<p><strong>3. Spout\u6302\u6389\u4e86\uff1a<\/strong>\u00a0\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u7ed9spout\u53d1\u9001\u6d88\u606f\u7684\u6d88\u606f\u6e90\u8d1f\u8d23\u91cd\u65b0\u53d1\u9001\u8fd9\u4e9b\u6d88\u606f\u3002\u6bd4\u5982Kestrel\u548cRabbitMQ\u5728\u4e00\u4e2a\u5ba2\u6237\u7aef\u65ad\u5f00\u4e4b\u540e\u4f1a\u628a\u6240\u6709\u201d\u5904\u7406\u4e2d\u201c\u7684\u6d88\u606f\u653e\u56de\u961f\u5217\u3002<\/p>\n<p>\u5c31\u50cf\u4f60\u770b\u5230\u7684\u90a3\u6837\uff0c storm\u7684\u53ef\u9760\u6027\u673a\u5236\u662f\u5b8c\u5168\u5206\u5e03\u5f0f\u7684\uff0c \u53ef\u4f38\u7f29\u7684\u5e76\u4e14\u662f\u9ad8\u5ea6\u5bb9\u9519\u7684\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u8c03\u6574\u53ef\u9760\u6027 (Tuning Reliability)<\/h2>\n<p>acker task\u662f\u975e\u5e38\u8f7b\u91cf\u7ea7\u7684\uff0c \u6240\u4ee5\u4e00\u4e2atopology\u91cc\u9762\u4e0d\u9700\u8981\u5f88\u591aacker\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7Strom UI(id: -1)\u6765\u8ddf\u8e2a\u5b83\u7684\u6027\u80fd\u3002 \u5982\u679c\u5b83\u7684\u541e\u5410\u91cf\u770b\u8d77\u6765\u4e0d\u6b63\u5e38\uff0c\u90a3\u4e48\u4f60\u5c31\u9700\u8981\u591a\u52a0\u70b9acker\u4e86\u3002<\/p>\n<p>\u5982\u679c\u53ef\u9760\u6027\u5bf9\u4f60\u6765\u8bf4\u4e0d\u662f\u90a3\u4e48\u91cd\u8981 \u2014 \u4f60\u4e0d\u592a\u5728\u610f\u5728\u4e00\u4e9b\u5931\u8d25\u7684\u60c5\u51b5\u4e0b\u635f\u5931\u4e00\u4e9b\u6570\u636e\uff0c \u90a3\u4e48\u4f60\u53ef\u4ee5\u901a\u8fc7\u4e0d\u8ddf\u8e2a\u8fd9\u4e9btuple\u6811\u6765\u83b7\u53d6\u66f4\u597d\u7684\u6027\u80fd\u3002\u4e0d\u53bb\u8ddf\u8e2a\u6d88\u606f\u7684\u8bdd\u4f1a\u4f7f\u5f97\u7cfb\u7edf\u91cc\u9762\u7684\u6d88\u606f\u6570\u91cf\u51cf\u5c11\u4e00\u534a\uff0c \u56e0\u4e3a\u5bf9\u4e8e\u6bcf\u4e00\u4e2atuple\u90fd\u8981\u53d1\u9001\u4e00\u4e2aack\u6d88\u606f\u3002\u5e76\u4e14\u5b83\u9700\u8981\u66f4\u5c11\u7684id\u6765\u4fdd\u5b58\u4e0b\u6e38\u7684tuple\uff0c \u51cf\u5c11\u5e26\u5bbd\u5360\u7528\u3002<\/p>\n<p>\u6709\u4e09\u79cd\u65b9\u6cd5\u53ef\u4ee5\u53bb\u6389\u53ef\u9760\u6027\u3002\u7b2c\u4e00\u662f\u628aConfig.TOPOLOGY_ACKERS \u8bbe\u7f6e\u6210 0. \u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c storm\u4f1a\u5728spout\u53d1\u5c04\u4e00\u4e2atuple\u4e4b\u540e\u9a6c\u4e0a\u8c03\u7528spout\u7684ack\u65b9\u6cd5\u3002\u4e5f\u5c31\u662f\u8bf4\u8fd9\u4e2atuple\u6811\u4e0d\u4f1a\u88ab\u8ddf\u8e2a\u3002<\/p>\n<p>\u7b2c\u4e8c\u4e2a\u65b9\u6cd5\u662f\u5728tuple\u5c42\u9762\u53bb\u6389\u53ef\u9760\u6027\u3002 \u4f60\u53ef\u4ee5\u5728\u53d1\u5c04tuple\u7684\u65f6\u5019\u4e0d\u6307\u5b9amessageid\u6765\u8fbe\u5230\u4e0d\u8ddf\u7cbd\u67d0\u4e2a\u7279\u5b9a\u7684spout tuple\u7684\u76ee\u7684\u3002<\/p>\n<p>\u6700\u540e\u4e00\u4e2a\u65b9\u6cd5\u662f\u5982\u679c\u4f60\u5bf9\u4e8e\u4e00\u4e2atuple\u6811\u91cc\u9762\u7684\u67d0\u4e00\u90e8\u5206\u5230\u5e95\u6210\u4e0d\u6210\u529f\u4e0d\u662f\u5f88\u5173\u5fc3\uff0c\u90a3\u4e48\u53ef\u4ee5\u5728\u53d1\u5c04\u8fd9\u4e9btuple\u7684\u65f6\u5019unanchor\u5b83\u4eec\u3002 \u8fd9\u6837\u8fd9\u4e9btuple\u5c31\u4e0d\u5728tuple\u6811\u91cc\u9762\uff0c \u4e5f\u5c31\u4e0d\u4f1a\u88ab\u8ddf\u8e2a\u4e86\u3002<\/p>\n<p>&nbsp;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 \u00a0Storm\u8fd9\u662f\u4e00\u4e2a\u5206\u5e03\u5f0f\u7684\u3001\u5bb9\u9519\u7684\u5b9e\u65f6\u8ba1\u7b97\u7cfb\u7edf\uff0c\u5b83\u88ab\u6258\u7ba1\u5728GitHub\u4e0a\uff0c\u9075\u5faa\u00a0Eclipse Publ &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[63],"tags":[80,150,151],"class_list":["post-232","post","type-post","status-publish","format-standard","hentry","category-63","tag-hadoop","tag-storm","tag-151"],"views":1450,"_links":{"self":[{"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/232","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=232"}],"version-history":[{"count":1,"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/232\/revisions"}],"predecessor-version":[{"id":233,"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/232\/revisions\/233"}],"wp:attachment":[{"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=232"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.max-shu.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}