Skip to content

Commit f377524

Browse files
committed
Throw exception if set_token called on RabbitMQ < 4.1
1 parent 2e229a0 commit f377524

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/main/java/com/rabbitmq/client/amqp/impl/AmqpConnection.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
package com.rabbitmq.client.amqp.impl;
1919

2020
import static com.rabbitmq.client.amqp.Resource.State.*;
21+
import static com.rabbitmq.client.amqp.impl.Utils.supportFilterExpressions;
22+
import static com.rabbitmq.client.amqp.impl.Utils.supportSetToken;
2123

2224
import com.rabbitmq.client.amqp.*;
2325
import com.rabbitmq.client.amqp.ObservationCollector;
@@ -72,7 +74,7 @@ final class AmqpConnection extends ResourceBase implements Connection {
7274
private final ConnectionSettings.AffinityStrategy affinityStrategy;
7375
private final String name;
7476
private final Lock instanceLock = new ReentrantLock();
75-
private final boolean filterExpressionsSupported;
77+
private final boolean filterExpressionsSupported, setTokenSupported;
7678
private volatile ExecutorService dispatchingExecutorService;
7779

7880
AmqpConnection(AmqpConnectionBuilder builder) {
@@ -128,8 +130,9 @@ final class AmqpConnection extends ResourceBase implements Connection {
128130
ConnectionUtils.NO_RETRY_STRATEGY,
129131
this.name());
130132
this.sync(ncw);
131-
this.filterExpressionsSupported =
132-
Utils.supportFilterExpressions(brokerVersion(this.nativeConnection));
133+
String brokerVesion = brokerVersion(this.nativeConnection);
134+
this.filterExpressionsSupported = supportFilterExpressions(brokerVesion);
135+
this.setTokenSupported = supportSetToken(brokerVesion);
133136
LOGGER.debug("Opened connection '{}' on node '{}'.", this.name(), this.connectionNodename());
134137
this.state(OPEN);
135138
this.environment.metricsCollector().openConnection();
@@ -708,6 +711,10 @@ boolean filterExpressionsSupported() {
708711
return this.filterExpressionsSupported;
709712
}
710713

714+
boolean setTokenSupported() {
715+
return this.setTokenSupported;
716+
}
717+
711718
long id() {
712719
return this.id;
713720
}

src/main/java/com/rabbitmq/client/amqp/impl/AmqpManagement.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ public UnbindSpecification unbind() {
172172
}
173173

174174
void setToken(String token) {
175+
if (!this.connection.setTokenSupported()) {
176+
throw new UnsupportedOperationException("Token renewal requires at least RabbitMQ 4.1.0");
177+
}
175178
checkAvailable();
176179
UUID requestId = messageId();
177180
try {

src/main/java/com/rabbitmq/client/amqp/impl/Utils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ static boolean supportFilterExpressions(String brokerVersion) {
233233
return is4_1_OrMore(brokerVersion);
234234
}
235235

236+
static boolean supportSetToken(String brokerVersion) {
237+
return is4_1_OrMore(brokerVersion);
238+
}
239+
236240
static final class ObservationConnectionInfo implements ObservationCollector.ConnectionInfo {
237241

238242
private final String address;

0 commit comments

Comments
 (0)