Skip to content

Commit bf5498d

Browse files
committed
AMQP-806: Move new invoke() to RabbitOperations
JIRA: https://jira.spring.io/browse/AMQP-806 * Use `default` in the in the `RabbitOperations` whenever it is possible for delegations instead of on the `RabbitTemplate` level
1 parent 3da5931 commit bf5498d

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/core/RabbitOperations.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,9 +26,11 @@
2626

2727
/**
2828
* Rabbit specific methods for Amqp functionality.
29+
*
2930
* @author Mark Pollack
3031
* @author Mark Fisher
3132
* @author Gary Russell
33+
* @author Artem Bilan
3234
*/
3335
public interface RabbitOperations extends AmqpTemplate {
3436

@@ -52,7 +54,22 @@ public interface RabbitOperations extends AmqpTemplate {
5254
* @throws AmqpException if one occurs.
5355
* @since 2.0
5456
*/
55-
<T> T invoke(OperationsCallback<T> action) throws AmqpException;
57+
default <T> T invoke(OperationsCallback<T> action) throws AmqpException {
58+
return invoke(action, null, null);
59+
}
60+
61+
/**
62+
* Invoke operations on the same channel.
63+
* If callbacks are needed, both callbacks must be supplied.
64+
* @param action the callback.
65+
* @param acks a confirm callback for acks.
66+
* @param nacks a confirm callback for nacks.
67+
* @param <T> the return type.
68+
* @return the result of the action method.
69+
* @since 2.1
70+
*/
71+
<T> T invoke(OperationsCallback<T> action, com.rabbitmq.client.ConfirmCallback acks,
72+
com.rabbitmq.client.ConfirmCallback nacks);
5673

5774
/**
5875
* Delegate to the underlying dedicated channel to wait for confirms. The connection
@@ -318,8 +335,10 @@ <T> T convertSendAndReceiveAsType(String routingKey, Object message, Correlation
318335
* @return the response if there is one
319336
* @throws AmqpException if there is a problem
320337
*/
321-
<T> T convertSendAndReceiveAsType(String exchange, String routingKey, Object message,
322-
CorrelationData correlationData, ParameterizedTypeReference<T> responseType) throws AmqpException;
338+
default <T> T convertSendAndReceiveAsType(String exchange, String routingKey, Object message,
339+
CorrelationData correlationData, ParameterizedTypeReference<T> responseType) throws AmqpException {
340+
return convertSendAndReceiveAsType(exchange, routingKey, message, null, correlationData, responseType);
341+
}
323342

324343
/**
325344
* Basic RPC pattern with conversion. Send a Java object converted to a message to a

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/core/RabbitTemplate.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,12 +1426,6 @@ public <T> T convertSendAndReceiveAsType(final String exchange, final String rou
14261426
return convertSendAndReceiveAsType(exchange, routingKey, message, (CorrelationData) null, responseType);
14271427
}
14281428

1429-
@Override
1430-
public <T> T convertSendAndReceiveAsType(final String exchange, final String routingKey, final Object message,
1431-
CorrelationData correlationData, ParameterizedTypeReference<T> responseType) throws AmqpException {
1432-
return convertSendAndReceiveAsType(exchange, routingKey, message, null, correlationData, responseType);
1433-
}
1434-
14351429
@Override
14361430
public <T> T convertSendAndReceiveAsType(final Object message, final MessagePostProcessor messagePostProcessor,
14371431
ParameterizedTypeReference<T> responseType) throws AmqpException {
@@ -1848,20 +1842,6 @@ private <T> T doExecute(ChannelCallback<T> action, ConnectionFactory connectionF
18481842
}
18491843

18501844
@Override
1851-
public <T> T invoke(OperationsCallback<T> action) {
1852-
return invoke(action, null, null);
1853-
}
1854-
1855-
/**
1856-
* Invoke operations on the same channel.
1857-
* If callbacks are needed, both callbacks must be supplied.
1858-
* @param action the callback.
1859-
* @param acks a confirm callback for acks.
1860-
* @param nacks a confirm callback for nacks.
1861-
* @param <T> the return type.
1862-
* @return the result of the action method.
1863-
* @since 2.1
1864-
*/
18651845
public <T> T invoke(OperationsCallback<T> action, com.rabbitmq.client.ConfirmCallback acks,
18661846
com.rabbitmq.client.ConfirmCallback nacks) {
18671847

0 commit comments

Comments
 (0)