|
13 | 13 |
|
14 | 14 | package com.rabbitmq.stream.impl;
|
15 | 15 |
|
16 |
| -import static com.rabbitmq.stream.Constants.COMMAND_CLOSE; |
17 |
| -import static com.rabbitmq.stream.Constants.COMMAND_CONSUMER_UPDATE; |
18 |
| -import static com.rabbitmq.stream.Constants.COMMAND_CREATE_STREAM; |
19 |
| -import static com.rabbitmq.stream.Constants.COMMAND_CREDIT; |
20 |
| -import static com.rabbitmq.stream.Constants.COMMAND_DECLARE_PUBLISHER; |
21 |
| -import static com.rabbitmq.stream.Constants.COMMAND_DELETE_PUBLISHER; |
22 |
| -import static com.rabbitmq.stream.Constants.COMMAND_DELETE_STREAM; |
23 |
| -import static com.rabbitmq.stream.Constants.COMMAND_EXCHANGE_COMMAND_VERSIONS; |
24 |
| -import static com.rabbitmq.stream.Constants.COMMAND_HEARTBEAT; |
25 |
| -import static com.rabbitmq.stream.Constants.COMMAND_METADATA; |
26 |
| -import static com.rabbitmq.stream.Constants.COMMAND_OPEN; |
27 |
| -import static com.rabbitmq.stream.Constants.COMMAND_PARTITIONS; |
28 |
| -import static com.rabbitmq.stream.Constants.COMMAND_PEER_PROPERTIES; |
29 |
| -import static com.rabbitmq.stream.Constants.COMMAND_PUBLISH; |
30 |
| -import static com.rabbitmq.stream.Constants.COMMAND_QUERY_OFFSET; |
31 |
| -import static com.rabbitmq.stream.Constants.COMMAND_QUERY_PUBLISHER_SEQUENCE; |
32 |
| -import static com.rabbitmq.stream.Constants.COMMAND_ROUTE; |
33 |
| -import static com.rabbitmq.stream.Constants.COMMAND_SASL_AUTHENTICATE; |
34 |
| -import static com.rabbitmq.stream.Constants.COMMAND_SASL_HANDSHAKE; |
35 |
| -import static com.rabbitmq.stream.Constants.COMMAND_STORE_OFFSET; |
36 |
| -import static com.rabbitmq.stream.Constants.COMMAND_STREAM_STATS; |
37 |
| -import static com.rabbitmq.stream.Constants.COMMAND_SUBSCRIBE; |
38 |
| -import static com.rabbitmq.stream.Constants.COMMAND_UNSUBSCRIBE; |
39 |
| -import static com.rabbitmq.stream.Constants.RESPONSE_CODE_AUTHENTICATION_FAILURE; |
40 |
| -import static com.rabbitmq.stream.Constants.RESPONSE_CODE_AUTHENTICATION_FAILURE_LOOPBACK; |
41 |
| -import static com.rabbitmq.stream.Constants.RESPONSE_CODE_OK; |
42 |
| -import static com.rabbitmq.stream.Constants.RESPONSE_CODE_SASL_CHALLENGE; |
43 |
| -import static com.rabbitmq.stream.Constants.VERSION_1; |
| 16 | +import static com.rabbitmq.stream.Constants.*; |
44 | 17 | import static com.rabbitmq.stream.impl.Utils.encodeRequestCode;
|
45 | 18 | import static com.rabbitmq.stream.impl.Utils.encodeResponseCode;
|
46 | 19 | import static com.rabbitmq.stream.impl.Utils.extractResponseCode;
|
@@ -216,6 +189,7 @@ public long applyAsLong(Object value) {
|
216 | 189 | private final Duration rpcTimeout;
|
217 | 190 | private volatile ShutdownReason shutdownReason = null;
|
218 | 191 | private final Runnable exchangeCommandVersionsCheck;
|
| 192 | + private final boolean filteringSupported; |
219 | 193 |
|
220 | 194 | public Client() {
|
221 | 195 | this(new ClientParameters());
|
@@ -398,18 +372,25 @@ public void initChannel(SocketChannel ch) {
|
398 | 372 | tuneState.getHeartbeat());
|
399 | 373 | this.connectionProperties = open(parameters.virtualHost);
|
400 | 374 | Set<FrameHandlerInfo> supportedCommands = maybeExchangeCommandVersions();
|
401 |
| - if (supportedCommands.stream() |
402 |
| - .filter(i -> i.getKey() == COMMAND_STREAM_STATS) |
403 |
| - .findAny() |
404 |
| - .isPresent()) { |
405 |
| - this.exchangeCommandVersionsCheck = () -> {}; |
406 |
| - } else { |
407 |
| - this.exchangeCommandVersionsCheck = |
408 |
| - () -> { |
409 |
| - throw new UnsupportedOperationException( |
410 |
| - "QueryStreamInfo is available only on RabbitMQ 3.11 or more."); |
411 |
| - }; |
412 |
| - } |
| 375 | + AtomicReference<Runnable> exchangeCommandVersionsCheckReference = new AtomicReference<>(); |
| 376 | + AtomicBoolean filteringSupportedReference = new AtomicBoolean(false); |
| 377 | + supportedCommands.forEach( |
| 378 | + c -> { |
| 379 | + if (c.getKey() == COMMAND_STREAM_STATS) { |
| 380 | + exchangeCommandVersionsCheckReference.set(() -> {}); |
| 381 | + } |
| 382 | + if (c.getKey() == COMMAND_PUBLISH && c.getMaxVersion() >= VERSION_2) { |
| 383 | + filteringSupportedReference.set(true); |
| 384 | + } |
| 385 | + }); |
| 386 | + this.exchangeCommandVersionsCheck = |
| 387 | + exchangeCommandVersionsCheckReference.get() == null |
| 388 | + ? () -> { |
| 389 | + throw new UnsupportedOperationException( |
| 390 | + "QueryStreamInfo is available only on RabbitMQ 3.11 or more."); |
| 391 | + } |
| 392 | + : exchangeCommandVersionsCheckReference.get(); |
| 393 | + this.filteringSupported = filteringSupportedReference.get(); |
413 | 394 | started.set(true);
|
414 | 395 | this.metricsCollector.openConnection();
|
415 | 396 | } catch (RuntimeException e) {
|
@@ -1414,6 +1395,10 @@ private String serverAddress() {
|
1414 | 1395 | }
|
1415 | 1396 | }
|
1416 | 1397 |
|
| 1398 | + boolean filteringSupported() { |
| 1399 | + return this.filteringSupported; |
| 1400 | + } |
| 1401 | + |
1417 | 1402 | public List<String> route(String routingKey, String superStream) {
|
1418 | 1403 | if (routingKey == null || superStream == null) {
|
1419 | 1404 | throw new IllegalArgumentException("routing key and stream must not be null");
|
@@ -1615,11 +1600,7 @@ private Set<FrameHandlerInfo> maybeExchangeCommandVersions() {
|
1615 | 1600 | Set<FrameHandlerInfo> supported = new HashSet<>();
|
1616 | 1601 | try {
|
1617 | 1602 | if (Utils.is3_11_OrMore(brokerVersion())) {
|
1618 |
| - for (FrameHandlerInfo info : exchangeCommandVersions()) { |
1619 |
| - if (info.getKey() == COMMAND_STREAM_STATS) { |
1620 |
| - supported.add(info); |
1621 |
| - } |
1622 |
| - } |
| 1603 | + supported.addAll(exchangeCommandVersions()); |
1623 | 1604 | }
|
1624 | 1605 | } catch (Exception e) {
|
1625 | 1606 | LOGGER.info("Error while exchanging command versions: {}", e.getMessage());
|
|
0 commit comments