{"action":"created","comment":{"url":"https://api.github.com/repos/iZettle/izettle-toolbox/pulls/comments/71302412","id":71302412,"diff_hunk":"@@ -0,0 +1,132 @@\n+package com.izettle.messaging.handler;\n+\n+import static com.izettle.java.ValueChecks.empty;\n+\n+import com.amazonaws.services.sqs.model.Message;\n+import com.fasterxml.jackson.databind.ObjectMapper;\n+\n+import com.izettle.messaging.MessagingException;\n+import com.izettle.messaging.serialization.AmazonSNSMessage;\n+import com.izettle.messaging.serialization.AmazonSQSMessage;\n+import com.izettle.messaging.serialization.JsonSerializer;\n+import com.izettle.messaging.serialization.MessageDeserializer;\n+import java.util.ArrayList;\n+import java.util.List;\n+import java.util.Map;\n+import java.util.concurrent.ConcurrentHashMap;\n+\n+/**\n+ * Routes messages to other MessageHandlers based on message type. All handlers added with the\n+ * addHandler() method will be called whenever a message of the supplied type is received by this class.\n+ * The handlers need to delete the messages from the queue after handling them, using the receipt handle in\n+ * the AmazonSQSMessage.\n+ *\n+ * The received message will need either a Subject or a Type field in the body, as the value of one of these fields\n+ * is used to map to a handler.\n+ */\n+public class AsyncMessageDispatcher implements MessageHandler<Message> {\n+    private final MessageDeserializer<String> messageDeserializer;\n+    private final Map<String, ListOfMessageHandlersForType> messageHandlersPerEventName = new ConcurrentHashMap<>();\n+    private final List<MessageHandler<AmazonSQSMessage>> defaultMessageHandlers = new ArrayList<>();\n+    private static final ObjectMapper JSON_MAPPER = JsonSerializer.getInstance();\n+\n+    public static AsyncMessageDispatcher nonEncryptedMessageDispatcher() {\n+        return new AsyncMessageDispatcher();\n+    }\n+\n+    public static AsyncMessageDispatcher encryptedMessageDispatcher(\n+        byte[] privatePgpKey,\n+        final String privatePgpKeyPassphrase\n+    ) throws MessagingException {\n+        if (empty(privatePgpKey) || empty(privatePgpKeyPassphrase)) {","path":"izettle-messaging/src/main/java/com/izettle/messaging/handler/AsyncMessageDispatcher.java","position":41,"original_position":41,"commit_id":"f5f301c1f280f162ca3d165687ac0b2d9a6f8a27","original_commit_id":"f5f301c1f280f162ca3d165687ac0b2d9a6f8a27","user":{"login":"adamvoncorswant","id":1142587,"avatar_url":"https://avatars.githubusercontent.com/u/1142587?v=3","gravatar_id":"","url":"https://api.github.com/users/adamvoncorswant","html_url":"https://github.com/adamvoncorswant","followers_url":"https://api.github.com/users/adamvoncorswant/followers","following_url":"https://api.github.com/users/adamvoncorswant/following{/other_user}","gists_url":"https://api.github.com/users/adamvoncorswant/gists{/gist_id}","starred_url":"https://api.github.com/users/adamvoncorswant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamvoncorswant/subscriptions","organizations_url":"https://api.github.com/users/adamvoncorswant/orgs","repos_url":"https://api.github.com/users/adamvoncorswant/repos","events_url":"https://api.github.com/users/adamvoncorswant/events{/privacy}","received_events_url":"https://api.github.com/users/adamvoncorswant/received_events","type":"User","site_admin":false},"body":"Minor: `allEmpty` is suitable here","created_at":"2016-07-19T09:32:41Z","updated_at":"2016-07-19T09:32:41Z","html_url":"https://github.com/iZettle/izettle-toolbox/pull/179#discussion_r71302412","pull_request_url":"https://api.github.com/repos/iZettle/izettle-toolbox/pulls/179","_links":{"self":{"href":"https://api.github.com/repos/iZettle/izettle-toolbox/pulls/comments/71302412"},"html":{"href":"https://github.com/iZettle/izettle-toolbox/pull/179#discussion_r71302412"},"pull_request":{"href":"https://api.github.com/repos/iZettle/izettle-toolbox/pulls/179"}}},"pull_request":{"url":"https://api.github.com/repos/iZettle/izettle-toolbox/pulls/179","id":77938750,"html_url":"https://github.com/iZettle/izettle-toolbox/pull/179","diff_url":"https://github.com/iZettle/izettle-toolbox/pull/179.diff","patch_url":"https://github.com/iZettle/izettle-toolbox/pull/179.patch","issue_url":"https://api.github.com/repos/iZettle/izettle-toolbox/issues/179","number":179,"state":"open","locked":false,"title":"Add AsyncMessageDispatcher for asynchronous interaction with SQS","user":{"login":"powion","id":4322541,"avatar_url":"https://avatars.githubusercontent.com/u/4322541?v=3","gravatar_id":"","url":"https://api.github.com/users/powion","html_url":"https://github.com/powion","followers_url":"https://api.github.com/users/powion/followers","following_url":"https://api.github.com/users/powion/following{/other_user}","gists_url":"https://api.github.com/users/powion/gists{/gist_id}","starred_url":"https://api.github.com/users/powion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/powion/subscriptions","organizations_url":"https://api.github.com/users/powion/orgs","repos_url":"https://api.github.com/users/powion/repos","events_url":"https://api.github.com/users/powion/events{/privacy}","received_events_url":"https://api.github.com/users/powion/received_events","type":"User","site_admin":false},"body":"This dispatcher passes along the receipt handle from SQS, allowing the receiving handler to delete the message at a later point.","created_at":"2016-07-19T08:48:12Z","updated_at":"2016-07-19T09:32:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d1ef3a06979df560cfcb717e17e8c091a78a6f67","assignee":{"login":"freddd","id":1108176,"avatar_url":"https://avatars.githubusercontent.com/u/1108176?v=3","gravatar_id":"","url":"https://api.github.com/users/freddd","html_url":"https://github.com/freddd","followers_url":"https://api.github.com/users/freddd/followers","following_url":"https://api.github.com/users/freddd/following{/other_user}","gists_url":"https://api.github.com/users/freddd/gists{/gist_id}","starred_url":"https://api.github.com/users/freddd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/freddd/subscriptions","organizations_url":"https://api.github.com/users/freddd/orgs","repos_url":"https://api.github.com/users/freddd/repos","events_url":"https://api.github.com/users/freddd/events{/privacy}","received_events_url":"https://api.github.com/users/freddd/received_events","type":"User","site_admin":false},"assignees":[{"login":"freddd","id":1108176,"avatar_url":"https://avatars.githubusercontent.com/u/1108176?v=3","gravatar_id":"","url":"https://api.github.com/users/freddd","html_url":"https://github.com/freddd","followers_url":"https://api.github.com/users/freddd/followers","following_url":"https://api.github.com/users/freddd/following{/other_user}","gists_url":"https://api.github.com/users/freddd/gists{/gist_id}","starred_url":"https://api.github.com/users/freddd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/freddd/subscriptions","organizations_url":"https://api.github.com/users/freddd/orgs","repos_url":"https://api.github.com/users/freddd/repos","events_url":"https://api.github.com/users/freddd/events{/privacy}","received_events_url":"https://api.github.com/users/freddd/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/iZettle/izettle-toolbox/pulls/179/commits","review_comments_url":"https://api.github.com/repos/iZettle/izettle-toolbox/pulls/179/comments","review_comment_url":"https://api.github.com/repos/iZettle/izettle-toolbox/pulls/comments{/number}","comments_url":"https://api.github.com/repos/iZettle/izettle-toolbox/issues/179/comments","statuses_url":"https://api.github.com/repos/iZettle/izettle-toolbox/statuses/f5f301c1f280f162ca3d165687ac0b2d9a6f8a27","head":{"label":"iZettle:async-sqs-dispatcher","ref":"async-sqs-dispatcher","sha":"f5f301c1f280f162ca3d165687ac0b2d9a6f8a27","user":{"login":"iZettle","id":1272526,"avatar_url":"https://avatars.githubusercontent.com/u/1272526?v=3","gravatar_id":"","url":"https://api.github.com/users/iZettle","html_url":"https://github.com/iZettle","followers_url":"https://api.github.com/users/iZettle/followers","following_url":"https://api.github.com/users/iZettle/following{/other_user}","gists_url":"https://api.github.com/users/iZettle/gists{/gist_id}","starred_url":"https://api.github.com/users/iZettle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iZettle/subscriptions","organizations_url":"https://api.github.com/users/iZettle/orgs","repos_url":"https://api.github.com/users/iZettle/repos","events_url":"https://api.github.com/users/iZettle/events{/privacy}","received_events_url":"https://api.github.com/users/iZettle/received_events","type":"Organization","site_admin":false},"repo":{"id":13087671,"name":"izettle-toolbox","full_name":"iZettle/izettle-toolbox","owner":{"login":"iZettle","id":1272526,"avatar_url":"https://avatars.githubusercontent.com/u/1272526?v=3","gravatar_id":"","url":"https://api.github.com/users/iZettle","html_url":"https://github.com/iZettle","followers_url":"https://api.github.com/users/iZettle/followers","following_url":"https://api.github.com/users/iZettle/following{/other_user}","gists_url":"https://api.github.com/users/iZettle/gists{/gist_id}","starred_url":"https://api.github.com/users/iZettle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iZettle/subscriptions","organizations_url":"https://api.github.com/users/iZettle/orgs","repos_url":"https://api.github.com/users/iZettle/repos","events_url":"https://api.github.com/users/iZettle/events{/privacy}","received_events_url":"https://api.github.com/users/iZettle/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/iZettle/izettle-toolbox","description":"","fork":false,"url":"https://api.github.com/repos/iZettle/izettle-toolbox","forks_url":"https://api.github.com/repos/iZettle/izettle-toolbox/forks","keys_url":"https://api.github.com/repos/iZettle/izettle-toolbox/keys{/key_id}","collaborators_url":"https://api.github.com/repos/iZettle/izettle-toolbox/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/iZettle/izettle-toolbox/teams","hooks_url":"https://api.github.com/repos/iZettle/izettle-toolbox/hooks","issue_events_url":"https://api.github.com/repos/iZettle/izettle-toolbox/issues/events{/number}","events_url":"https://api.github.com/repos/iZettle/izettle-toolbox/events","assignees_url":"https://api.github.com/repos/iZettle/izettle-toolbox/assignees{/user}","branches_url":"https://api.github.com/repos/iZettle/izettle-toolbox/branches{/branch}","tags_url":"https://api.github.com/repos/iZettle/izettle-toolbox/tags","blobs_url":"https://api.github.com/repos/iZettle/izettle-toolbox/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/iZettle/izettle-toolbox/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/iZettle/izettle-toolbox/git/refs{/sha}","trees_url":"https://api.github.com/repos/iZettle/izettle-toolbox/git/trees{/sha}","statuses_url":"https://api.github.com/repos/iZettle/izettle-toolbox/statuses/{sha}","languages_url":"https://api.github.com/repos/iZettle/izettle-toolbox/languages","stargazers_url":"https://api.github.com/repos/iZettle/izettle-toolbox/stargazers","contributors_url":"https://api.github.com/repos/iZettle/izettle-toolbox/contributors","subscribers_url":"https://api.github.com/repos/iZettle/izettle-toolbox/subscribers","subscription_url":"https://api.github.com/repos/iZettle/izettle-toolbox/subscription","commits_url":"https://api.github.com/repos/iZettle/izettle-toolbox/commits{/sha}","git_commits_url":"https://api.github.com/repos/iZettle/izettle-toolbox/git/commits{/sha}","comments_url":"https://api.github.com/repos/iZettle/izettle-toolbox/comments{/number}","issue_comment_url":"https://api.github.com/repos/iZettle/izettle-toolbox/issues/comments{/number}","contents_url":"https://api.github.com/repos/iZettle/izettle-toolbox/contents/{+path}","compare_url":"https://api.github.com/repos/iZettle/izettle-toolbox/compare/{base}...{head}","merges_url":"https://api.github.com/repos/iZettle/izettle-toolbox/merges","archive_url":"https://api.github.com/repos/iZettle/izettle-toolbox/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/iZettle/izettle-toolbox/downloads","issues_url":"https://api.github.com/repos/iZettle/izettle-toolbox/issues{/number}","pulls_url":"https://api.github.com/repos/iZettle/izettle-toolbox/pulls{/number}","milestones_url":"https://api.github.com/repos/iZettle/izettle-toolbox/milestones{/number}","notifications_url":"https://api.github.com/repos/iZettle/izettle-toolbox/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/iZettle/izettle-toolbox/labels{/name}","releases_url":"https://api.github.com/repos/iZettle/izettle-toolbox/releases{/id}","deployments_url":"https://api.github.com/repos/iZettle/izettle-toolbox/deployments","created_at":"2013-09-25T08:01:29Z","updated_at":"2016-01-11T12:47:53Z","pushed_at":"2016-07-19T08:48:12Z","git_url":"git://github.com/iZettle/izettle-toolbox.git","ssh_url":"git@github.com:iZettle/izettle-toolbox.git","clone_url":"https://github.com/iZettle/izettle-toolbox.git","svn_url":"https://github.com/iZettle/izettle-toolbox","homepage":null,"size":831,"stargazers_count":2,"watchers_count":2,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":7,"forks":0,"open_issues":7,"watchers":2,"default_branch":"master"}},"base":{"label":"iZettle:master","ref":"master","sha":"3d500a5d02fffd75d2a2050cac2907e6abd90ddb","user":{"login":"iZettle","id":1272526,"avatar_url":"https://avatars.githubusercontent.com/u/1272526?v=3","gravatar_id":"","url":"https://api.github.com/users/iZettle","html_url":"https://github.com/iZettle","followers_url":"https://api.github.com/users/iZettle/followers","following_url":"https://api.github.com/users/iZettle/following{/other_user}","gists_url":"https://api.github.com/users/iZettle/gists{/gist_id}","starred_url":"https://api.github.com/users/iZettle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iZettle/subscriptions","organizations_url":"https://api.github.com/users/iZettle/orgs","repos_url":"https://api.github.com/users/iZettle/repos","events_url":"https://api.github.com/users/iZettle/events{/privacy}","received_events_url":"https://api.github.com/users/iZettle/received_events","type":"Organization","site_admin":false},"repo":{"id":13087671,"name":"izettle-toolbox","full_name":"iZettle/izettle-toolbox","owner":{"login":"iZettle","id":1272526,"avatar_url":"https://avatars.githubusercontent.com/u/1272526?v=3","gravatar_id":"","url":"https://api.github.com/users/iZettle","html_url":"https://github.com/iZettle","followers_url":"https://api.github.com/users/iZettle/followers","following_url":"https://api.github.com/users/iZettle/following{/other_user}","gists_url":"https://api.github.com/users/iZettle/gists{/gist_id}","starred_url":"https://api.github.com/users/iZettle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iZettle/subscriptions","organizations_url":"https://api.github.com/users/iZettle/orgs","repos_url":"https://api.github.com/users/iZettle/repos","events_url":"https://api.github.com/users/iZettle/events{/privacy}","received_events_url":"https://api.github.com/users/iZettle/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/iZettle/izettle-toolbox","description":"","fork":false,"url":"https://api.github.com/repos/iZettle/izettle-toolbox","forks_url":"https://api.github.com/repos/iZettle/izettle-toolbox/forks","keys_url":"https://api.github.com/repos/iZettle/izettle-toolbox/keys{/key_id}","collaborators_url":"https://api.github.com/repos/iZettle/izettle-toolbox/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/iZettle/izettle-toolbox/teams","hooks_url":"https://api.github.com/repos/iZettle/izettle-toolbox/hooks","issue_events_url":"https://api.github.com/repos/iZettle/izettle-toolbox/issues/events{/number}","events_url":"https://api.github.com/repos/iZettle/izettle-toolbox/events","assignees_url":"https://api.github.com/repos/iZettle/izettle-toolbox/assignees{/user}","branches_url":"https://api.github.com/repos/iZettle/izettle-toolbox/branches{/branch}","tags_url":"https://api.github.com/repos/iZettle/izettle-toolbox/tags","blobs_url":"https://api.github.com/repos/iZettle/izettle-toolbox/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/iZettle/izettle-toolbox/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/iZettle/izettle-toolbox/git/refs{/sha}","trees_url":"https://api.github.com/repos/iZettle/izettle-toolbox/git/trees{/sha}","statuses_url":"https://api.github.com/repos/iZettle/izettle-toolbox/statuses/{sha}","languages_url":"https://api.github.com/repos/iZettle/izettle-toolbox/languages","stargazers_url":"https://api.github.com/repos/iZettle/izettle-toolbox/stargazers","contributors_url":"https://api.github.com/repos/iZettle/izettle-toolbox/contributors","subscribers_url":"https://api.github.com/repos/iZettle/izettle-toolbox/subscribers","subscription_url":"https://api.github.com/repos/iZettle/izettle-toolbox/subscription","commits_url":"https://api.github.com/repos/iZettle/izettle-toolbox/commits{/sha}","git_commits_url":"https://api.github.com/repos/iZettle/izettle-toolbox/git/commits{/sha}","comments_url":"https://api.github.com/repos/iZettle/izettle-toolbox/comments{/number}","issue_comment_url":"https://api.github.com/repos/iZettle/izettle-toolbox/issues/comments{/number}","contents_url":"https://api.github.com/repos/iZettle/izettle-toolbox/contents/{+path}","compare_url":"https://api.github.com/repos/iZettle/izettle-toolbox/compare/{base}...{head}","merges_url":"https://api.github.com/repos/iZettle/izettle-toolbox/merges","archive_url":"https://api.github.com/repos/iZettle/izettle-toolbox/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/iZettle/izettle-toolbox/downloads","issues_url":"https://api.github.com/repos/iZettle/izettle-toolbox/issues{/number}","pulls_url":"https://api.github.com/repos/iZettle/izettle-toolbox/pulls{/number}","milestones_url":"https://api.github.com/repos/iZettle/izettle-toolbox/milestones{/number}","notifications_url":"https://api.github.com/repos/iZettle/izettle-toolbox/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/iZettle/izettle-toolbox/labels{/name}","releases_url":"https://api.github.com/repos/iZettle/izettle-toolbox/releases{/id}","deployments_url":"https://api.github.com/repos/iZettle/izettle-toolbox/deployments","created_at":"2013-09-25T08:01:29Z","updated_at":"2016-01-11T12:47:53Z","pushed_at":"2016-07-19T08:48:12Z","git_url":"git://github.com/iZettle/izettle-toolbox.git","ssh_url":"git@github.com:iZettle/izettle-toolbox.git","clone_url":"https://github.com/iZettle/izettle-toolbox.git","svn_url":"https://github.com/iZettle/izettle-toolbox","homepage":null,"size":831,"stargazers_count":2,"watchers_count":2,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":7,"forks":0,"open_issues":7,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/iZettle/izettle-toolbox/pulls/179"},"html":{"href":"https://github.com/iZettle/izettle-toolbox/pull/179"},"issue":{"href":"https://api.github.com/repos/iZettle/izettle-toolbox/issues/179"},"comments":{"href":"https://api.github.com/repos/iZettle/izettle-toolbox/issues/179/comments"},"review_comments":{"href":"https://api.github.com/repos/iZettle/izettle-toolbox/pulls/179/comments"},"review_comment":{"href":"https://api.github.com/repos/iZettle/izettle-toolbox/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/iZettle/izettle-toolbox/pulls/179/commits"},"statuses":{"href":"https://api.github.com/repos/iZettle/izettle-toolbox/statuses/f5f301c1f280f162ca3d165687ac0b2d9a6f8a27"}}}}
{"actor":{"display_login":"adamvoncorswant"}}