{"id":138039,"date":"2020-07-21T21:38:19","date_gmt":"2020-07-21T13:38:19","guid":{"rendered":"http:\/\/4563.org\/?p=138039"},"modified":"2020-07-21T21:38:19","modified_gmt":"2020-07-21T13:38:19","slug":"golang-%e5%a6%82%e4%bd%95%e8%a7%a3%e8%80%a6%e5%a4%9a%e5%b1%82%e7%ba%a7-kafka-consumer-%e6%af%94%e8%be%83%e5%a5%bd-2","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=138039","title":{"rendered":"Golang \u5982\u4f55\u89e3\u8026\u591a\u5c42\u7ea7 kafka consumer \u6bd4\u8f83\u597d?"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Golang \u5982\u4f55\u89e3\u8026\u591a\u5c42\u7ea7 kafka consumer \u6bd4\u8f83\u597d?               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Darain <\/span>  <span><i><\/i> 4<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u7b80\u5355\u63cf\u8ff0\u4e00\u4e0b\u5f53\u524d\u7684\u4e1a\u52a1\u8bbe\u8ba1:<\/p>\n<p>1.\u4e3b\u7ebf\u7a0b\u4ece kafka \u8bfb\u6d88\u606f (message)<\/p>\n<p>2.\u628a message \u6839\u636e id \u5bf9 partition \u53d6\u6a21\u8f6c\u53d1\u7ed9 dispatcher (dispatcher \u6570\u91cf = partiton \u5927\u5c0f)<\/p>\n<p>3.dispatcher \u8f6c\u53d1 message \u7ed9 concurrent handler (\u4e00\u4e2a dispatcher \u5bf9\u5e94\u591a\u4e2a concurrent handler)<\/p>\n<p>4.concurrent handler \u5185\u6709\u82e5\u5e72 message handler. \u6bcf\u4e2a concurrent handler \u5904\u7406\u4e00\u7c7b\u8868(\u5206\u8868)\u7684\u6d88\u606f.<\/p>\n<p>5.message handler \u5185\u6709\u4e00\u4e2a handler.<\/p>\n<p>6.handler \u662f\u5b9e\u73b0\u4e86 Handle() \u65b9\u6cd5\u7684\u5b9e\u9645\u4e1a\u52a1\u5904\u7406\u8005.(\u4e00\u6761 message \u88ab\u4e00\u4e2a handler \u5904\u7406)<\/p>\n<p>dispatcher \u7684\u8bbe\u8ba1\u76ee\u7684\u662f\u4e3a\u4e86\u7ef4\u62a4 partition offset.<\/p>\n<p>concurrent message handler \u7684\u8bbe\u8ba1\u76ee\u7684\u662f\u7b80\u5355\u7684\u5185\u90e8\u6269\u5bb9,<\/p>\n<p>message handler \u7684\u8bbe\u8ba1\u76ee\u7684\u662f\u590d\u7528\u4e1a\u52a1\u5224\u65ad\u548c\u9519\u8bef\u5904\u7406, \u8ba9 handler \u53ef\u4ee5\u53ea\u5199\u4e1a\u52a1.<\/p>\n<p>\u76ee\u524d\u7684\u4e3b\u8981\u95ee\u9898\u662f, \u6211\u90fd\u662f\u7528 NewXX() \u548c Run()\u65b9\u6cd5, \u5728\u6bcf\u4e00\u4e2a Run() \u65b9\u6cd5\u8c03\u7528\u5b83\u7684\u5b50 handler \u7684 Run(). \u5728 NewXX()\u65b9\u6cd5\u91cc\u8c03\u7528\u5b50 handler \u7684 NewXX() \u65b9\u6cd5.<\/p>\n<p>\u6700\u540e\u5bfc\u81f4\u4ee3\u7801\u7ed3\u6784\u6bd4\u8f83\u590d\u6742, \u800c\u4e14\u5f88\u96be\u7406\u6e05. \u4e0d\u77e5\u9053\u8be5\u600e\u4e48\u4f18\u5316<\/p>\n<p>\u6216\u8005\u5e94\u8be5\u770b\u4e9b\u4ec0\u4e48\u4e66 \/\u6587\u7ae0\u6bd4\u8f83\u597d. \u611f\u89c9\u601d\u8def\u662f\u5bf9\u7684, \u5c31\u662f\u4ee3\u7801\u5199\u7684\u592a\u7ed5\u4e86<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>2<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"2606842\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : madNeal <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e3a\u5565\u4e0d\u7528\u73b0\u6210\u7684\u8f6e\u5b50<\/p>\n<p>https:\/\/github.com\/segmentio\/kafka-go                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2606843\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : superfat <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u6700\u8fd1\u4e5f\u5728\u7528\u8fd9\u4e2a\u5e93\u505a consumer \u76f8\u5173\u5f00\u53d1                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Golang \u5982\u4f55\u89e3\u8026\u591a\u5c42\u7ea7 ka&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/138039"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=138039"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/138039\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=138039"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=138039"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=138039"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}