Skip to content

Commit 49c57cf

Browse files
JHahnHROacogoluegnes
authored andcommitted
make RpcClient implement java.io.Closeable
(cherry picked from commit 75a94f6)
1 parent 7aed364 commit 49c57cf

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/main/java/com/rabbitmq/client/RpcClient.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.io.ByteArrayInputStream;
2020
import java.io.ByteArrayOutputStream;
21+
import java.io.Closeable;
2122
import java.io.DataInputStream;
2223
import java.io.DataOutputStream;
2324
import java.io.EOFException;
@@ -44,7 +45,7 @@
4445
* It simply provides a mechanism for sending a message to an exchange with a given routing key,
4546
* and waiting for a response.
4647
*/
47-
public class RpcClient {
48+
public class RpcClient implements Closeable {
4849

4950
private static final Logger LOGGER = LoggerFactory.getLogger(RpcClient.class);
5051

@@ -236,10 +237,13 @@ public void checkConsumer() throws IOException {
236237
* Public API - cancels the consumer, thus deleting the temporary queue, and marks the RpcClient as closed.
237238
* @throws IOException if an error is encountered
238239
*/
240+
@Override
239241
public void close() throws IOException {
240242
if (_consumer != null) {
241-
_channel.basicCancel(_consumer.getConsumerTag());
243+
final String consumerTag = _consumer.getConsumerTag();
244+
// set it null before calling basicCancel to make this method idempotent in case of IOException
242245
_consumer = null;
246+
_channel.basicCancel(consumerTag);
243247
}
244248
}
245249

0 commit comments

Comments
 (0)