{"action":"created","comment":{"url":"https://api.github.com/repos/alv-ch/job-ad-service/pulls/comments/200572874","pull_request_review_id":134913320,"id":200572874,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwMDU3Mjg3NA==","diff_hunk":"@@ -0,0 +1,125 @@\n+package ch.admin.seco.jobs.services.jobadservice.infrastructure.messagebroker.dlq;\n+\n+import com.fasterxml.jackson.core.type.TypeReference;\n+import com.fasterxml.jackson.databind.ObjectMapper;\n+import com.fasterxml.jackson.databind.node.ObjectNode;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+import org.springframework.cloud.stream.annotation.StreamListener;\n+import org.springframework.data.domain.Page;\n+import org.springframework.data.domain.Pageable;\n+import org.springframework.messaging.Message;\n+import org.springframework.messaging.MessageChannel;\n+import org.springframework.messaging.MessageHeaders;\n+import org.springframework.messaging.support.GenericMessage;\n+import org.springframework.messaging.support.MessageBuilder;\n+import org.springframework.transaction.annotation.Transactional;\n+\n+import javax.validation.constraints.NotNull;\n+import java.io.IOException;\n+import java.io.UncheckedIOException;\n+import java.time.Instant;\n+import java.util.*;\n+\n+import static ch.admin.seco.jobs.services.jobadservice.infrastructure.messagebroker.dlq.MessageBrokerChannels.JOB_AD_ACTION_DLQ_CHANNEL;\n+\n+@Transactional\n+public class DLQService {\n+    private static final String KAFKA_RECEIVED_TIMESTAMP = \"kafka_receivedTimestamp\";\n+\n+    private final Logger LOG = LoggerFactory.getLogger(DLQService.class);\n+\n+    private final DLQRepository dlqRepository;\n+    private final MessageChannel dlqResendChannel;\n+    private final ObjectMapper objectMapper;\n+    private final List<String> requiredHeaderNames;\n+\n+    public DLQService(MessageChannel dqlResendChannel, DLQRepository dlqRepository, List<String> requiredHeaderNames) {\n+        this.dlqResendChannel = dqlResendChannel;\n+        this.dlqRepository = dlqRepository;\n+        this.objectMapper = new ObjectMapper();\n+        this.requiredHeaderNames = Collections.unmodifiableList(requiredHeaderNames);\n+    }\n+\n+    public long getDLQItemListSize() {\n+        return this.dlqRepository.count();\n+    }\n+\n+    public Page<DLQItem> getDLQItemList(Pageable pageable) {\n+        return this.dlqRepository.findAll(pageable);\n+    }\n+\n+    public Optional<DLQItem> findById(String idString) {\n+        return this.dlqRepository.findById(new DLQItemId(idString));\n+    }\n+\n+    public void deleteDLQItemWithId(String idString) {\n+        this.dlqRepository.deleteById(new DLQItemId(idString));\n+    }\n+\n+    public void resendDLQItem(String idString) {\n+        final DLQItem dlqItem = this.dlqRepository.getOne(new DLQItemId(idString));\n+        final Message message = MessageBuilder\n+                .withPayload(dlqItem.getPayload())\n+                .copyHeaders(headersAsMap(dlqItem.getHeaders()))\n+                .build();\n+\n+        if (this.dlqResendChannel.send(message)) {\n+            this.dlqRepository.deleteById(new DLQItemId(idString));\n+        } else {\n+            LOG.error(\"Failed to resend dlq message: [header: {}, payload: {}]\", dlqItem.getHeaders(), dlqItem.getPayload());\n+        }\n+    }\n+\n+    //todo: Make this part general and decouple form the channel name\n+    @StreamListener(target = JOB_AD_ACTION_DLQ_CHANNEL)\n+    public void handleDLQMessage(@NotNull GenericMessage<?> message) {\n+\n+        final String header = extractHeaderAsString(message);","path":"infrastructure-messagebroker-dlq/src/main/java/ch/admin/seco/jobs/services/jobadservice/infrastructure/messagebroker/dlq/DLQService.java","position":78,"original_position":78,"commit_id":"dc4509b9db9622bc1be75bfa4170168a628cc353","original_commit_id":"dc4509b9db9622bc1be75bfa4170168a628cc353","user":{"login":"michael-wirth","id":3389626,"node_id":"MDQ6VXNlcjMzODk2MjY=","avatar_url":"https://avatars3.githubusercontent.com/u/3389626?v=4","gravatar_id":"","url":"https://api.github.com/users/michael-wirth","html_url":"https://github.com/michael-wirth","followers_url":"https://api.github.com/users/michael-wirth/followers","following_url":"https://api.github.com/users/michael-wirth/following{/other_user}","gists_url":"https://api.github.com/users/michael-wirth/gists{/gist_id}","starred_url":"https://api.github.com/users/michael-wirth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michael-wirth/subscriptions","organizations_url":"https://api.github.com/users/michael-wirth/orgs","repos_url":"https://api.github.com/users/michael-wirth/repos","events_url":"https://api.github.com/users/michael-wirth/events{/privacy}","received_events_url":"https://api.github.com/users/michael-wirth/received_events","type":"User","site_admin":false},"body":"Consider to save also the stacktrace, which is also save as  header value\r\nDon't we need the original kafka messageId?","created_at":"2018-07-06T07:42:01Z","updated_at":"2018-07-06T07:51:34Z","html_url":"https://github.com/alv-ch/job-ad-service/pull/137#discussion_r200572874","pull_request_url":"https://api.github.com/repos/alv-ch/job-ad-service/pulls/137","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/alv-ch/job-ad-service/pulls/comments/200572874"},"html":{"href":"https://github.com/alv-ch/job-ad-service/pull/137#discussion_r200572874"},"pull_request":{"href":"https://api.github.com/repos/alv-ch/job-ad-service/pulls/137"}}},"pull_request":{"url":"https://api.github.com/repos/alv-ch/job-ad-service/pulls/137","id":199205886,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk5MjA1ODg2","html_url":"https://github.com/alv-ch/job-ad-service/pull/137","diff_url":"https://github.com/alv-ch/job-ad-service/pull/137.diff","patch_url":"https://github.com/alv-ch/job-ad-service/pull/137.patch","issue_url":"https://api.github.com/repos/alv-ch/job-ad-service/issues/137","number":137,"state":"open","locked":false,"title":"Add MessageBrokerRestController utility rest endpoint","user":{"login":"birom","id":21288589,"node_id":"MDQ6VXNlcjIxMjg4NTg5","avatar_url":"https://avatars0.githubusercontent.com/u/21288589?v=4","gravatar_id":"","url":"https://api.github.com/users/birom","html_url":"https://github.com/birom","followers_url":"https://api.github.com/users/birom/followers","following_url":"https://api.github.com/users/birom/following{/other_user}","gists_url":"https://api.github.com/users/birom/gists{/gist_id}","starred_url":"https://api.github.com/users/birom/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/birom/subscriptions","organizations_url":"https://api.github.com/users/birom/orgs","repos_url":"https://api.github.com/users/birom/repos","events_url":"https://api.github.com/users/birom/events{/privacy}","received_events_url":"https://api.github.com/users/birom/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-07-04T10:26:56Z","updated_at":"2018-07-06T07:51:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"33dbbd83481e3ab55d7bf16e9d5825c76a9e3fae","assignee":null,"assignees":[],"requested_reviewers":[{"login":"pavax","id":5336841,"node_id":"MDQ6VXNlcjUzMzY4NDE=","avatar_url":"https://avatars1.githubusercontent.com/u/5336841?v=4","gravatar_id":"","url":"https://api.github.com/users/pavax","html_url":"https://github.com/pavax","followers_url":"https://api.github.com/users/pavax/followers","following_url":"https://api.github.com/users/pavax/following{/other_user}","gists_url":"https://api.github.com/users/pavax/gists{/gist_id}","starred_url":"https://api.github.com/users/pavax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pavax/subscriptions","organizations_url":"https://api.github.com/users/pavax/orgs","repos_url":"https://api.github.com/users/pavax/repos","events_url":"https://api.github.com/users/pavax/events{/privacy}","received_events_url":"https://api.github.com/users/pavax/received_events","type":"User","site_admin":false},{"login":"cjpsycos","id":7815345,"node_id":"MDQ6VXNlcjc4MTUzNDU=","avatar_url":"https://avatars0.githubusercontent.com/u/7815345?v=4","gravatar_id":"","url":"https://api.github.com/users/cjpsycos","html_url":"https://github.com/cjpsycos","followers_url":"https://api.github.com/users/cjpsycos/followers","following_url":"https://api.github.com/users/cjpsycos/following{/other_user}","gists_url":"https://api.github.com/users/cjpsycos/gists{/gist_id}","starred_url":"https://api.github.com/users/cjpsycos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cjpsycos/subscriptions","organizations_url":"https://api.github.com/users/cjpsycos/orgs","repos_url":"https://api.github.com/users/cjpsycos/repos","events_url":"https://api.github.com/users/cjpsycos/events{/privacy}","received_events_url":"https://api.github.com/users/cjpsycos/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[{"id":831014408,"node_id":"MDU6TGFiZWw4MzEwMTQ0MDg=","url":"https://api.github.com/repos/alv-ch/job-ad-service/labels/enhancement","name":"enhancement","color":"a2eeef","default":true}],"milestone":null,"commits_url":"https://api.github.com/repos/alv-ch/job-ad-service/pulls/137/commits","review_comments_url":"https://api.github.com/repos/alv-ch/job-ad-service/pulls/137/comments","review_comment_url":"https://api.github.com/repos/alv-ch/job-ad-service/pulls/comments{/number}","comments_url":"https://api.github.com/repos/alv-ch/job-ad-service/issues/137/comments","statuses_url":"https://api.github.com/repos/alv-ch/job-ad-service/statuses/dc4509b9db9622bc1be75bfa4170168a628cc353","head":{"label":"alv-ch:enhance-dlq","ref":"enhance-dlq","sha":"dc4509b9db9622bc1be75bfa4170168a628cc353","user":{"login":"alv-ch","id":7008756,"node_id":"MDEyOk9yZ2FuaXphdGlvbjcwMDg3NTY=","avatar_url":"https://avatars0.githubusercontent.com/u/7008756?v=4","gravatar_id":"","url":"https://api.github.com/users/alv-ch","html_url":"https://github.com/alv-ch","followers_url":"https://api.github.com/users/alv-ch/followers","following_url":"https://api.github.com/users/alv-ch/following{/other_user}","gists_url":"https://api.github.com/users/alv-ch/gists{/gist_id}","starred_url":"https://api.github.com/users/alv-ch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alv-ch/subscriptions","organizations_url":"https://api.github.com/users/alv-ch/orgs","repos_url":"https://api.github.com/users/alv-ch/repos","events_url":"https://api.github.com/users/alv-ch/events{/privacy}","received_events_url":"https://api.github.com/users/alv-ch/received_events","type":"Organization","site_admin":false},"repo":{"id":120743245,"node_id":"MDEwOlJlcG9zaXRvcnkxMjA3NDMyNDU=","name":"job-ad-service","full_name":"alv-ch/job-ad-service","owner":{"login":"alv-ch","id":7008756,"node_id":"MDEyOk9yZ2FuaXphdGlvbjcwMDg3NTY=","avatar_url":"https://avatars0.githubusercontent.com/u/7008756?v=4","gravatar_id":"","url":"https://api.github.com/users/alv-ch","html_url":"https://github.com/alv-ch","followers_url":"https://api.github.com/users/alv-ch/followers","following_url":"https://api.github.com/users/alv-ch/following{/other_user}","gists_url":"https://api.github.com/users/alv-ch/gists{/gist_id}","starred_url":"https://api.github.com/users/alv-ch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alv-ch/subscriptions","organizations_url":"https://api.github.com/users/alv-ch/orgs","repos_url":"https://api.github.com/users/alv-ch/repos","events_url":"https://api.github.com/users/alv-ch/events{/privacy}","received_events_url":"https://api.github.com/users/alv-ch/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alv-ch/job-ad-service","description":null,"fork":false,"url":"https://api.github.com/repos/alv-ch/job-ad-service","forks_url":"https://api.github.com/repos/alv-ch/job-ad-service/forks","keys_url":"https://api.github.com/repos/alv-ch/job-ad-service/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alv-ch/job-ad-service/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alv-ch/job-ad-service/teams","hooks_url":"https://api.github.com/repos/alv-ch/job-ad-service/hooks","issue_events_url":"https://api.github.com/repos/alv-ch/job-ad-service/issues/events{/number}","events_url":"https://api.github.com/repos/alv-ch/job-ad-service/events","assignees_url":"https://api.github.com/repos/alv-ch/job-ad-service/assignees{/user}","branches_url":"https://api.github.com/repos/alv-ch/job-ad-service/branches{/branch}","tags_url":"https://api.github.com/repos/alv-ch/job-ad-service/tags","blobs_url":"https://api.github.com/repos/alv-ch/job-ad-service/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alv-ch/job-ad-service/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alv-ch/job-ad-service/git/refs{/sha}","trees_url":"https://api.github.com/repos/alv-ch/job-ad-service/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alv-ch/job-ad-service/statuses/{sha}","languages_url":"https://api.github.com/repos/alv-ch/job-ad-service/languages","stargazers_url":"https://api.github.com/repos/alv-ch/job-ad-service/stargazers","contributors_url":"https://api.github.com/repos/alv-ch/job-ad-service/contributors","subscribers_url":"https://api.github.com/repos/alv-ch/job-ad-service/subscribers","subscription_url":"https://api.github.com/repos/alv-ch/job-ad-service/subscription","commits_url":"https://api.github.com/repos/alv-ch/job-ad-service/commits{/sha}","git_commits_url":"https://api.github.com/repos/alv-ch/job-ad-service/git/commits{/sha}","comments_url":"https://api.github.com/repos/alv-ch/job-ad-service/comments{/number}","issue_comment_url":"https://api.github.com/repos/alv-ch/job-ad-service/issues/comments{/number}","contents_url":"https://api.github.com/repos/alv-ch/job-ad-service/contents/{+path}","compare_url":"https://api.github.com/repos/alv-ch/job-ad-service/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alv-ch/job-ad-service/merges","archive_url":"https://api.github.com/repos/alv-ch/job-ad-service/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alv-ch/job-ad-service/downloads","issues_url":"https://api.github.com/repos/alv-ch/job-ad-service/issues{/number}","pulls_url":"https://api.github.com/repos/alv-ch/job-ad-service/pulls{/number}","milestones_url":"https://api.github.com/repos/alv-ch/job-ad-service/milestones{/number}","notifications_url":"https://api.github.com/repos/alv-ch/job-ad-service/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alv-ch/job-ad-service/labels{/name}","releases_url":"https://api.github.com/repos/alv-ch/job-ad-service/releases{/id}","deployments_url":"https://api.github.com/repos/alv-ch/job-ad-service/deployments","created_at":"2018-02-08T09:56:53Z","updated_at":"2018-07-05T19:55:27Z","pushed_at":"2018-07-05T19:55:25Z","git_url":"git://github.com/alv-ch/job-ad-service.git","ssh_url":"git@github.com:alv-ch/job-ad-service.git","clone_url":"https://github.com/alv-ch/job-ad-service.git","svn_url":"https://github.com/alv-ch/job-ad-service","homepage":null,"size":2235,"stargazers_count":1,"watchers_count":1,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":3,"license":null,"forks":1,"open_issues":3,"watchers":1,"default_branch":"master"}},"base":{"label":"alv-ch:master","ref":"master","sha":"154387a45166c1fb2174c2d412a81ff0bce2681e","user":{"login":"alv-ch","id":7008756,"node_id":"MDEyOk9yZ2FuaXphdGlvbjcwMDg3NTY=","avatar_url":"https://avatars0.githubusercontent.com/u/7008756?v=4","gravatar_id":"","url":"https://api.github.com/users/alv-ch","html_url":"https://github.com/alv-ch","followers_url":"https://api.github.com/users/alv-ch/followers","following_url":"https://api.github.com/users/alv-ch/following{/other_user}","gists_url":"https://api.github.com/users/alv-ch/gists{/gist_id}","starred_url":"https://api.github.com/users/alv-ch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alv-ch/subscriptions","organizations_url":"https://api.github.com/users/alv-ch/orgs","repos_url":"https://api.github.com/users/alv-ch/repos","events_url":"https://api.github.com/users/alv-ch/events{/privacy}","received_events_url":"https://api.github.com/users/alv-ch/received_events","type":"Organization","site_admin":false},"repo":{"id":120743245,"node_id":"MDEwOlJlcG9zaXRvcnkxMjA3NDMyNDU=","name":"job-ad-service","full_name":"alv-ch/job-ad-service","owner":{"login":"alv-ch","id":7008756,"node_id":"MDEyOk9yZ2FuaXphdGlvbjcwMDg3NTY=","avatar_url":"https://avatars0.githubusercontent.com/u/7008756?v=4","gravatar_id":"","url":"https://api.github.com/users/alv-ch","html_url":"https://github.com/alv-ch","followers_url":"https://api.github.com/users/alv-ch/followers","following_url":"https://api.github.com/users/alv-ch/following{/other_user}","gists_url":"https://api.github.com/users/alv-ch/gists{/gist_id}","starred_url":"https://api.github.com/users/alv-ch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alv-ch/subscriptions","organizations_url":"https://api.github.com/users/alv-ch/orgs","repos_url":"https://api.github.com/users/alv-ch/repos","events_url":"https://api.github.com/users/alv-ch/events{/privacy}","received_events_url":"https://api.github.com/users/alv-ch/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alv-ch/job-ad-service","description":null,"fork":false,"url":"https://api.github.com/repos/alv-ch/job-ad-service","forks_url":"https://api.github.com/repos/alv-ch/job-ad-service/forks","keys_url":"https://api.github.com/repos/alv-ch/job-ad-service/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alv-ch/job-ad-service/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alv-ch/job-ad-service/teams","hooks_url":"https://api.github.com/repos/alv-ch/job-ad-service/hooks","issue_events_url":"https://api.github.com/repos/alv-ch/job-ad-service/issues/events{/number}","events_url":"https://api.github.com/repos/alv-ch/job-ad-service/events","assignees_url":"https://api.github.com/repos/alv-ch/job-ad-service/assignees{/user}","branches_url":"https://api.github.com/repos/alv-ch/job-ad-service/branches{/branch}","tags_url":"https://api.github.com/repos/alv-ch/job-ad-service/tags","blobs_url":"https://api.github.com/repos/alv-ch/job-ad-service/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alv-ch/job-ad-service/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alv-ch/job-ad-service/git/refs{/sha}","trees_url":"https://api.github.com/repos/alv-ch/job-ad-service/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alv-ch/job-ad-service/statuses/{sha}","languages_url":"https://api.github.com/repos/alv-ch/job-ad-service/languages","stargazers_url":"https://api.github.com/repos/alv-ch/job-ad-service/stargazers","contributors_url":"https://api.github.com/repos/alv-ch/job-ad-service/contributors","subscribers_url":"https://api.github.com/repos/alv-ch/job-ad-service/subscribers","subscription_url":"https://api.github.com/repos/alv-ch/job-ad-service/subscription","commits_url":"https://api.github.com/repos/alv-ch/job-ad-service/commits{/sha}","git_commits_url":"https://api.github.com/repos/alv-ch/job-ad-service/git/commits{/sha}","comments_url":"https://api.github.com/repos/alv-ch/job-ad-service/comments{/number}","issue_comment_url":"https://api.github.com/repos/alv-ch/job-ad-service/issues/comments{/number}","contents_url":"https://api.github.com/repos/alv-ch/job-ad-service/contents/{+path}","compare_url":"https://api.github.com/repos/alv-ch/job-ad-service/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alv-ch/job-ad-service/merges","archive_url":"https://api.github.com/repos/alv-ch/job-ad-service/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alv-ch/job-ad-service/downloads","issues_url":"https://api.github.com/repos/alv-ch/job-ad-service/issues{/number}","pulls_url":"https://api.github.com/repos/alv-ch/job-ad-service/pulls{/number}","milestones_url":"https://api.github.com/repos/alv-ch/job-ad-service/milestones{/number}","notifications_url":"https://api.github.com/repos/alv-ch/job-ad-service/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alv-ch/job-ad-service/labels{/name}","releases_url":"https://api.github.com/repos/alv-ch/job-ad-service/releases{/id}","deployments_url":"https://api.github.com/repos/alv-ch/job-ad-service/deployments","created_at":"2018-02-08T09:56:53Z","updated_at":"2018-07-05T19:55:27Z","pushed_at":"2018-07-05T19:55:25Z","git_url":"git://github.com/alv-ch/job-ad-service.git","ssh_url":"git@github.com:alv-ch/job-ad-service.git","clone_url":"https://github.com/alv-ch/job-ad-service.git","svn_url":"https://github.com/alv-ch/job-ad-service","homepage":null,"size":2235,"stargazers_count":1,"watchers_count":1,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":3,"license":null,"forks":1,"open_issues":3,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/alv-ch/job-ad-service/pulls/137"},"html":{"href":"https://github.com/alv-ch/job-ad-service/pull/137"},"issue":{"href":"https://api.github.com/repos/alv-ch/job-ad-service/issues/137"},"comments":{"href":"https://api.github.com/repos/alv-ch/job-ad-service/issues/137/comments"},"review_comments":{"href":"https://api.github.com/repos/alv-ch/job-ad-service/pulls/137/comments"},"review_comment":{"href":"https://api.github.com/repos/alv-ch/job-ad-service/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/alv-ch/job-ad-service/pulls/137/commits"},"statuses":{"href":"https://api.github.com/repos/alv-ch/job-ad-service/statuses/dc4509b9db9622bc1be75bfa4170168a628cc353"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"michael-wirth"}}