{"action":"created","comment":{"url":"https://api.github.com/repos/m3db/m3msg/pulls/comments/183757966","pull_request_review_id":114816586,"id":183757966,"diff_hunk":"@@ -0,0 +1,172 @@\n+// Copyright (c) 2018 Uber Technologies, Inc.\n+//\n+// Permission is hereby granted, free of charge, to any person obtaining a copy\n+// of this software and associated documentation files (the \"Software\"), to deal\n+// in the Software without restriction, including without limitation the rights\n+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+// copies of the Software, and to permit persons to whom the Software is\n+// furnished to do so, subject to the following conditions:\n+//\n+// The above copyright notice and this permission notice shall be included in\n+// all copies or substantial portions of the Software.\n+//\n+// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n+// THE SOFTWARE.\n+\n+package consumer\n+\n+import (\n+\t\"bufio\"\n+\t\"net\"\n+\t\"sync\"\n+\n+\t\"github.com/m3db/m3msg/generated/proto/msgpb\"\n+\t\"github.com/m3db/m3msg/protocol/proto\"\n+)\n+\n+type listener struct {\n+\tnet.Listener\n+\n+\topts    Options\n+\tmsgPool *messagePool\n+}\n+\n+// NewListener creates a consumer listener.\n+func NewListener(addr string, opts Options) (Listener, error) {\n+\tif opts == nil {\n+\t\topts = NewOptions()\n+\t}\n+\tlis, err := net.Listen(\"tcp\", addr)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\tmPool := newMessagePool(opts.MessagePoolOptions())\n+\tmPool.Init()\n+\treturn &listener{\n+\t\tListener: lis,\n+\t\topts:     opts,\n+\t\tmsgPool:  mPool,\n+\t}, nil\n+}\n+\n+func (l *listener) Accept() (Consumer, error) {\n+\tconn, err := l.Listener.Accept()\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\treturn newConsumer(conn, l.msgPool, l.opts), nil\n+}\n+\n+type consumer struct {\n+\topts   Options\n+\tmPool  *messagePool\n+\tencdec proto.EncodeDecoder\n+\trw     *bufio.ReadWriter\n+\tconn   net.Conn\n+\n+\tackLock sync.Mutex\n+\tackPb   msgpb.Ack\n+\tcanAck  bool\n+}\n+\n+func newConsumer(\n+\tconn net.Conn,\n+\tmPool *messagePool,\n+\topts Options,\n+) *consumer {\n+\tr := bufio.NewReaderSize(conn, opts.ConnectionReadBufferSize())\n+\tw := bufio.NewWriterSize(conn, opts.ConnectionWriteBufferSize())\n+\trw := bufio.NewReadWriter(r, w)\n+\treturn &consumer{\n+\t\topts:   opts,\n+\t\tmPool:  mPool,\n+\t\tencdec: proto.NewEncodeDecoder(rw, opts.EncodeDecoderOptions()),\n+\t\trw:     rw,\n+\t\tconn:   conn,\n+\t\tcanAck: true,\n+\t}\n+}\n+\n+func (c *consumer) Message() (Message, error) {\n+\tm := c.mPool.Get()\n+\tm.reset(c)\n+\tif err := c.encdec.Decode(m); err != nil {\n+\t\tc.mPool.Put(m)\n+\t\treturn nil, err\n+\t}\n+\treturn m, nil\n+}\n+\n+// This function could be called concurrently if messages are being\n+// processed concurrently.\n+func (c *consumer) ack(m msgpb.Metadata) {\n+\tc.ackLock.Lock()\n+\tif !c.canAck {\n+\t\tc.ackLock.Unlock()\n+\t\treturn","path":"consumer/consumer.go","position":111,"original_position":111,"commit_id":"25390eb8c8f55ea652764692c5136dfb60c43f06","original_commit_id":"25390eb8c8f55ea652764692c5136dfb60c43f06","user":{"login":"cw9","id":6710599,"avatar_url":"https://avatars0.githubusercontent.com/u/6710599?v=4","gravatar_id":"","url":"https://api.github.com/users/cw9","html_url":"https://github.com/cw9","followers_url":"https://api.github.com/users/cw9/followers","following_url":"https://api.github.com/users/cw9/following{/other_user}","gists_url":"https://api.github.com/users/cw9/gists{/gist_id}","starred_url":"https://api.github.com/users/cw9/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cw9/subscriptions","organizations_url":"https://api.github.com/users/cw9/orgs","repos_url":"https://api.github.com/users/cw9/repos","events_url":"https://api.github.com/users/cw9/events{/privacy}","received_events_url":"https://api.github.com/users/cw9/received_events","type":"User","site_admin":false},"body":"sure sounds good","created_at":"2018-04-24T14:42:07Z","updated_at":"2018-04-24T14:42:07Z","html_url":"https://github.com/m3db/m3msg/pull/11#discussion_r183757966","pull_request_url":"https://api.github.com/repos/m3db/m3msg/pulls/11","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/m3db/m3msg/pulls/comments/183757966"},"html":{"href":"https://github.com/m3db/m3msg/pull/11#discussion_r183757966"},"pull_request":{"href":"https://api.github.com/repos/m3db/m3msg/pulls/11"}},"in_reply_to_id":183437352},"pull_request":{"url":"https://api.github.com/repos/m3db/m3msg/pulls/11","id":183284717,"html_url":"https://github.com/m3db/m3msg/pull/11","diff_url":"https://github.com/m3db/m3msg/pull/11.diff","patch_url":"https://github.com/m3db/m3msg/pull/11.patch","issue_url":"https://api.github.com/repos/m3db/m3msg/issues/11","number":11,"state":"open","locked":false,"title":"Add consumer","user":{"login":"cw9","id":6710599,"avatar_url":"https://avatars0.githubusercontent.com/u/6710599?v=4","gravatar_id":"","url":"https://api.github.com/users/cw9","html_url":"https://github.com/cw9","followers_url":"https://api.github.com/users/cw9/followers","following_url":"https://api.github.com/users/cw9/following{/other_user}","gists_url":"https://api.github.com/users/cw9/gists{/gist_id}","starred_url":"https://api.github.com/users/cw9/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cw9/subscriptions","organizations_url":"https://api.github.com/users/cw9/orgs","repos_url":"https://api.github.com/users/cw9/repos","events_url":"https://api.github.com/users/cw9/events{/privacy}","received_events_url":"https://api.github.com/users/cw9/received_events","type":"User","site_admin":false},"body":"This pr adds consumer that receives message from producer and supports acking per message, the interface is similar to net.Listener + net.Conn\r\n\r\n@xichen2020 @jeromefroe @jskelcy @m-sandusky ","created_at":"2018-04-22T17:38:02Z","updated_at":"2018-04-24T14:42:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9d979658643aca0754317976fc3a3690daf18d8e","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/m3db/m3msg/pulls/11/commits","review_comments_url":"https://api.github.com/repos/m3db/m3msg/pulls/11/comments","review_comment_url":"https://api.github.com/repos/m3db/m3msg/pulls/comments{/number}","comments_url":"https://api.github.com/repos/m3db/m3msg/issues/11/comments","statuses_url":"https://api.github.com/repos/m3db/m3msg/statuses/25390eb8c8f55ea652764692c5136dfb60c43f06","head":{"label":"m3db:chao-consumer","ref":"chao-consumer","sha":"25390eb8c8f55ea652764692c5136dfb60c43f06","user":{"login":"m3db","id":19937171,"avatar_url":"https://avatars0.githubusercontent.com/u/19937171?v=4","gravatar_id":"","url":"https://api.github.com/users/m3db","html_url":"https://github.com/m3db","followers_url":"https://api.github.com/users/m3db/followers","following_url":"https://api.github.com/users/m3db/following{/other_user}","gists_url":"https://api.github.com/users/m3db/gists{/gist_id}","starred_url":"https://api.github.com/users/m3db/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m3db/subscriptions","organizations_url":"https://api.github.com/users/m3db/orgs","repos_url":"https://api.github.com/users/m3db/repos","events_url":"https://api.github.com/users/m3db/events{/privacy}","received_events_url":"https://api.github.com/users/m3db/received_events","type":"Organization","site_admin":false},"repo":{"id":126348256,"name":"m3msg","full_name":"m3db/m3msg","owner":{"login":"m3db","id":19937171,"avatar_url":"https://avatars0.githubusercontent.com/u/19937171?v=4","gravatar_id":"","url":"https://api.github.com/users/m3db","html_url":"https://github.com/m3db","followers_url":"https://api.github.com/users/m3db/followers","following_url":"https://api.github.com/users/m3db/following{/other_user}","gists_url":"https://api.github.com/users/m3db/gists{/gist_id}","starred_url":"https://api.github.com/users/m3db/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m3db/subscriptions","organizations_url":"https://api.github.com/users/m3db/orgs","repos_url":"https://api.github.com/users/m3db/repos","events_url":"https://api.github.com/users/m3db/events{/privacy}","received_events_url":"https://api.github.com/users/m3db/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/m3db/m3msg","description":null,"fork":false,"url":"https://api.github.com/repos/m3db/m3msg","forks_url":"https://api.github.com/repos/m3db/m3msg/forks","keys_url":"https://api.github.com/repos/m3db/m3msg/keys{/key_id}","collaborators_url":"https://api.github.com/repos/m3db/m3msg/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/m3db/m3msg/teams","hooks_url":"https://api.github.com/repos/m3db/m3msg/hooks","issue_events_url":"https://api.github.com/repos/m3db/m3msg/issues/events{/number}","events_url":"https://api.github.com/repos/m3db/m3msg/events","assignees_url":"https://api.github.com/repos/m3db/m3msg/assignees{/user}","branches_url":"https://api.github.com/repos/m3db/m3msg/branches{/branch}","tags_url":"https://api.github.com/repos/m3db/m3msg/tags","blobs_url":"https://api.github.com/repos/m3db/m3msg/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/m3db/m3msg/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/m3db/m3msg/git/refs{/sha}","trees_url":"https://api.github.com/repos/m3db/m3msg/git/trees{/sha}","statuses_url":"https://api.github.com/repos/m3db/m3msg/statuses/{sha}","languages_url":"https://api.github.com/repos/m3db/m3msg/languages","stargazers_url":"https://api.github.com/repos/m3db/m3msg/stargazers","contributors_url":"https://api.github.com/repos/m3db/m3msg/contributors","subscribers_url":"https://api.github.com/repos/m3db/m3msg/subscribers","subscription_url":"https://api.github.com/repos/m3db/m3msg/subscription","commits_url":"https://api.github.com/repos/m3db/m3msg/commits{/sha}","git_commits_url":"https://api.github.com/repos/m3db/m3msg/git/commits{/sha}","comments_url":"https://api.github.com/repos/m3db/m3msg/comments{/number}","issue_comment_url":"https://api.github.com/repos/m3db/m3msg/issues/comments{/number}","contents_url":"https://api.github.com/repos/m3db/m3msg/contents/{+path}","compare_url":"https://api.github.com/repos/m3db/m3msg/compare/{base}...{head}","merges_url":"https://api.github.com/repos/m3db/m3msg/merges","archive_url":"https://api.github.com/repos/m3db/m3msg/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/m3db/m3msg/downloads","issues_url":"https://api.github.com/repos/m3db/m3msg/issues{/number}","pulls_url":"https://api.github.com/repos/m3db/m3msg/pulls{/number}","milestones_url":"https://api.github.com/repos/m3db/m3msg/milestones{/number}","notifications_url":"https://api.github.com/repos/m3db/m3msg/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/m3db/m3msg/labels{/name}","releases_url":"https://api.github.com/repos/m3db/m3msg/releases{/id}","deployments_url":"https://api.github.com/repos/m3db/m3msg/deployments","created_at":"2018-03-22T14:32:21Z","updated_at":"2018-04-20T20:12:03Z","pushed_at":"2018-04-22T17:46:11Z","git_url":"git://github.com/m3db/m3msg.git","ssh_url":"git@github.com:m3db/m3msg.git","clone_url":"https://github.com/m3db/m3msg.git","svn_url":"https://github.com/m3db/m3msg","homepage":null,"size":90,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"m3db:master","ref":"master","sha":"45faa9a53b82d9e365907b3172e0f1a611a48110","user":{"login":"m3db","id":19937171,"avatar_url":"https://avatars0.githubusercontent.com/u/19937171?v=4","gravatar_id":"","url":"https://api.github.com/users/m3db","html_url":"https://github.com/m3db","followers_url":"https://api.github.com/users/m3db/followers","following_url":"https://api.github.com/users/m3db/following{/other_user}","gists_url":"https://api.github.com/users/m3db/gists{/gist_id}","starred_url":"https://api.github.com/users/m3db/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m3db/subscriptions","organizations_url":"https://api.github.com/users/m3db/orgs","repos_url":"https://api.github.com/users/m3db/repos","events_url":"https://api.github.com/users/m3db/events{/privacy}","received_events_url":"https://api.github.com/users/m3db/received_events","type":"Organization","site_admin":false},"repo":{"id":126348256,"name":"m3msg","full_name":"m3db/m3msg","owner":{"login":"m3db","id":19937171,"avatar_url":"https://avatars0.githubusercontent.com/u/19937171?v=4","gravatar_id":"","url":"https://api.github.com/users/m3db","html_url":"https://github.com/m3db","followers_url":"https://api.github.com/users/m3db/followers","following_url":"https://api.github.com/users/m3db/following{/other_user}","gists_url":"https://api.github.com/users/m3db/gists{/gist_id}","starred_url":"https://api.github.com/users/m3db/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/m3db/subscriptions","organizations_url":"https://api.github.com/users/m3db/orgs","repos_url":"https://api.github.com/users/m3db/repos","events_url":"https://api.github.com/users/m3db/events{/privacy}","received_events_url":"https://api.github.com/users/m3db/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/m3db/m3msg","description":null,"fork":false,"url":"https://api.github.com/repos/m3db/m3msg","forks_url":"https://api.github.com/repos/m3db/m3msg/forks","keys_url":"https://api.github.com/repos/m3db/m3msg/keys{/key_id}","collaborators_url":"https://api.github.com/repos/m3db/m3msg/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/m3db/m3msg/teams","hooks_url":"https://api.github.com/repos/m3db/m3msg/hooks","issue_events_url":"https://api.github.com/repos/m3db/m3msg/issues/events{/number}","events_url":"https://api.github.com/repos/m3db/m3msg/events","assignees_url":"https://api.github.com/repos/m3db/m3msg/assignees{/user}","branches_url":"https://api.github.com/repos/m3db/m3msg/branches{/branch}","tags_url":"https://api.github.com/repos/m3db/m3msg/tags","blobs_url":"https://api.github.com/repos/m3db/m3msg/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/m3db/m3msg/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/m3db/m3msg/git/refs{/sha}","trees_url":"https://api.github.com/repos/m3db/m3msg/git/trees{/sha}","statuses_url":"https://api.github.com/repos/m3db/m3msg/statuses/{sha}","languages_url":"https://api.github.com/repos/m3db/m3msg/languages","stargazers_url":"https://api.github.com/repos/m3db/m3msg/stargazers","contributors_url":"https://api.github.com/repos/m3db/m3msg/contributors","subscribers_url":"https://api.github.com/repos/m3db/m3msg/subscribers","subscription_url":"https://api.github.com/repos/m3db/m3msg/subscription","commits_url":"https://api.github.com/repos/m3db/m3msg/commits{/sha}","git_commits_url":"https://api.github.com/repos/m3db/m3msg/git/commits{/sha}","comments_url":"https://api.github.com/repos/m3db/m3msg/comments{/number}","issue_comment_url":"https://api.github.com/repos/m3db/m3msg/issues/comments{/number}","contents_url":"https://api.github.com/repos/m3db/m3msg/contents/{+path}","compare_url":"https://api.github.com/repos/m3db/m3msg/compare/{base}...{head}","merges_url":"https://api.github.com/repos/m3db/m3msg/merges","archive_url":"https://api.github.com/repos/m3db/m3msg/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/m3db/m3msg/downloads","issues_url":"https://api.github.com/repos/m3db/m3msg/issues{/number}","pulls_url":"https://api.github.com/repos/m3db/m3msg/pulls{/number}","milestones_url":"https://api.github.com/repos/m3db/m3msg/milestones{/number}","notifications_url":"https://api.github.com/repos/m3db/m3msg/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/m3db/m3msg/labels{/name}","releases_url":"https://api.github.com/repos/m3db/m3msg/releases{/id}","deployments_url":"https://api.github.com/repos/m3db/m3msg/deployments","created_at":"2018-03-22T14:32:21Z","updated_at":"2018-04-20T20:12:03Z","pushed_at":"2018-04-22T17:46:11Z","git_url":"git://github.com/m3db/m3msg.git","ssh_url":"git@github.com:m3db/m3msg.git","clone_url":"https://github.com/m3db/m3msg.git","svn_url":"https://github.com/m3db/m3msg","homepage":null,"size":90,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/m3db/m3msg/pulls/11"},"html":{"href":"https://github.com/m3db/m3msg/pull/11"},"issue":{"href":"https://api.github.com/repos/m3db/m3msg/issues/11"},"comments":{"href":"https://api.github.com/repos/m3db/m3msg/issues/11/comments"},"review_comments":{"href":"https://api.github.com/repos/m3db/m3msg/pulls/11/comments"},"review_comment":{"href":"https://api.github.com/repos/m3db/m3msg/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/m3db/m3msg/pulls/11/commits"},"statuses":{"href":"https://api.github.com/repos/m3db/m3msg/statuses/25390eb8c8f55ea652764692c5136dfb60c43f06"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"cw9"}}