{"action":"created","comment":{"url":"https://api.github.com/repos/twingly/twingly-amqp/pulls/comments/42381964","id":42381964,"diff_hunk":"@@ -0,0 +1,124 @@\n+require \"raven\"\n+\n+module Twingly\n+  module AMQP\n+    class Subscription\n+      def initialize(queue_name:, exchange_topic:, routing_key:, consumer_threads: 4, prefetch: 20, connection: nil)\n+        @queue_name       = queue_name\n+        @exchange_topic   = exchange_topic\n+        @routing_key      = routing_key\n+        @consumer_threads = consumer_threads\n+        @prefetch         = prefetch\n+\n+        connection ||= Connection.new.connection\n+        @channel = create_channel(connection)\n+      end\n+\n+      def subscribe(&block)\n+        queue    = @channel.queue(@queue_name, queue_options)\n+        exchange = @channel.topic(@exchange_topic, durable: true)\n+        queue.bind(exchange, routing_key: @routing_key)\n+\n+        setup_traps\n+\n+        consumer = queue.subscribe(subscribe_options) do |delivery_info, metadata, payload|\n+          begin\n+            Raven::Context.clear!","path":"lib/twingly/amqp/subscription.rb","position":null,"original_position":26,"commit_id":"cff2acfade356a6f369e2e238700e9195aec4bea","original_commit_id":"5a19ae556a877278b1f3f2753d7d9477614a6519","user":{"login":"roback","id":2803721,"avatar_url":"https://avatars.githubusercontent.com/u/2803721?v=3","gravatar_id":"","url":"https://api.github.com/users/roback","html_url":"https://github.com/roback","followers_url":"https://api.github.com/users/roback/followers","following_url":"https://api.github.com/users/roback/following{/other_user}","gists_url":"https://api.github.com/users/roback/gists{/gist_id}","starred_url":"https://api.github.com/users/roback/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roback/subscriptions","organizations_url":"https://api.github.com/users/roback/orgs","repos_url":"https://api.github.com/users/roback/repos","events_url":"https://api.github.com/users/roback/events{/privacy}","received_events_url":"https://api.github.com/users/roback/received_events","type":"User","site_admin":false},"body":"Removed raven as dependency and added some callbacks instead: cff2acfade356a6f369e2e238700e9195aec4bea","created_at":"2015-10-19T15:04:04Z","updated_at":"2015-10-19T15:04:04Z","html_url":"https://github.com/twingly/twingly-amqp/pull/8#discussion_r42381964","pull_request_url":"https://api.github.com/repos/twingly/twingly-amqp/pulls/8","_links":{"self":{"href":"https://api.github.com/repos/twingly/twingly-amqp/pulls/comments/42381964"},"html":{"href":"https://github.com/twingly/twingly-amqp/pull/8#discussion_r42381964"},"pull_request":{"href":"https://api.github.com/repos/twingly/twingly-amqp/pulls/8"}}},"pull_request":{"url":"https://api.github.com/repos/twingly/twingly-amqp/pulls/8","id":48065859,"html_url":"https://github.com/twingly/twingly-amqp/pull/8","diff_url":"https://github.com/twingly/twingly-amqp/pull/8.diff","patch_url":"https://github.com/twingly/twingly-amqp/pull/8.patch","issue_url":"https://api.github.com/repos/twingly/twingly-amqp/issues/8","number":8,"state":"open","locked":false,"title":"AMQP subscription","user":{"login":"roback","id":2803721,"avatar_url":"https://avatars.githubusercontent.com/u/2803721?v=3","gravatar_id":"","url":"https://api.github.com/users/roback","html_url":"https://github.com/roback","followers_url":"https://api.github.com/users/roback/followers","following_url":"https://api.github.com/users/roback/following{/other_user}","gists_url":"https://api.github.com/users/roback/gists{/gist_id}","starred_url":"https://api.github.com/users/roback/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/roback/subscriptions","organizations_url":"https://api.github.com/users/roback/orgs","repos_url":"https://api.github.com/users/roback/repos","events_url":"https://api.github.com/users/roback/events{/privacy}","received_events_url":"https://api.github.com/users/roback/received_events","type":"User","site_admin":false},"body":"close #4\r\n\r\nAdded a class for subscribing to queues. The code is roughly the same as in chapman and zambezi.\r\n\r\nTested it by using `rabbitmqadmin`:\r\n\r\n```shell\r\n$ rabbitmqadmin declare exchange name=binlog-test type=topic\r\n\r\n$ bundle console\r\n> s = Twingly::AMQP::Subscription.new(queue_name: \"testing-twingly-amqp\", routing_key: \"testing.#\", exchange_topic: \"binlog-test\")\r\n> s.subscribe do |message|\r\n>   puts message\r\n> end\r\n```\r\n\r\n```shell\r\n$ rabbitmqadmin publish exchange=binlog-test routing_key=\"testing.test\" payload='{\"message\": \"hello!\"}'\r\n```\r\n\r\nTests for this would be nice, but I don't know how to do. I don't know how you should test `Subscription#subscribe` since it blocks the starting thread.","created_at":"2015-10-19T12:38:34Z","updated_at":"2015-10-19T15:04:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cf4053b1d0e2f36a58b5212c85a96ff545a5a171","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/twingly/twingly-amqp/pulls/8/commits","review_comments_url":"https://api.github.com/repos/twingly/twingly-amqp/pulls/8/comments","review_comment_url":"https://api.github.com/repos/twingly/twingly-amqp/pulls/comments{/number}","comments_url":"https://api.github.com/repos/twingly/twingly-amqp/issues/8/comments","statuses_url":"https://api.github.com/repos/twingly/twingly-amqp/statuses/cff2acfade356a6f369e2e238700e9195aec4bea","head":{"label":"twingly:amqp-subscription","ref":"amqp-subscription","sha":"cff2acfade356a6f369e2e238700e9195aec4bea","user":{"login":"twingly","id":280263,"avatar_url":"https://avatars.githubusercontent.com/u/280263?v=3","gravatar_id":"","url":"https://api.github.com/users/twingly","html_url":"https://github.com/twingly","followers_url":"https://api.github.com/users/twingly/followers","following_url":"https://api.github.com/users/twingly/following{/other_user}","gists_url":"https://api.github.com/users/twingly/gists{/gist_id}","starred_url":"https://api.github.com/users/twingly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twingly/subscriptions","organizations_url":"https://api.github.com/users/twingly/orgs","repos_url":"https://api.github.com/users/twingly/repos","events_url":"https://api.github.com/users/twingly/events{/privacy}","received_events_url":"https://api.github.com/users/twingly/received_events","type":"Organization","site_admin":false},"repo":{"id":43805440,"name":"twingly-amqp","full_name":"twingly/twingly-amqp","owner":{"login":"twingly","id":280263,"avatar_url":"https://avatars.githubusercontent.com/u/280263?v=3","gravatar_id":"","url":"https://api.github.com/users/twingly","html_url":"https://github.com/twingly","followers_url":"https://api.github.com/users/twingly/followers","following_url":"https://api.github.com/users/twingly/following{/other_user}","gists_url":"https://api.github.com/users/twingly/gists{/gist_id}","starred_url":"https://api.github.com/users/twingly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twingly/subscriptions","organizations_url":"https://api.github.com/users/twingly/orgs","repos_url":"https://api.github.com/users/twingly/repos","events_url":"https://api.github.com/users/twingly/events{/privacy}","received_events_url":"https://api.github.com/users/twingly/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/twingly/twingly-amqp","description":":bus: Ruby gem for publishing messages via RabbitMQ","fork":false,"url":"https://api.github.com/repos/twingly/twingly-amqp","forks_url":"https://api.github.com/repos/twingly/twingly-amqp/forks","keys_url":"https://api.github.com/repos/twingly/twingly-amqp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/twingly/twingly-amqp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/twingly/twingly-amqp/teams","hooks_url":"https://api.github.com/repos/twingly/twingly-amqp/hooks","issue_events_url":"https://api.github.com/repos/twingly/twingly-amqp/issues/events{/number}","events_url":"https://api.github.com/repos/twingly/twingly-amqp/events","assignees_url":"https://api.github.com/repos/twingly/twingly-amqp/assignees{/user}","branches_url":"https://api.github.com/repos/twingly/twingly-amqp/branches{/branch}","tags_url":"https://api.github.com/repos/twingly/twingly-amqp/tags","blobs_url":"https://api.github.com/repos/twingly/twingly-amqp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/twingly/twingly-amqp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/twingly/twingly-amqp/git/refs{/sha}","trees_url":"https://api.github.com/repos/twingly/twingly-amqp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/twingly/twingly-amqp/statuses/{sha}","languages_url":"https://api.github.com/repos/twingly/twingly-amqp/languages","stargazers_url":"https://api.github.com/repos/twingly/twingly-amqp/stargazers","contributors_url":"https://api.github.com/repos/twingly/twingly-amqp/contributors","subscribers_url":"https://api.github.com/repos/twingly/twingly-amqp/subscribers","subscription_url":"https://api.github.com/repos/twingly/twingly-amqp/subscription","commits_url":"https://api.github.com/repos/twingly/twingly-amqp/commits{/sha}","git_commits_url":"https://api.github.com/repos/twingly/twingly-amqp/git/commits{/sha}","comments_url":"https://api.github.com/repos/twingly/twingly-amqp/comments{/number}","issue_comment_url":"https://api.github.com/repos/twingly/twingly-amqp/issues/comments{/number}","contents_url":"https://api.github.com/repos/twingly/twingly-amqp/contents/{+path}","compare_url":"https://api.github.com/repos/twingly/twingly-amqp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/twingly/twingly-amqp/merges","archive_url":"https://api.github.com/repos/twingly/twingly-amqp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/twingly/twingly-amqp/downloads","issues_url":"https://api.github.com/repos/twingly/twingly-amqp/issues{/number}","pulls_url":"https://api.github.com/repos/twingly/twingly-amqp/pulls{/number}","milestones_url":"https://api.github.com/repos/twingly/twingly-amqp/milestones{/number}","notifications_url":"https://api.github.com/repos/twingly/twingly-amqp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/twingly/twingly-amqp/labels{/name}","releases_url":"https://api.github.com/repos/twingly/twingly-amqp/releases{/id}","created_at":"2015-10-07T09:11:33Z","updated_at":"2015-10-09T08:11:33Z","pushed_at":"2015-10-19T15:02:36Z","git_url":"git://github.com/twingly/twingly-amqp.git","ssh_url":"git@github.com:twingly/twingly-amqp.git","clone_url":"https://github.com/twingly/twingly-amqp.git","svn_url":"https://github.com/twingly/twingly-amqp","homepage":"","size":138,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":7,"forks":0,"open_issues":7,"watchers":0,"default_branch":"master"}},"base":{"label":"twingly:master","ref":"master","sha":"a6c553da5ea7926c71df425b5ec90d35c5c280fd","user":{"login":"twingly","id":280263,"avatar_url":"https://avatars.githubusercontent.com/u/280263?v=3","gravatar_id":"","url":"https://api.github.com/users/twingly","html_url":"https://github.com/twingly","followers_url":"https://api.github.com/users/twingly/followers","following_url":"https://api.github.com/users/twingly/following{/other_user}","gists_url":"https://api.github.com/users/twingly/gists{/gist_id}","starred_url":"https://api.github.com/users/twingly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twingly/subscriptions","organizations_url":"https://api.github.com/users/twingly/orgs","repos_url":"https://api.github.com/users/twingly/repos","events_url":"https://api.github.com/users/twingly/events{/privacy}","received_events_url":"https://api.github.com/users/twingly/received_events","type":"Organization","site_admin":false},"repo":{"id":43805440,"name":"twingly-amqp","full_name":"twingly/twingly-amqp","owner":{"login":"twingly","id":280263,"avatar_url":"https://avatars.githubusercontent.com/u/280263?v=3","gravatar_id":"","url":"https://api.github.com/users/twingly","html_url":"https://github.com/twingly","followers_url":"https://api.github.com/users/twingly/followers","following_url":"https://api.github.com/users/twingly/following{/other_user}","gists_url":"https://api.github.com/users/twingly/gists{/gist_id}","starred_url":"https://api.github.com/users/twingly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twingly/subscriptions","organizations_url":"https://api.github.com/users/twingly/orgs","repos_url":"https://api.github.com/users/twingly/repos","events_url":"https://api.github.com/users/twingly/events{/privacy}","received_events_url":"https://api.github.com/users/twingly/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/twingly/twingly-amqp","description":":bus: Ruby gem for publishing messages via RabbitMQ","fork":false,"url":"https://api.github.com/repos/twingly/twingly-amqp","forks_url":"https://api.github.com/repos/twingly/twingly-amqp/forks","keys_url":"https://api.github.com/repos/twingly/twingly-amqp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/twingly/twingly-amqp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/twingly/twingly-amqp/teams","hooks_url":"https://api.github.com/repos/twingly/twingly-amqp/hooks","issue_events_url":"https://api.github.com/repos/twingly/twingly-amqp/issues/events{/number}","events_url":"https://api.github.com/repos/twingly/twingly-amqp/events","assignees_url":"https://api.github.com/repos/twingly/twingly-amqp/assignees{/user}","branches_url":"https://api.github.com/repos/twingly/twingly-amqp/branches{/branch}","tags_url":"https://api.github.com/repos/twingly/twingly-amqp/tags","blobs_url":"https://api.github.com/repos/twingly/twingly-amqp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/twingly/twingly-amqp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/twingly/twingly-amqp/git/refs{/sha}","trees_url":"https://api.github.com/repos/twingly/twingly-amqp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/twingly/twingly-amqp/statuses/{sha}","languages_url":"https://api.github.com/repos/twingly/twingly-amqp/languages","stargazers_url":"https://api.github.com/repos/twingly/twingly-amqp/stargazers","contributors_url":"https://api.github.com/repos/twingly/twingly-amqp/contributors","subscribers_url":"https://api.github.com/repos/twingly/twingly-amqp/subscribers","subscription_url":"https://api.github.com/repos/twingly/twingly-amqp/subscription","commits_url":"https://api.github.com/repos/twingly/twingly-amqp/commits{/sha}","git_commits_url":"https://api.github.com/repos/twingly/twingly-amqp/git/commits{/sha}","comments_url":"https://api.github.com/repos/twingly/twingly-amqp/comments{/number}","issue_comment_url":"https://api.github.com/repos/twingly/twingly-amqp/issues/comments{/number}","contents_url":"https://api.github.com/repos/twingly/twingly-amqp/contents/{+path}","compare_url":"https://api.github.com/repos/twingly/twingly-amqp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/twingly/twingly-amqp/merges","archive_url":"https://api.github.com/repos/twingly/twingly-amqp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/twingly/twingly-amqp/downloads","issues_url":"https://api.github.com/repos/twingly/twingly-amqp/issues{/number}","pulls_url":"https://api.github.com/repos/twingly/twingly-amqp/pulls{/number}","milestones_url":"https://api.github.com/repos/twingly/twingly-amqp/milestones{/number}","notifications_url":"https://api.github.com/repos/twingly/twingly-amqp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/twingly/twingly-amqp/labels{/name}","releases_url":"https://api.github.com/repos/twingly/twingly-amqp/releases{/id}","created_at":"2015-10-07T09:11:33Z","updated_at":"2015-10-09T08:11:33Z","pushed_at":"2015-10-19T15:02:36Z","git_url":"git://github.com/twingly/twingly-amqp.git","ssh_url":"git@github.com:twingly/twingly-amqp.git","clone_url":"https://github.com/twingly/twingly-amqp.git","svn_url":"https://github.com/twingly/twingly-amqp","homepage":"","size":138,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":7,"forks":0,"open_issues":7,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/twingly/twingly-amqp/pulls/8"},"html":{"href":"https://github.com/twingly/twingly-amqp/pull/8"},"issue":{"href":"https://api.github.com/repos/twingly/twingly-amqp/issues/8"},"comments":{"href":"https://api.github.com/repos/twingly/twingly-amqp/issues/8/comments"},"review_comments":{"href":"https://api.github.com/repos/twingly/twingly-amqp/pulls/8/comments"},"review_comment":{"href":"https://api.github.com/repos/twingly/twingly-amqp/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/twingly/twingly-amqp/pulls/8/commits"},"statuses":{"href":"https://api.github.com/repos/twingly/twingly-amqp/statuses/cff2acfade356a6f369e2e238700e9195aec4bea"}}}}