{"action":"created","comment":{"url":"https://api.github.com/repos/spring-projects/spring-amqp/pulls/comments/92034579","pull_request_review_id":12544080,"id":92034579,"diff_hunk":"@@ -687,28 +690,89 @@ public void handleDelivery(String consumerTag, Envelope envelope,\n \t\t\t\t\tif (this.isRabbitTxManager) {\n \t\t\t\t\t\tConsumerChannelRegistry.registerConsumerChannel(getChannel(), this.connectionFactory);\n \t\t\t\t\t}\n-\t\t\t\t\tnew TransactionTemplate(this.transactionManager, this.transactionAttribute).execute(s -> {\n+\t\t\t\t\tif (this.transactionTemplate == null) {\n+\t\t\t\t\t\tthis.transactionTemplate =\n+\t\t\t\t\t\t\t\tnew TransactionTemplate(this.transactionManager, this.transactionAttribute);\n+\t\t\t\t\t}\n+\t\t\t\t\tthis.transactionTemplate.execute(s -> {\n \t\t\t\t\t\tConnectionFactoryUtils.bindResourceToTransaction(new RabbitResourceHolder(getChannel(), false),\n \t\t\t\t\t\t\t\tthis.connectionFactory, true);\n-\t\t\t\t\t\tcallExecuteListener(message, deliveryTag);\n+\t\t\t\t\t\t// unbound in ResourceHolderSynchronization.beforeCompletion()\n+\t\t\t\t\t\ttry {\n+\t\t\t\t\t\t\tcallExecuteListener(message, deliveryTag);\n+\t\t\t\t\t\t}\n+\t\t\t\t\t\tcatch (RuntimeException e1) {\n+\t\t\t\t\t\t\tthrow e1;\n+\t\t\t\t\t\t}\n+\t\t\t\t\t\tcatch (Throwable e2) { //NOSONAR ok to catch Throwable here because we re-throw it below\n+\t\t\t\t\t\t\tthrow new WrappedTransactionException(e2);\n+\t\t\t\t\t\t}\n \t\t\t\t\t\treturn null;\n \t\t\t\t\t});\n \t\t\t\t}\n+\t\t\t\tcatch (Throwable e) {\n+\t\t\t\t\tif (e instanceof WrappedTransactionException) {\n+\t\t\t\t\t\tif (e.getCause() instanceof Error) {\n+\t\t\t\t\t\t\tthrow (Error) e.getCause();\n+\t\t\t\t\t\t}\n+\t\t\t\t\t}\n+\t\t\t\t}\n \t\t\t\tfinally {\n \t\t\t\t\tif (this.isRabbitTxManager) {\n \t\t\t\t\t\tConsumerChannelRegistry.unRegisterConsumerChannel();\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t}\n \t\t\telse {\n-\t\t\t\tcallExecuteListener(message, deliveryTag);\n+\t\t\t\ttry {\n+\t\t\t\t\tcallExecuteListener(message, deliveryTag);\n+\t\t\t\t}\n+\t\t\t\tcatch (Exception e) {\n+\t\t\t\t\t// NOSONAR\n+\t\t\t\t}\n \t\t\t}\n \t\t}\n \n-\t\tprivate void callExecuteListener(Message message, long deliveryTag) {\n+\t\tprivate void callExecuteListener(Message message, long deliveryTag) throws Exception {\n+\t\t\tboolean channelLocallyTransacted = isChannelLocallyTransacted();\n \t\t\ttry {\n \t\t\t\texecuteListener(getChannel(), message);\n-\t\t\t\tboolean channelLocallyTransacted = isChannelLocallyTransacted();\n+\t\t\t\thandleAck(deliveryTag, channelLocallyTransacted);\n+\t\t\t}\n+\t\t\tcatch (ImmediateAcknowledgeAmqpException e) {\n+\t\t\t\tif (this.logger.isDebugEnabled()) {\n+\t\t\t\t\tthis.logger.debug(\"User requested ack for failed delivery\");\n+\t\t\t\t}\n+\t\t\t\thandleAck(deliveryTag, channelLocallyTransacted);\n+\t\t\t}\n+\t\t\tcatch (Exception e) {\n+\t\t\t\tif (causeChainHasImmediateAcknowledgeAmqpException(e)) {\n+\t\t\t\t\tif (this.logger.isDebugEnabled()) {\n+\t\t\t\t\t\tthis.logger.debug(\"User requested ack for failed delivery\");\n+\t\t\t\t\t}\n+\t\t\t\t}\n+\t\t\t\telse {\n+\t\t\t\t\tthis.logger.error(\"Failed to invoke listener\", e);\n+\t\t\t\t\tif (this.transactionManager != null) {\n+\t\t\t\t\t\tif (this.transactionAttribute.rollbackOn(e)) {\n+\t\t\t\t\t\t\trollback(deliveryTag, e);\n+\t\t\t\t\t\t\tthrow e;\n+\t\t\t\t\t\t}\n+\t\t\t\t\t\telse {\n+\t\t\t\t\t\t\tif (this.logger.isDebugEnabled()) {\n+\t\t\t\t\t\t\t\tthis.logger.debug(\"No rollback for \" + e);\n+\t\t\t\t\t\t\t}\n+\t\t\t\t\t\t}\n+\t\t\t\t\t}\n+\t\t\t\t\telse {\n+\t\t\t\t\t\trollback(deliveryTag, e);\n+\t\t\t\t\t}","path":"spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/DirectMessageListenerContainer.java","position":117,"original_position":117,"commit_id":"12074c7f39a06fd7b9db4bc1f6597b538d2f3de1","original_commit_id":"12074c7f39a06fd7b9db4bc1f6597b538d2f3de1","user":{"login":"garyrussell","id":483832,"avatar_url":"https://avatars.githubusercontent.com/u/483832?v=3","gravatar_id":"","url":"https://api.github.com/users/garyrussell","html_url":"https://github.com/garyrussell","followers_url":"https://api.github.com/users/garyrussell/followers","following_url":"https://api.github.com/users/garyrussell/following{/other_user}","gists_url":"https://api.github.com/users/garyrussell/gists{/gist_id}","starred_url":"https://api.github.com/users/garyrussell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/garyrussell/subscriptions","organizations_url":"https://api.github.com/users/garyrussell/orgs","repos_url":"https://api.github.com/users/garyrussell/repos","events_url":"https://api.github.com/users/garyrussell/events{/privacy}","received_events_url":"https://api.github.com/users/garyrussell/received_events","type":"User","site_admin":false},"body":"In this else block, we're not running in a transaction template, so there is no reason to throw the exception since it is ignored anyway (because we're running on the amqp-client thread). Will add a comment.","created_at":"2016-12-12T20:38:05Z","updated_at":"2016-12-12T20:38:05Z","html_url":"https://github.com/spring-projects/spring-amqp/pull/521#discussion_r92034579","pull_request_url":"https://api.github.com/repos/spring-projects/spring-amqp/pulls/521","_links":{"self":{"href":"https://api.github.com/repos/spring-projects/spring-amqp/pulls/comments/92034579"},"html":{"href":"https://github.com/spring-projects/spring-amqp/pull/521#discussion_r92034579"},"pull_request":{"href":"https://api.github.com/repos/spring-projects/spring-amqp/pulls/521"}}},"pull_request":{"url":"https://api.github.com/repos/spring-projects/spring-amqp/pulls/521","id":97216293,"html_url":"https://github.com/spring-projects/spring-amqp/pull/521","diff_url":"https://github.com/spring-projects/spring-amqp/pull/521.diff","patch_url":"https://github.com/spring-projects/spring-amqp/pull/521.patch","issue_url":"https://api.github.com/repos/spring-projects/spring-amqp/issues/521","number":521,"state":"open","locked":false,"title":"AMQP-687: Fix Conditional Rollback","user":{"login":"garyrussell","id":483832,"avatar_url":"https://avatars.githubusercontent.com/u/483832?v=3","gravatar_id":"","url":"https://api.github.com/users/garyrussell","html_url":"https://github.com/garyrussell","followers_url":"https://api.github.com/users/garyrussell/followers","following_url":"https://api.github.com/users/garyrussell/following{/other_user}","gists_url":"https://api.github.com/users/garyrussell/gists{/gist_id}","starred_url":"https://api.github.com/users/garyrussell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/garyrussell/subscriptions","organizations_url":"https://api.github.com/users/garyrussell/orgs","repos_url":"https://api.github.com/users/garyrussell/repos","events_url":"https://api.github.com/users/garyrussell/events{/privacy}","received_events_url":"https://api.github.com/users/garyrussell/received_events","type":"User","site_admin":false},"body":"JIRA: https://jira.spring.io/browse/AMQP-687\r\n\r\nWhen using a rule-based transaction attribute with a rollback/no-rollback rule,\r\nthe rule is ignored when providing the transaction attribute directly to the container\r\nrather than via a transaction advice,\r\n\r\nAlso, user exceptions are always wrapped in a `ListenerExecutionFailedException` which\r\nlimits the ability to configure rules, even when using an advice.\r\n\r\n- Honor the attribute `rollBackOn()` mechanism within the container\r\n- Add `ListenerFailedRuleBasedTransactionAttribute` to allow the user to configure rules based on the actual exception.","created_at":"2016-12-08T22:46:26Z","updated_at":"2016-12-12T20:38:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e6f1b20b50460c573110d9ccac755473929a4fb7","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/spring-projects/spring-amqp/pulls/521/commits","review_comments_url":"https://api.github.com/repos/spring-projects/spring-amqp/pulls/521/comments","review_comment_url":"https://api.github.com/repos/spring-projects/spring-amqp/pulls/comments{/number}","comments_url":"https://api.github.com/repos/spring-projects/spring-amqp/issues/521/comments","statuses_url":"https://api.github.com/repos/spring-projects/spring-amqp/statuses/12074c7f39a06fd7b9db4bc1f6597b538d2f3de1","head":{"label":"garyrussell:AMQP-687","ref":"AMQP-687","sha":"12074c7f39a06fd7b9db4bc1f6597b538d2f3de1","user":{"login":"garyrussell","id":483832,"avatar_url":"https://avatars.githubusercontent.com/u/483832?v=3","gravatar_id":"","url":"https://api.github.com/users/garyrussell","html_url":"https://github.com/garyrussell","followers_url":"https://api.github.com/users/garyrussell/followers","following_url":"https://api.github.com/users/garyrussell/following{/other_user}","gists_url":"https://api.github.com/users/garyrussell/gists{/gist_id}","starred_url":"https://api.github.com/users/garyrussell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/garyrussell/subscriptions","organizations_url":"https://api.github.com/users/garyrussell/orgs","repos_url":"https://api.github.com/users/garyrussell/repos","events_url":"https://api.github.com/users/garyrussell/events{/privacy}","received_events_url":"https://api.github.com/users/garyrussell/received_events","type":"User","site_admin":false},"repo":{"id":3138424,"name":"spring-amqp","full_name":"garyrussell/spring-amqp","owner":{"login":"garyrussell","id":483832,"avatar_url":"https://avatars.githubusercontent.com/u/483832?v=3","gravatar_id":"","url":"https://api.github.com/users/garyrussell","html_url":"https://github.com/garyrussell","followers_url":"https://api.github.com/users/garyrussell/followers","following_url":"https://api.github.com/users/garyrussell/following{/other_user}","gists_url":"https://api.github.com/users/garyrussell/gists{/gist_id}","starred_url":"https://api.github.com/users/garyrussell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/garyrussell/subscriptions","organizations_url":"https://api.github.com/users/garyrussell/orgs","repos_url":"https://api.github.com/users/garyrussell/repos","events_url":"https://api.github.com/users/garyrussell/events{/privacy}","received_events_url":"https://api.github.com/users/garyrussell/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/garyrussell/spring-amqp","description":"Spring AMQP - support for Spring programming model with AMQP, especially but not limited to RabbitMQ","fork":true,"url":"https://api.github.com/repos/garyrussell/spring-amqp","forks_url":"https://api.github.com/repos/garyrussell/spring-amqp/forks","keys_url":"https://api.github.com/repos/garyrussell/spring-amqp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/garyrussell/spring-amqp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/garyrussell/spring-amqp/teams","hooks_url":"https://api.github.com/repos/garyrussell/spring-amqp/hooks","issue_events_url":"https://api.github.com/repos/garyrussell/spring-amqp/issues/events{/number}","events_url":"https://api.github.com/repos/garyrussell/spring-amqp/events","assignees_url":"https://api.github.com/repos/garyrussell/spring-amqp/assignees{/user}","branches_url":"https://api.github.com/repos/garyrussell/spring-amqp/branches{/branch}","tags_url":"https://api.github.com/repos/garyrussell/spring-amqp/tags","blobs_url":"https://api.github.com/repos/garyrussell/spring-amqp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/garyrussell/spring-amqp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/garyrussell/spring-amqp/git/refs{/sha}","trees_url":"https://api.github.com/repos/garyrussell/spring-amqp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/garyrussell/spring-amqp/statuses/{sha}","languages_url":"https://api.github.com/repos/garyrussell/spring-amqp/languages","stargazers_url":"https://api.github.com/repos/garyrussell/spring-amqp/stargazers","contributors_url":"https://api.github.com/repos/garyrussell/spring-amqp/contributors","subscribers_url":"https://api.github.com/repos/garyrussell/spring-amqp/subscribers","subscription_url":"https://api.github.com/repos/garyrussell/spring-amqp/subscription","commits_url":"https://api.github.com/repos/garyrussell/spring-amqp/commits{/sha}","git_commits_url":"https://api.github.com/repos/garyrussell/spring-amqp/git/commits{/sha}","comments_url":"https://api.github.com/repos/garyrussell/spring-amqp/comments{/number}","issue_comment_url":"https://api.github.com/repos/garyrussell/spring-amqp/issues/comments{/number}","contents_url":"https://api.github.com/repos/garyrussell/spring-amqp/contents/{+path}","compare_url":"https://api.github.com/repos/garyrussell/spring-amqp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/garyrussell/spring-amqp/merges","archive_url":"https://api.github.com/repos/garyrussell/spring-amqp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/garyrussell/spring-amqp/downloads","issues_url":"https://api.github.com/repos/garyrussell/spring-amqp/issues{/number}","pulls_url":"https://api.github.com/repos/garyrussell/spring-amqp/pulls{/number}","milestones_url":"https://api.github.com/repos/garyrussell/spring-amqp/milestones{/number}","notifications_url":"https://api.github.com/repos/garyrussell/spring-amqp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/garyrussell/spring-amqp/labels{/name}","releases_url":"https://api.github.com/repos/garyrussell/spring-amqp/releases{/id}","deployments_url":"https://api.github.com/repos/garyrussell/spring-amqp/deployments","created_at":"2012-01-09T17:21:18Z","updated_at":"2016-11-07T13:32:11Z","pushed_at":"2016-12-09T17:36:26Z","git_url":"git://github.com/garyrussell/spring-amqp.git","ssh_url":"git@github.com:garyrussell/spring-amqp.git","clone_url":"https://github.com/garyrussell/spring-amqp.git","svn_url":"https://github.com/garyrussell/spring-amqp","homepage":"http://www.springsource.org/spring-amqp","size":8759,"stargazers_count":4,"watchers_count":4,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":4,"default_branch":"master"}},"base":{"label":"spring-projects:master","ref":"master","sha":"8f37772874977a6c48ceaec0b80b0d209e4db1bc","user":{"login":"spring-projects","id":317776,"avatar_url":"https://avatars.githubusercontent.com/u/317776?v=3","gravatar_id":"","url":"https://api.github.com/users/spring-projects","html_url":"https://github.com/spring-projects","followers_url":"https://api.github.com/users/spring-projects/followers","following_url":"https://api.github.com/users/spring-projects/following{/other_user}","gists_url":"https://api.github.com/users/spring-projects/gists{/gist_id}","starred_url":"https://api.github.com/users/spring-projects/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spring-projects/subscriptions","organizations_url":"https://api.github.com/users/spring-projects/orgs","repos_url":"https://api.github.com/users/spring-projects/repos","events_url":"https://api.github.com/users/spring-projects/events{/privacy}","received_events_url":"https://api.github.com/users/spring-projects/received_events","type":"Organization","site_admin":false},"repo":{"id":1088796,"name":"spring-amqp","full_name":"spring-projects/spring-amqp","owner":{"login":"spring-projects","id":317776,"avatar_url":"https://avatars.githubusercontent.com/u/317776?v=3","gravatar_id":"","url":"https://api.github.com/users/spring-projects","html_url":"https://github.com/spring-projects","followers_url":"https://api.github.com/users/spring-projects/followers","following_url":"https://api.github.com/users/spring-projects/following{/other_user}","gists_url":"https://api.github.com/users/spring-projects/gists{/gist_id}","starred_url":"https://api.github.com/users/spring-projects/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spring-projects/subscriptions","organizations_url":"https://api.github.com/users/spring-projects/orgs","repos_url":"https://api.github.com/users/spring-projects/repos","events_url":"https://api.github.com/users/spring-projects/events{/privacy}","received_events_url":"https://api.github.com/users/spring-projects/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/spring-projects/spring-amqp","description":"Spring AMQP - support for Spring programming model with AMQP, especially but not limited to RabbitMQ","fork":false,"url":"https://api.github.com/repos/spring-projects/spring-amqp","forks_url":"https://api.github.com/repos/spring-projects/spring-amqp/forks","keys_url":"https://api.github.com/repos/spring-projects/spring-amqp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/spring-projects/spring-amqp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/spring-projects/spring-amqp/teams","hooks_url":"https://api.github.com/repos/spring-projects/spring-amqp/hooks","issue_events_url":"https://api.github.com/repos/spring-projects/spring-amqp/issues/events{/number}","events_url":"https://api.github.com/repos/spring-projects/spring-amqp/events","assignees_url":"https://api.github.com/repos/spring-projects/spring-amqp/assignees{/user}","branches_url":"https://api.github.com/repos/spring-projects/spring-amqp/branches{/branch}","tags_url":"https://api.github.com/repos/spring-projects/spring-amqp/tags","blobs_url":"https://api.github.com/repos/spring-projects/spring-amqp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/spring-projects/spring-amqp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/spring-projects/spring-amqp/git/refs{/sha}","trees_url":"https://api.github.com/repos/spring-projects/spring-amqp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/spring-projects/spring-amqp/statuses/{sha}","languages_url":"https://api.github.com/repos/spring-projects/spring-amqp/languages","stargazers_url":"https://api.github.com/repos/spring-projects/spring-amqp/stargazers","contributors_url":"https://api.github.com/repos/spring-projects/spring-amqp/contributors","subscribers_url":"https://api.github.com/repos/spring-projects/spring-amqp/subscribers","subscription_url":"https://api.github.com/repos/spring-projects/spring-amqp/subscription","commits_url":"https://api.github.com/repos/spring-projects/spring-amqp/commits{/sha}","git_commits_url":"https://api.github.com/repos/spring-projects/spring-amqp/git/commits{/sha}","comments_url":"https://api.github.com/repos/spring-projects/spring-amqp/comments{/number}","issue_comment_url":"https://api.github.com/repos/spring-projects/spring-amqp/issues/comments{/number}","contents_url":"https://api.github.com/repos/spring-projects/spring-amqp/contents/{+path}","compare_url":"https://api.github.com/repos/spring-projects/spring-amqp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/spring-projects/spring-amqp/merges","archive_url":"https://api.github.com/repos/spring-projects/spring-amqp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/spring-projects/spring-amqp/downloads","issues_url":"https://api.github.com/repos/spring-projects/spring-amqp/issues{/number}","pulls_url":"https://api.github.com/repos/spring-projects/spring-amqp/pulls{/number}","milestones_url":"https://api.github.com/repos/spring-projects/spring-amqp/milestones{/number}","notifications_url":"https://api.github.com/repos/spring-projects/spring-amqp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/spring-projects/spring-amqp/labels{/name}","releases_url":"https://api.github.com/repos/spring-projects/spring-amqp/releases{/id}","deployments_url":"https://api.github.com/repos/spring-projects/spring-amqp/deployments","created_at":"2010-11-17T15:50:16Z","updated_at":"2016-12-09T10:19:10Z","pushed_at":"2016-12-09T17:44:33Z","git_url":"git://github.com/spring-projects/spring-amqp.git","ssh_url":"git@github.com:spring-projects/spring-amqp.git","clone_url":"https://github.com/spring-projects/spring-amqp.git","svn_url":"https://github.com/spring-projects/spring-amqp","homepage":"http://www.springsource.org/spring-amqp","size":9932,"stargazers_count":283,"watchers_count":283,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":245,"mirror_url":null,"open_issues_count":2,"forks":245,"open_issues":2,"watchers":283,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/spring-projects/spring-amqp/pulls/521"},"html":{"href":"https://github.com/spring-projects/spring-amqp/pull/521"},"issue":{"href":"https://api.github.com/repos/spring-projects/spring-amqp/issues/521"},"comments":{"href":"https://api.github.com/repos/spring-projects/spring-amqp/issues/521/comments"},"review_comments":{"href":"https://api.github.com/repos/spring-projects/spring-amqp/pulls/521/comments"},"review_comment":{"href":"https://api.github.com/repos/spring-projects/spring-amqp/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/spring-projects/spring-amqp/pulls/521/commits"},"statuses":{"href":"https://api.github.com/repos/spring-projects/spring-amqp/statuses/12074c7f39a06fd7b9db4bc1f6597b538d2f3de1"}}}}
{"actor":{"display_login":"garyrussell"}}