{"action":"created","comment":{"url":"https://api.github.com/repos/spring-projects/spring-amqp/pulls/comments/51040899","id":51040899,"diff_hunk":"@@ -0,0 +1,583 @@\n+/*\n+ * Copyright 2016 the original author or authors.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *      http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package org.springframework.amqp.rabbit.core;\n+\n+import java.nio.charset.Charset;\n+import java.util.UUID;\n+import java.util.concurrent.ConcurrentHashMap;\n+import java.util.concurrent.ConcurrentMap;\n+import java.util.concurrent.ExecutionException;\n+\n+import org.apache.commons.logging.Log;\n+import org.apache.commons.logging.LogFactory;\n+\n+import org.springframework.amqp.AmqpException;\n+import org.springframework.amqp.core.AmqpMessageReturnedException;\n+import org.springframework.amqp.core.Message;\n+import org.springframework.amqp.core.MessageListener;\n+import org.springframework.amqp.core.MessagePostProcessor;\n+import org.springframework.amqp.core.MessageProperties;\n+import org.springframework.amqp.rabbit.connection.ConnectionFactory;\n+import org.springframework.amqp.rabbit.core.RabbitTemplate.ConfirmCallback;\n+import org.springframework.amqp.rabbit.core.RabbitTemplate.ReturnCallback;\n+import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;\n+import org.springframework.amqp.rabbit.support.CorrelationData;\n+import org.springframework.context.SmartLifecycle;\n+import org.springframework.util.Assert;\n+import org.springframework.util.concurrent.ListenableFuture;\n+import org.springframework.util.concurrent.SettableListenableFuture;\n+\n+/**\n+ * Provides asynchronous send and receive operations returning a {@link ListenableFuture}\n+ * allowing the caller to obtain the reply later, using {@code get()} or a callback.\n+ * <p>\n+ * When confirms are enabled, the future has a confirm property which is itself a\n+ * {@link ListenableFuture}. If the reply is received before the publisher confirm,\n+ * the confirm is discarded since the reply implicitly indicates the message was\n+ * published.\n+ * <p>\n+ * Returned (undeliverable) request messages are presented as a\n+ * {@link AmqpMessageReturnedException} cause of an {@link ExecutionException}.\n+ * <p>\n+ * Internally, the template uses a {@link RabbitTemplate} and a\n+ * {@link SimpleMessageListenerContainer} either provided or constructed internally.\n+ * If an external {@link RabbitTemplate} is provided and confirms/returns are enabled,\n+ * it must not previously have had callbacks registered because this object needs to\n+ * be the callback.\n+ *\n+ * @author Gary Russell\n+ * @since 1.6\n+ *\n+ */\n+public class AsyncRabbitTemplate<C> implements SmartLifecycle, MessageListener, ReturnCallback, ConfirmCallback {","path":"spring-rabbit/src/main/java/org/springframework/amqp/rabbit/core/AsyncRabbitTemplate.java","position":65,"original_position":65,"commit_id":"aa54588277d2504d256d9c97606538f1e29f53e3","original_commit_id":"aa54588277d2504d256d9c97606538f1e29f53e3","user":{"login":"artembilan","id":1071590,"avatar_url":"https://avatars.githubusercontent.com/u/1071590?v=3","gravatar_id":"","url":"https://api.github.com/users/artembilan","html_url":"https://github.com/artembilan","followers_url":"https://api.github.com/users/artembilan/followers","following_url":"https://api.github.com/users/artembilan/following{/other_user}","gists_url":"https://api.github.com/users/artembilan/gists{/gist_id}","starred_url":"https://api.github.com/users/artembilan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artembilan/subscriptions","organizations_url":"https://api.github.com/users/artembilan/orgs","repos_url":"https://api.github.com/users/artembilan/repos","events_url":"https://api.github.com/users/artembilan/events{/privacy}","received_events_url":"https://api.github.com/users/artembilan/received_events","type":"User","site_admin":false},"body":"Well, I totally agreed with you!\r\n\r\nWe can just end up with the:\r\n```\r\npublic AmqpOutboundEndpoint(AsyncRabbitTemplate asyncRabbitTemplate) {\r\n...\r\n}\r\n```\r\nAnd go to drink beer! :smile: \r\n\r\nOut of topic: do we really need that `<C>` generic?\r\n\r\nIt does not make so much sense for the class level, because we are in the messaging, so any message may carry its own object.\r\nThe contract like:\r\n```\r\npublic <C> RabbitConverterFuture<C> convertSendAndReceive()\r\n```\r\nmakes more sense for me.","created_at":"2016-01-27T19:58:12Z","updated_at":"2016-01-27T19:58:12Z","html_url":"https://github.com/spring-projects/spring-amqp/pull/362#discussion_r51040899","pull_request_url":"https://api.github.com/repos/spring-projects/spring-amqp/pulls/362","_links":{"self":{"href":"https://api.github.com/repos/spring-projects/spring-amqp/pulls/comments/51040899"},"html":{"href":"https://github.com/spring-projects/spring-amqp/pull/362#discussion_r51040899"},"pull_request":{"href":"https://api.github.com/repos/spring-projects/spring-amqp/pulls/362"}}},"pull_request":{"url":"https://api.github.com/repos/spring-projects/spring-amqp/pulls/362","id":57226458,"html_url":"https://github.com/spring-projects/spring-amqp/pull/362","diff_url":"https://github.com/spring-projects/spring-amqp/pull/362.diff","patch_url":"https://github.com/spring-projects/spring-amqp/pull/362.patch","issue_url":"https://api.github.com/repos/spring-projects/spring-amqp/issues/362","number":362,"state":"open","locked":false,"title":"AMQP-539: Add AsyncRabbitTemplate","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-539\r\n\r\nAsync `sendAndReceive` operations returning a `ListenableFuture`.\r\n\r\n__Initial commit for review - needs docs.__","created_at":"2016-01-26T15:35:45Z","updated_at":"2016-01-27T19:58:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7b807b47c39388f607a14c8d05449e4eb66fffe8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/spring-projects/spring-amqp/pulls/362/commits","review_comments_url":"https://api.github.com/repos/spring-projects/spring-amqp/pulls/362/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/362/comments","statuses_url":"https://api.github.com/repos/spring-projects/spring-amqp/statuses/aa54588277d2504d256d9c97606538f1e29f53e3","head":{"label":"garyrussell:AMQP-539","ref":"AMQP-539","sha":"aa54588277d2504d256d9c97606538f1e29f53e3","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":"2015-10-21T18:02:46Z","pushed_at":"2016-01-27T16:52:09Z","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":6544,"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":"f8809d26e9eb36f2d9ed4d86ce89cb438def71da","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-01-27T03:46:17Z","pushed_at":"2016-01-27T18:33:54Z","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":7807,"stargazers_count":189,"watchers_count":189,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":179,"mirror_url":null,"open_issues_count":1,"forks":179,"open_issues":1,"watchers":189,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/spring-projects/spring-amqp/pulls/362"},"html":{"href":"https://github.com/spring-projects/spring-amqp/pull/362"},"issue":{"href":"https://api.github.com/repos/spring-projects/spring-amqp/issues/362"},"comments":{"href":"https://api.github.com/repos/spring-projects/spring-amqp/issues/362/comments"},"review_comments":{"href":"https://api.github.com/repos/spring-projects/spring-amqp/pulls/362/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/362/commits"},"statuses":{"href":"https://api.github.com/repos/spring-projects/spring-amqp/statuses/aa54588277d2504d256d9c97606538f1e29f53e3"}}}}