├── .mvn
├── maven.config
└── wrapper
│ └── maven-wrapper.properties
├── src
├── test
│ ├── resources
│ │ ├── junit-platform.properties
│ │ ├── META-INF
│ │ │ └── services
│ │ │ │ └── org.junit.jupiter.api.extension.Extension
│ │ ├── property-file-initialisation
│ │ │ ├── tls
│ │ │ │ ├── keystore.p12
│ │ │ │ └── truststore.jks
│ │ │ └── configuration.properties
│ │ └── logback-test.xml
│ └── java
│ │ ├── com
│ │ └── rabbitmq
│ │ │ └── client
│ │ │ ├── test
│ │ │ ├── functional
│ │ │ │ ├── InvalidAcks.java
│ │ │ │ ├── InvalidAcksTx.java
│ │ │ │ ├── RequeueOnChannelClose.java
│ │ │ │ ├── RequeueOnConnectionClose.java
│ │ │ │ ├── ExchangeDeletePredeclared.java
│ │ │ │ ├── MessageCount.java
│ │ │ │ ├── ConsumerCount.java
│ │ │ │ ├── BasicConsume.java
│ │ │ │ ├── DoubleDeletion.java
│ │ │ │ ├── UnbindAutoDeleteExchange.java
│ │ │ │ ├── ExchangeEquivalenceBase.java
│ │ │ │ └── InvalidAcksBase.java
│ │ │ ├── server
│ │ │ │ ├── HaTestSuite.java
│ │ │ │ ├── Shutdown.java
│ │ │ │ ├── LastHaTestSuite.java
│ │ │ │ ├── ServerTestSuite.java
│ │ │ │ ├── AlternateExchangeEquivalence.java
│ │ │ │ ├── MessageRecovery.java
│ │ │ │ └── PersistenceGuarantees.java
│ │ │ ├── ClientVersionTest.java
│ │ │ ├── ssl
│ │ │ │ ├── SslTestSuite.java
│ │ │ │ ├── ConnectionFactoryDefaultTlsVersion.java
│ │ │ │ └── BadVerifiedConnection.java
│ │ │ ├── LongStringTest.java
│ │ │ ├── RequiredPropertiesSuite.java
│ │ │ ├── ClonePropertiesTest.java
│ │ │ └── DnsRecordIpAddressResolverTests.java
│ │ │ └── impl
│ │ │ └── recovery
│ │ │ └── AutorecoveringChannelTest.java
│ │ └── SanityCheck.java
└── main
│ ├── resources
│ ├── rabbitmq-amqp-client.properties
│ ├── META-INF
│ │ └── native-image
│ │ │ └── com.rabbitmq
│ │ │ └── amqp-client
│ │ │ └── native-image.properties
│ └── version.properties
│ ├── java
│ └── com
│ │ └── rabbitmq
│ │ ├── client
│ │ ├── observation
│ │ │ ├── package-info.java
│ │ │ ├── micrometer
│ │ │ │ ├── package-info.java
│ │ │ │ ├── DefaultProcessObservationConvention.java
│ │ │ │ ├── DefaultReceiveObservationConvention.java
│ │ │ │ ├── DeliverObservationConvention.java
│ │ │ │ ├── PublishObservationConvention.java
│ │ │ │ └── DeliverContext.java
│ │ │ └── NoOpObservationCollector.java
│ │ ├── impl
│ │ │ ├── recovery
│ │ │ │ ├── package-info.java
│ │ │ │ ├── RecoveredQueueNameSupplier.java
│ │ │ │ ├── Utils.java
│ │ │ │ ├── QueueRecoveryListener.java
│ │ │ │ ├── ConsumerRecoveryListener.java
│ │ │ │ ├── RecoveryCanBeginListener.java
│ │ │ │ ├── RecordedNamedEntity.java
│ │ │ │ ├── RecordedEntity.java
│ │ │ │ ├── BackoffPolicy.java
│ │ │ │ ├── RecordedQueueBinding.java
│ │ │ │ ├── RecordedExchangeBinding.java
│ │ │ │ ├── RetryResult.java
│ │ │ │ └── TopologyRecoveryFilter.java
│ │ │ ├── package-info.java
│ │ │ ├── FrameHandlerFactory.java
│ │ │ ├── HeartbeatSender.java
│ │ │ ├── WorkPoolFullException.java
│ │ │ ├── RpcWrapper.java
│ │ │ ├── DefaultExceptionHandler.java
│ │ │ ├── OAuthTokenManagementException.java
│ │ │ ├── ExternalMechanism.java
│ │ │ ├── UnknownChannelException.java
│ │ │ ├── LogTrafficListener.java
│ │ │ ├── AnonymousMechanism.java
│ │ │ ├── NetworkConnection.java
│ │ │ ├── AMQBasicProperties.java
│ │ │ ├── ErrorOnWriteListener.java
│ │ │ ├── PlainMechanism.java
│ │ │ ├── DefaultCredentialsProvider.java
│ │ │ ├── AbstractFrameHandlerFactory.java
│ │ │ ├── RpcContinuationRpcWrapper.java
│ │ │ ├── CompletableFutureRpcWrapper.java
│ │ │ ├── Environment.java
│ │ │ ├── CRDemoMechanism.java
│ │ │ └── CredentialsProvider.java
│ │ ├── package-info.java
│ │ ├── RecoverableConnection.java
│ │ ├── RecoverableChannel.java
│ │ ├── BuiltinExchangeType.java
│ │ ├── ResolvedInetAddress.java
│ │ ├── TrafficListener.java
│ │ ├── SaslConfig.java
│ │ ├── AuthenticationFailureException.java
│ │ ├── UnblockedCallback.java
│ │ ├── BlockedCallback.java
│ │ ├── BlockedListener.java
│ │ ├── MissedHeartbeatException.java
│ │ ├── ReturnCallback.java
│ │ ├── ListAddressResolver.java
│ │ ├── MalformedFrameException.java
│ │ ├── ReturnListener.java
│ │ ├── SslContextFactory.java
│ │ ├── ConfirmCallback.java
│ │ ├── PossibleAuthenticationFailureException.java
│ │ ├── ConfirmListener.java
│ │ ├── SaslMechanism.java
│ │ ├── ConsumerCancelledException.java
│ │ ├── Method.java
│ │ ├── ShutdownListener.java
│ │ ├── Recoverable.java
│ │ ├── UnroutableRpcRequestException.java
│ │ ├── TopologyRecoveryException.java
│ │ ├── DefaultSocketConfigurator.java
│ │ ├── ContentHeader.java
│ │ ├── UnexpectedFrameError.java
│ │ ├── UnknownClassOrMethodId.java
│ │ ├── ChannelContinuationTimeoutException.java
│ │ ├── Command.java
│ │ ├── Delivery.java
│ │ ├── SocketConfigurator.java
│ │ ├── AlreadyClosedException.java
│ │ ├── RecoveryListener.java
│ │ ├── Return.java
│ │ ├── ConsumerShutdownSignalCallback.java
│ │ ├── DeliverCallback.java
│ │ ├── AddressResolver.java
│ │ ├── SslEngineConfigurator.java
│ │ ├── CancelCallback.java
│ │ └── UnexpectedMethodError.java
│ │ ├── tools
│ │ ├── package-info.java
│ │ ├── json
│ │ │ └── package-info.java
│ │ └── jsonrpc
│ │ │ ├── package-info.java
│ │ │ ├── JsonRpcMappingException.java
│ │ │ └── JsonRpcException.java
│ │ └── utility
│ │ ├── package-info.java
│ │ ├── SensibleClone.java
│ │ └── BlockingValueOrException.java
│ └── scripts
│ └── generate_amqp_sources.groovy
├── doc
└── channels
│ ├── channels.pdf
│ ├── channels.tex
│ ├── whiteboard.JPG
│ └── worktransition.pdf
├── release-versions.txt
├── .git-blame-ignore-revs
├── .gitignore
├── generate-observation-documentation.sh
├── deploy-javadoc.sh
├── LICENSE
├── ci
├── cluster
│ ├── configuration
│ │ └── rabbitmq.conf
│ └── docker-compose.yml
├── release-java-client.sh
├── start-cluster.sh
└── start-broker.sh
├── .github
├── workflows
│ ├── publish-snapshot.yml
│ ├── release.yml
│ └── codeql-analysis.yml
├── dependabot.yml
├── ISSUE_TEMPLATE.md
└── PULL_REQUEST_TEMPLATE.md
└── Makefile
/.mvn/maven.config:
--------------------------------------------------------------------------------
1 | -Dmaven.wagon.http.retryHandler.count=10
2 |
--------------------------------------------------------------------------------
/src/test/resources/junit-platform.properties:
--------------------------------------------------------------------------------
1 | junit.jupiter.extensions.autodetection.enabled=true
--------------------------------------------------------------------------------
/src/main/resources/rabbitmq-amqp-client.properties:
--------------------------------------------------------------------------------
1 | com.rabbitmq.client.version = ${project.version}
2 |
--------------------------------------------------------------------------------
/doc/channels/channels.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rabbitmq/rabbitmq-java-client/HEAD/doc/channels/channels.pdf
--------------------------------------------------------------------------------
/doc/channels/channels.tex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rabbitmq/rabbitmq-java-client/HEAD/doc/channels/channels.tex
--------------------------------------------------------------------------------
/release-versions.txt:
--------------------------------------------------------------------------------
1 | RELEASE_VERSION="6.0.0.M2"
2 | DEVELOPMENT_VERSION="6.0.0-SNAPSHOT"
3 | RELEASE_BRANCH="main"
4 |
--------------------------------------------------------------------------------
/doc/channels/whiteboard.JPG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rabbitmq/rabbitmq-java-client/HEAD/doc/channels/whiteboard.JPG
--------------------------------------------------------------------------------
/src/test/resources/META-INF/services/org.junit.jupiter.api.extension.Extension:
--------------------------------------------------------------------------------
1 | com.rabbitmq.client.AmqpClientTestExtension
--------------------------------------------------------------------------------
/doc/channels/worktransition.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rabbitmq/rabbitmq-java-client/HEAD/doc/channels/worktransition.pdf
--------------------------------------------------------------------------------
/.git-blame-ignore-revs:
--------------------------------------------------------------------------------
1 | # Bump (c) year to 2025
2 | 24d78382a0c195904f054413f208e9e1aa92bc11
3 | be27b603f804d24a293013298b84307227f263b6
4 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/observation/package-info.java:
--------------------------------------------------------------------------------
1 | /** Observability abstractions. */
2 | package com.rabbitmq.client.observation;
3 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/tools/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Non-core utilities and administration tools.
3 | */
4 | package com.rabbitmq.tools;
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/tools/json/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * JSON reader/writer and utility classes.
3 | */
4 | package com.rabbitmq.tools.json;
--------------------------------------------------------------------------------
/src/main/resources/META-INF/native-image/com.rabbitmq/amqp-client/native-image.properties:
--------------------------------------------------------------------------------
1 | Args=-H:IncludeResources=rabbitmq-amqp-client.properties|version.properties
2 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/impl/recovery/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Implementation of connection and topology recovery.
3 | */
4 | package com.rabbitmq.client.impl.recovery;
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/utility/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Utility package of helper classes, mostly used in the implementation code.
3 | */
4 | package com.rabbitmq.utility;
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/observation/micrometer/package-info.java:
--------------------------------------------------------------------------------
1 | /** Micrometer-based observability implementation. */
2 | package com.rabbitmq.client.observation.micrometer;
3 |
--------------------------------------------------------------------------------
/src/test/resources/property-file-initialisation/tls/keystore.p12:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rabbitmq/rabbitmq-java-client/HEAD/src/test/resources/property-file-initialisation/tls/keystore.p12
--------------------------------------------------------------------------------
/src/main/resources/version.properties:
--------------------------------------------------------------------------------
1 | # here for backward compatibility
2 | # use rabbitmq-amqp-client.properties to add or read properties
3 | com.rabbitmq.client.version = ${project.version}
4 |
--------------------------------------------------------------------------------
/src/test/resources/property-file-initialisation/tls/truststore.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rabbitmq/rabbitmq-java-client/HEAD/src/test/resources/property-file-initialisation/tls/truststore.jks
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/impl/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Implementations of interfaces specified in the client API, and their supporting classes.
3 | */
4 | package com.rabbitmq.client.impl;
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/tools/jsonrpc/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * JSON-RPC client and server classes for supporting JSON-RPC over an AMQP transport.
3 | */
4 | package com.rabbitmq.tools.jsonrpc;
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *~
2 | .sw?
3 | .*.sw?
4 | *.beam
5 | *.class
6 | *.dat
7 | *.dump
8 | *.iml
9 | *.ipr
10 | *.iws
11 | .DS_Store
12 | \#~
13 | /.idea/
14 | /deps/
15 | /target/
16 | /.classpath
17 | /.project
18 | /.settings
19 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * The client API proper: classes and interfaces representing the AMQP
3 | * connections, channels, and wire-protocol framing descriptors.
4 | */
5 | package com.rabbitmq.client;
--------------------------------------------------------------------------------
/generate-observation-documentation.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ./mvnw -q test-compile exec:java \
4 | -Dexec.mainClass=io.micrometer.docs.DocsGeneratorCommand \
5 | -Dexec.classpathScope="test" \
6 | -Dexec.args='src/main/java/com/rabbitmq/client/observation/micrometer .* target/micrometer-observation-docs'
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/RecoverableConnection.java:
--------------------------------------------------------------------------------
1 | package com.rabbitmq.client;
2 |
3 | /**
4 | * Convenient interface when working against auto-recovery connections.
5 | *
6 | * @since 4.0.0
7 | */
8 | public interface RecoverableConnection extends Recoverable, Connection {
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/impl/FrameHandlerFactory.java:
--------------------------------------------------------------------------------
1 | package com.rabbitmq.client.impl;
2 |
3 | import com.rabbitmq.client.Address;
4 |
5 | import java.io.IOException;
6 |
7 | /**
8 | *
9 | */
10 | public interface FrameHandlerFactory {
11 |
12 | FrameHandler create(Address addr, String connectionName) throws IOException;
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/RecoverableChannel.java:
--------------------------------------------------------------------------------
1 | package com.rabbitmq.client;
2 |
3 | import com.rabbitmq.client.Channel;
4 | import com.rabbitmq.client.Recoverable;
5 |
6 | /**
7 | * Convenient interface when working against auto-recovery channels.
8 | *
9 | * @since 4.0.0
10 | */
11 | public interface RecoverableChannel extends Recoverable, Channel {
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/BuiltinExchangeType.java:
--------------------------------------------------------------------------------
1 | package com.rabbitmq.client;
2 |
3 | /**
4 | * Enum for built-in exchange types.
5 | */
6 | public enum BuiltinExchangeType {
7 |
8 | DIRECT("direct"), FANOUT("fanout"), TOPIC("topic"), HEADERS("headers");
9 |
10 | private final String type;
11 |
12 | BuiltinExchangeType(String type) {
13 | this.type = type;
14 | }
15 |
16 | public String getType() {
17 | return type;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/impl/HeartbeatSender.java:
--------------------------------------------------------------------------------
1 | package com.rabbitmq.client.impl;
2 |
3 | interface HeartbeatSender {
4 |
5 | HeartbeatSender NO_OP =
6 | new HeartbeatSender() {
7 | @Override
8 | public void setHeartbeat(int heartbeat) {}
9 |
10 | @Override
11 | public void signalActivity() {}
12 |
13 | @Override
14 | public void shutdown() {}
15 | };
16 |
17 | void setHeartbeat(int heartbeat);
18 |
19 | void signalActivity();
20 |
21 | void shutdown();
22 | }
23 |
--------------------------------------------------------------------------------
/deploy-javadoc.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | DEPLOY_DIRECTORY=api/current
4 | TAG=$(git describe --exact-match --tags $(git log -n1 --pretty='%h'))
5 |
6 | make deps
7 | ./mvnw -q clean javadoc:javadoc -Dmaven.javadoc.failOnError=false
8 |
9 | if [ -e target/javadoc-bundle-options/element-list ]
10 | then cp target/javadoc-bundle-options/element-list target/reports/apidocs/package-list
11 | fi
12 |
13 | git co gh-pages
14 | rm -rf $DEPLOY_DIRECTORY/*
15 | cp -r target/reports/apidocs/* $DEPLOY_DIRECTORY
16 | git add $DEPLOY_DIRECTORY
17 | git commit -m "Add Javadoc for $TAG"
18 | git push origin gh-pages
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/ResolvedInetAddress.java:
--------------------------------------------------------------------------------
1 | package com.rabbitmq.client;
2 |
3 | import java.net.InetAddress;
4 | import java.net.InetSocketAddress;
5 |
6 | public class ResolvedInetAddress extends Address {
7 | private final InetAddress inetAddress;
8 |
9 | public ResolvedInetAddress(String originalHostname, InetAddress inetAddress, int port) {
10 | super(originalHostname, port);
11 | this.inetAddress = inetAddress;
12 | }
13 |
14 | @Override
15 | public InetSocketAddress toInetSocketAddress(int port) {
16 | return new InetSocketAddress(inetAddress, port);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/impl/recovery/RecoveredQueueNameSupplier.java:
--------------------------------------------------------------------------------
1 | package com.rabbitmq.client.impl.recovery;
2 |
3 | /**
4 | * Functional callback interface that can be used to rename a queue during topology recovery.
5 | * Can use along with {@link QueueRecoveryListener} to know when such a queue has been recovered successfully.
6 | *
7 | * @see QueueRecoveryListener
8 | */
9 | @FunctionalInterface
10 | public interface RecoveredQueueNameSupplier {
11 |
12 | /**
13 | * Get the queue name to use when recovering this RecordedQueue entity
14 | * @param recordedQueue the queue to be recovered
15 | * @return new queue name
16 | */
17 | String getNameToUseForRecovery(final RecordedQueue recordedQueue);
18 | }
--------------------------------------------------------------------------------
/src/test/resources/property-file-initialisation/configuration.properties:
--------------------------------------------------------------------------------
1 | rabbitmq.uri=amqp://bar:foo@somewhere:5674/foobar
2 | rabbitmq.username=foo
3 | rabbitmq.password=bar
4 | rabbitmq.virtual.host=dummy
5 | rabbitmq.host=127.0.0.1
6 | rabbitmq.port=5673
7 | rabbitmq.connection.channel.max=1
8 | rabbitmq.connection.frame.max=2
9 | rabbitmq.connection.heartbeat=10
10 | rabbitmq.connection.timeout=10000
11 | rabbitmq.handshake.timeout=5000
12 | rabbitmq.shutdown.timeout=20000
13 | rabbitmq.use.default.client.properties=true
14 | rabbitmq.client.properties.foo=bar
15 | rabbitmq.connection.recovery.enabled=false
16 | rabbitmq.topology.recovery.enabled=false
17 | rabbitmq.connection.recovery.interval=10000
18 | rabbitmq.channel.rpc.timeout=10000
19 | rabbitmq.channel.should.check.rpc.response.type=true
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | This package, the RabbitMQ Java client library, is triple-licensed under
2 | the Mozilla Public License 2.0 ("MPL"), the GNU General Public License
3 | version 2 ("GPL") and the Apache License version 2 ("ASL"). For the MPL,
4 | please see LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2.
5 | For the ASL, please see LICENSE-APACHE2.
6 |
7 | This means that you may choose one of these licenses when including or
8 | using this software in your own.
9 |
10 | The RabbitMQ Java client library includes third-party software under the
11 | ASL. For this license, please see LICENSE-APACHE2. For attribution of
12 | copyright and other details of provenance, please refer to the source code.
13 |
14 | If you have any questions regarding licensing, please contact us at
15 | info@rabbitmq.com.
16 |
--------------------------------------------------------------------------------
/src/test/resources/logback-test.xml:
--------------------------------------------------------------------------------
1 |
TRACE level.
10 | *
11 | * This implementation checks whether the Requires RabbitMQ 4.0 or more.
26 | */
27 | public class AnonymousMechanism implements SaslMechanism {
28 | @Override
29 | public String getName() {
30 | return "ANONYMOUS";
31 | }
32 |
33 | @Override
34 | public LongString handleChallenge(LongString challenge, String username, String password) {
35 | return LongStringHelper.asLongString("");
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/impl/NetworkConnection.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 | package com.rabbitmq.client.impl;
17 |
18 | import java.net.InetAddress;
19 |
20 | public interface NetworkConnection {
21 |
22 | /**
23 | * Retrieve the local host.
24 | * @return the client socket address.
25 | */
26 | InetAddress getLocalAddress();
27 |
28 | /**
29 | * Retrieve the local port number.
30 | * @return the client socket port number
31 | */
32 | int getLocalPort();
33 |
34 | /** Retrieve address of peer. */
35 | InetAddress getAddress();
36 |
37 | /** Retrieve port number of peer. */
38 | int getPort();
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/impl/AMQBasicProperties.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 | package com.rabbitmq.client.impl;
17 |
18 | import java.io.DataInputStream;
19 | import java.io.IOException;
20 |
21 | import com.rabbitmq.client.BasicProperties;
22 |
23 | public abstract class AMQBasicProperties
24 | extends AMQContentHeader implements BasicProperties {
25 |
26 | protected AMQBasicProperties() {
27 |
28 | }
29 |
30 | protected AMQBasicProperties(DataInputStream in) throws IOException {
31 | super(in);
32 | }
33 |
34 | @Override
35 | public Object clone() throws CloneNotSupportedException {
36 | return super.clone();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | MVN ?= mvn
2 | MVN_FLAGS ?=
3 |
4 | ifndef DEPS_DIR
5 | ifneq ($(wildcard ../../UMBRELLA.md),)
6 | DEPS_DIR = ..
7 | else
8 | DEPS_DIR = deps
9 | endif
10 | endif
11 |
12 | MVN_FLAGS += -Ddeps.dir="$(abspath $(DEPS_DIR))"
13 |
14 | .PHONY: all deps tests clean distclean
15 |
16 | all: deps
17 | $(MVN) $(MVN_FLAGS) compile
18 |
19 | deps: $(DEPS_DIR)/rabbitmq_codegen
20 | @:
21 |
22 | dist: clean
23 | $(MVN) $(MVN_FLAGS) -DskipTests=true -Dmaven.javadoc.failOnError=false package javadoc:javadoc
24 |
25 | $(DEPS_DIR)/rabbitmq_codegen:
26 | git clone -n --depth=1 --filter=tree:0 https://github.com/rabbitmq/rabbitmq-server.git $(DEPS_DIR)/rabbitmq-server
27 | git -C $(DEPS_DIR)/rabbitmq-server sparse-checkout set --no-cone deps/rabbitmq_codegen
28 | git -C $(DEPS_DIR)/rabbitmq-server checkout
29 | cp -R $(DEPS_DIR)/rabbitmq-server/deps/rabbitmq_codegen "$@"
30 | rm -rf $(DEPS_DIR)/rabbitmq-server
31 |
32 | tests: deps
33 | $(MVN) $(MVN_FLAGS) verify
34 |
35 | deploy:
36 | $(MVN) $(MVN_FLAGS) deploy
37 |
38 | clean:
39 | $(MVN) $(MVN_FLAGS) clean
40 |
41 | distclean: clean
42 | $(MAKE) -C $(DEPS_DIR)/rabbitmq_codegen clean
43 |
44 | .PHONY: cluster-other-node
45 |
46 | cluster-other-node:
47 | $(exec_verbose) $(RABBITMQCTL) -n $(OTHER_NODE) stop_app
48 | $(verbose) $(RABBITMQCTL) -n $(OTHER_NODE) reset
49 | $(verbose) $(RABBITMQCTL) -n $(OTHER_NODE) join_cluster \
50 | $(if $(MAIN_NODE),$(MAIN_NODE),$(RABBITMQ_NODENAME)@$$(hostname -s))
51 | $(verbose) $(RABBITMQCTL) -n $(OTHER_NODE) start_app
52 |
--------------------------------------------------------------------------------
/src/test/java/com/rabbitmq/client/impl/recovery/AutorecoveringChannelTest.java:
--------------------------------------------------------------------------------
1 | package com.rabbitmq.client.impl.recovery;
2 |
3 | import org.junit.jupiter.api.BeforeEach;
4 | import org.junit.jupiter.api.Test;
5 | import org.mockito.Mock;
6 | import org.mockito.MockitoAnnotations;
7 |
8 | import static org.mockito.Mockito.times;
9 | import static org.mockito.Mockito.verify;
10 |
11 | public final class AutorecoveringChannelTest {
12 |
13 | private AutorecoveringChannel channel;
14 |
15 | @Mock
16 | private AutorecoveringConnection autorecoveringConnection;
17 |
18 | @Mock
19 | private RecoveryAwareChannelN recoveryAwareChannelN;
20 |
21 | @BeforeEach
22 | void setup() {
23 | MockitoAnnotations.openMocks(this);
24 | this.channel = new AutorecoveringChannel(autorecoveringConnection, recoveryAwareChannelN);
25 | }
26 |
27 | @Test
28 | void abort() {
29 | this.channel.abort();
30 | verify(recoveryAwareChannelN, times(1)).abort();
31 | }
32 |
33 | @Test
34 | void abortWithDetails() {
35 | int closeCode = 1;
36 | String closeMessage = "reason";
37 | this.channel.abort(closeCode, closeMessage);
38 | verify(recoveryAwareChannelN, times(1)).abort(closeCode, closeMessage);
39 | }
40 |
41 | @Test
42 | void abortWithDetailsCloseMessageNull() {
43 | int closeCode = 1;
44 | this.channel.abort(closeCode, null);
45 | verify(recoveryAwareChannelN, times(1)).abort(closeCode, "");
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/ReturnListener.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 |
17 | package com.rabbitmq.client;
18 |
19 | import java.io.IOException;
20 |
21 | /**
22 | * Implement this interface in order to be notified of failed
23 | * deliveries when basicPublish is called with "mandatory" or
24 | * "immediate" flags set.
25 | * For a lambda-oriented syntax, use {@link ReturnCallback}.
26 | * @see Channel#basicPublish
27 | */
28 | public interface ReturnListener {
29 | void handleReturn(int replyCode,
30 | String replyText,
31 | String exchange,
32 | String routingKey,
33 | AMQP.BasicProperties properties,
34 | byte[] body)
35 | throws IOException;
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/SslContextFactory.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017-2023 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 | package com.rabbitmq.client;
17 |
18 | import javax.net.ssl.SSLContext;
19 |
20 | /**
21 | * A factory to create {@link SSLContext}s.
22 | *
23 | * @see ConnectionFactory#setSslContextFactory(SslContextFactory)
24 | * @since 5.0.0
25 | */
26 | public interface SslContextFactory {
27 |
28 | /**
29 | * Create a {@link SSLContext} for a given name.
30 | * The name is typically the name of the connection.
31 | * @param name name of the connection the SSLContext is used for
32 | * @return the SSLContext for this name
33 | * @see ConnectionFactory#newConnection(String)
34 | */
35 | SSLContext create(String name);
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/impl/ErrorOnWriteListener.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018-2023 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 | package com.rabbitmq.client.impl;
17 |
18 | import com.rabbitmq.client.Connection;
19 |
20 | import java.io.IOException;
21 |
22 | /**
23 | * Listener called when a connection gets an IO error trying to write on the socket.
24 | * This can be used to trigger connection recovery.
25 | *
26 | * @since 4.5.0
27 | */
28 | public interface ErrorOnWriteListener {
29 |
30 | /**
31 | * Called when writing to the socket failed
32 | * @param connection the owning connection instance
33 | * @param exception the thrown exception
34 | */
35 | void handle(Connection connection, IOException exception) throws IOException;
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/utility/SensibleClone.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 | package com.rabbitmq.utility;
17 |
18 | /**
19 | * This interface exists as a workaround for the annoyingness of java.lang.Cloneable.
20 | * It is used for generic methods which need to accept something they can actually clone
21 | * (Object.clone is protected and java.lang.Cloneable does not define a public clone method)
22 | * and want to provide some guarantees of the type of the cloned object.
23 | */
24 | public interface SensibleClone
21 | * The {@link RpcClient} must be configured with the mandatory
22 | * flag set to true with {@link RpcClientParams#useMandatory()}.
23 | *
24 | * @see RpcClientParams#useMandatory()
25 | * @see RpcClient#RpcClient(RpcClientParams)
26 | * @since 5.6.0
27 | */
28 | public class UnroutableRpcRequestException extends RuntimeException {
29 |
30 | private final Return returnMessage;
31 |
32 | public UnroutableRpcRequestException(Return returnMessage) {
33 | this.returnMessage = returnMessage;
34 | }
35 |
36 | /**
37 | * The returned message.
38 | *
39 | * @return
40 | */
41 | public Return getReturnMessage() {
42 | return returnMessage;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/test/java/com/rabbitmq/client/test/functional/ExchangeDeletePredeclared.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 | package com.rabbitmq.client.test.functional;
17 |
18 | import com.rabbitmq.client.AMQP;
19 | import com.rabbitmq.client.test.BrokerTestCase;
20 |
21 | import java.io.IOException;
22 |
23 | public class ExchangeDeletePredeclared extends BrokerTestCase {
24 | public void testDeletingPredeclaredAmqExchange() throws IOException {
25 | try {
26 | channel.exchangeDelete("amq.fanout");
27 | } catch (IOException e) {
28 | checkShutdownSignal(AMQP.ACCESS_REFUSED, e);
29 | }
30 | }
31 |
32 | public void testDeletingPredeclaredAmqRabbitMQExchange() throws IOException {
33 | try {
34 | channel.exchangeDelete("amq.rabbitmq.log");
35 | } catch (IOException e) {
36 | checkShutdownSignal(AMQP.ACCESS_REFUSED, e);
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/test/java/com/rabbitmq/client/test/functional/MessageCount.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 | package com.rabbitmq.client.test.functional;
17 |
18 | import static org.junit.jupiter.api.Assertions.assertEquals;
19 |
20 | import java.io.IOException;
21 |
22 | import org.junit.jupiter.api.Test;
23 |
24 | import com.rabbitmq.client.test.BrokerTestCase;
25 |
26 | public class MessageCount extends BrokerTestCase {
27 | @Test public void messageCount() throws IOException {
28 | String q = generateQueueName();
29 | channel.queueDeclare(q, false, true, false, null);
30 | assertEquals(0, channel.messageCount(q));
31 |
32 | basicPublishVolatile(q);
33 | assertEquals(1, channel.messageCount(q));
34 | basicPublishVolatile(q);
35 | assertEquals(2, channel.messageCount(q));
36 |
37 | channel.queuePurge(q);
38 | assertEquals(0, channel.messageCount(q));
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/test/java/com/rabbitmq/client/test/functional/ConsumerCount.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 | package com.rabbitmq.client.test.functional;
17 |
18 | import static org.junit.jupiter.api.Assertions.assertEquals;
19 |
20 | import java.io.IOException;
21 |
22 | import org.junit.jupiter.api.Test;
23 |
24 | import com.rabbitmq.client.DefaultConsumer;
25 | import com.rabbitmq.client.test.BrokerTestCase;
26 |
27 | public class ConsumerCount extends BrokerTestCase {
28 | @Test public void consumerCount() throws IOException {
29 | String q = generateQueueName();
30 | channel.queueDeclare(q, false, true, false, null);
31 | assertEquals(0, channel.consumerCount(q));
32 |
33 | String tag = channel.basicConsume(q, new DefaultConsumer(channel));
34 | assertEquals(1, channel.consumerCount(q));
35 |
36 | channel.basicCancel(tag);
37 | assertEquals(0, channel.consumerCount(q));
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/impl/RpcContinuationRpcWrapper.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017-2023 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 | package com.rabbitmq.client.impl;
17 |
18 | import com.rabbitmq.client.ShutdownSignalException;
19 |
20 | /**
21 | *
22 | */
23 | public class RpcContinuationRpcWrapper implements RpcWrapper {
24 |
25 | private final AMQChannel.RpcContinuation continuation;
26 |
27 | public RpcContinuationRpcWrapper(AMQChannel.RpcContinuation continuation) {
28 | this.continuation = continuation;
29 | }
30 |
31 | @Override
32 | public boolean canHandleReply(AMQCommand command) {
33 | return continuation.canHandleReply(command);
34 | }
35 |
36 | @Override
37 | public void complete(AMQCommand command) {
38 | continuation.handleCommand(command);
39 | }
40 |
41 | @Override
42 | public void shutdown(ShutdownSignalException signal) {
43 | continuation.handleShutdownSignal(signal);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/observation/NoOpObservationCollector.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007-2025 Broadcom. All Rights Reserved.
2 | // The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
3 | //
4 | // This software, the RabbitMQ Java client library, is triple-licensed under the
5 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
6 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
7 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
8 | // please see LICENSE-APACHE2.
9 | //
10 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
11 | // either express or implied. See the LICENSE file for specific language governing
12 | // rights and limitations of this software.
13 | //
14 | // If you have any questions regarding licensing, please contact us at
15 | // info@rabbitmq.com.
16 | package com.rabbitmq.client.observation;
17 |
18 | import com.rabbitmq.client.AMQP;
19 | import com.rabbitmq.client.Consumer;
20 | import com.rabbitmq.client.GetResponse;
21 | import java.io.IOException;
22 |
23 | final class NoOpObservationCollector implements ObservationCollector {
24 |
25 | @Override
26 | public void publish(
27 | PublishCall call,
28 | AMQP.Basic.Publish publish,
29 | AMQP.BasicProperties properties,
30 | byte[] body,
31 | ConnectionInfo connectionInfo)
32 | throws IOException {
33 | call.publish(properties);
34 | }
35 |
36 | @Override
37 | public Consumer basicConsume(String queue, String consumerTag, Consumer consumer) {
38 | return consumer;
39 | }
40 |
41 | @Override
42 | public GetResponse basicGet(BasicGetCall call, String queue) {
43 | return call.get();
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/TopologyRecoveryException.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 | package com.rabbitmq.client;
17 |
18 | import com.rabbitmq.client.impl.recovery.RecordedEntity;
19 |
20 | /**
21 | * Indicates an exception thrown during topology recovery.
22 | *
23 | * @see com.rabbitmq.client.ConnectionFactory#setTopologyRecoveryEnabled(boolean)
24 | * @since 3.3.0
25 | */
26 | public class TopologyRecoveryException extends Exception {
27 |
28 | private final RecordedEntity recordedEntity;
29 |
30 | public TopologyRecoveryException(String message, Throwable cause) {
31 | this(message, cause, null);
32 | }
33 |
34 | public TopologyRecoveryException(String message, Throwable cause, final RecordedEntity recordedEntity) {
35 | super(message, cause);
36 | this.recordedEntity = recordedEntity;
37 | }
38 |
39 | public RecordedEntity getRecordedEntity() {
40 | return recordedEntity;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/DefaultSocketConfigurator.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 | package com.rabbitmq.client;
17 |
18 | import java.io.IOException;
19 | import java.net.Socket;
20 |
21 | public class DefaultSocketConfigurator implements SocketConfigurator {
22 | /**
23 | * Provides a hook to insert custom configuration of the sockets
24 | * used to connect to an AMQP server before they connect.
25 | *
26 | * The default behaviour of this method is to disable Nagle's
27 | * algorithm to get more consistently low latency. However it
28 | * may be overridden freely and there is no requirement to retain
29 | * this behaviour.
30 | *
31 | * @param socket The socket that is to be used for the Connection
32 | */
33 | @Override
34 | public void configure(Socket socket) throws IOException {
35 | // disable Nagle's algorithm, for more consistently low latency
36 | socket.setTcpNoDelay(true);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/scripts/generate_amqp_sources.groovy:
--------------------------------------------------------------------------------
1 | import java.security.MessageDigest
2 |
3 | def md5(final file) {
4 | MessageDigest digest = MessageDigest.getInstance("MD5")
5 | file.withInputStream() { is ->
6 | byte[] buffer = new byte[8192]
7 | int read = 0
8 | while ((read = is.read(buffer)) > 0) {
9 | digest.update(buffer, 0, read);
10 | }
11 | }
12 | byte[] md5sum = digest.digest()
13 | BigInteger bigInt = new BigInteger(1, md5sum)
14 | return bigInt.toString(16)
15 | }
16 |
17 | def generate_source(final type, final filename) {
18 | def pythonBin = System.getenv('PYTHON_BIN') ?: 'python'
19 | String[] command = [
20 | pythonBin,
21 | properties['script'], type,
22 | properties['spec'],
23 | filename
24 | ]
25 |
26 | def pb = new ProcessBuilder(command)
27 | pb.environment().put('PYTHONPATH', properties['codegen.dir'])
28 | pb.redirectErrorStream(true)
29 |
30 | def process = pb.start()
31 | process.waitFor()
32 | if (process.exitValue() != 0) {
33 | println(process.in.text.trim())
34 | fail("Failed to generate ${filename} with command: ${command.join(' ')}")
35 | }
36 | }
37 |
38 | def maybe_regen_source(final type, final filename) {
39 | def file = new File(filename)
40 |
41 | if (file.exists()) {
42 | def tmp_filename = filename + '.new'
43 | def tmp_file = new File(tmp_filename)
44 |
45 | generate_source(type, tmp_filename)
46 | old_md5 = md5(file)
47 | new_md5 = md5(tmp_file)
48 |
49 | if (old_md5 == new_md5) {
50 | tmp_file.delete()
51 | } else {
52 | tmp_file.renameTo(file)
53 | }
54 | } else {
55 | generate_source(type, filename)
56 | }
57 |
58 | }
59 |
60 | maybe_regen_source('header', properties['header'])
61 | maybe_regen_source('body', properties['body'])
62 |
--------------------------------------------------------------------------------
/src/test/java/com/rabbitmq/client/test/RequiredPropertiesSuite.java:
--------------------------------------------------------------------------------
1 | package com.rabbitmq.client.test;
2 |
3 |
4 | import java.util.ArrayList;
5 | import java.util.List;
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 |
9 | /**
10 | *
11 | */
12 | public class RequiredPropertiesSuite { //extends Suite {
13 |
14 | /*
15 | private static final Logger LOGGER = LoggerFactory.getLogger(RequiredPropertiesSuite.class);
16 |
17 | public RequiredPropertiesSuite(Class> klass, RunnerBuilder builder) throws InitializationError {
18 | super(klass, builder);
19 | }
20 |
21 | public RequiredPropertiesSuite(RunnerBuilder builder, Class>[] classes) throws InitializationError {
22 | super(builder, classes);
23 | }
24 |
25 | protected RequiredPropertiesSuite(Class> klass, Class>[] suiteClasses) throws InitializationError {
26 | super(klass, suiteClasses);
27 | }
28 |
29 | protected RequiredPropertiesSuite(RunnerBuilder builder, Class> klass, Class>[] suiteClasses) throws InitializationError {
30 | super(builder, klass, suiteClasses);
31 | }
32 |
33 | protected RequiredPropertiesSuite(Class> klass, List The automatic connection recovery calls this method after {@link #getAddresses()} to pick a
38 | * random address for reconnecting.
39 | *
40 | * The default method implementation calls {@link Collections#shuffle(List)}. Custom
41 | * implementations can choose to not do any shuffling to have more predictability in the
42 | * reconnection.
43 | *
44 | * @param input
45 | * @return potentially shuffled list of addresses.
46 | */
47 | default List There is no replacement for this method, as it used to use the {@link SecurityManager},
31 | * which is itself deprecated and subject to removal.
32 | *
33 | * @deprecated
34 | * @return always returns true
35 | */
36 | @Deprecated
37 | public static boolean isAllowedToModifyThreads() {
38 | return true;
39 | }
40 |
41 | static Thread newThread(Runnable runnable, String name) {
42 | return newThread(Executors.defaultThreadFactory(), runnable, name);
43 | }
44 |
45 | public static Thread newThread(ThreadFactory factory, Runnable runnable, String name) {
46 | Thread t = factory.newThread(runnable);
47 | t.setName(name);
48 | return t;
49 | }
50 |
51 | public static Thread newThread(
52 | ThreadFactory factory, Runnable runnable, String name, boolean isDaemon) {
53 | Thread t = newThread(factory, runnable, name);
54 | t.setDaemon(isDaemon);
55 | return t;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/CancelCallback.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017-2023 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 | package com.rabbitmq.client;
17 |
18 | import java.io.IOException;
19 | import java.util.Map;
20 |
21 | /**
22 | * Callback interface to be notified of the cancellation of a consumer.
23 | * Prefer it over {@link Consumer} for a lambda-oriented syntax,
24 | * if you don't need to implement all the application callbacks.
25 | * @see DeliverCallback
26 | * @see ConsumerShutdownSignalCallback
27 | * @see Channel#basicConsume(String, boolean, String, boolean, boolean, Map, DeliverCallback, CancelCallback)
28 | * @see Channel#basicConsume(String, boolean, String, boolean, boolean, Map, DeliverCallback, ConsumerShutdownSignalCallback)
29 | * @see Channel#basicConsume(String, boolean, String, boolean, boolean, Map, DeliverCallback, CancelCallback, ConsumerShutdownSignalCallback)
30 | * @since 5.0
31 | */
32 | @FunctionalInterface
33 | public interface CancelCallback {
34 |
35 | /**
36 | * Called when the consumer is cancelled for reasons other than by a call to
37 | * {@link Channel#basicCancel}. For example, the queue has been deleted.
38 | * See {@link Consumer#handleCancelOk} for notification of consumer
39 | * cancellation due to {@link Channel#basicCancel}.
40 | * @param consumerTag the consumer tag associated with the consumer
41 | * @throws IOException
42 | */
43 | void handle(String consumerTag) throws IOException;
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/test/java/com/rabbitmq/client/test/ssl/BadVerifiedConnection.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 | package com.rabbitmq.client.test.ssl;
17 |
18 | import org.junit.jupiter.api.Test;
19 |
20 | import javax.net.ssl.SSLContext;
21 | import javax.net.ssl.SSLHandshakeException;
22 | import java.io.IOException;
23 | import java.util.concurrent.TimeoutException;
24 | import org.junit.jupiter.api.condition.EnabledForJreRange;
25 | import org.junit.jupiter.api.condition.JRE;
26 |
27 | import static org.junit.jupiter.api.Assertions.fail;
28 |
29 | /**
30 | * Test for bug 19356 - SSL Support in rabbitmq
31 | *
32 | */
33 | @EnabledForJreRange(min = JRE.JAVA_11)
34 | public class BadVerifiedConnection extends UnverifiedConnection {
35 |
36 | public void openConnection()
37 | throws IOException, TimeoutException {
38 | try {
39 | SSLContext c = TlsTestUtils.badVerifiedSslContext();
40 | connectionFactory.useSslProtocol(c);
41 | TlsTestUtils.maybeConfigureNetty(connectionFactory, c);
42 |
43 | } catch (Exception ex) {
44 | throw new IOException(ex);
45 | }
46 |
47 | try {
48 | connection = connectionFactory.newConnection();
49 | fail();
50 | } catch (SSLHandshakeException ignored) {
51 | } catch (IOException e) {
52 | fail();
53 | }
54 | }
55 |
56 | public void openChannel() {}
57 | @Test public void sSL() {}
58 | }
59 |
--------------------------------------------------------------------------------
/src/test/java/com/rabbitmq/client/test/functional/InvalidAcksBase.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 | package com.rabbitmq.client.test.functional;
17 |
18 | import com.rabbitmq.client.AMQP;
19 | import com.rabbitmq.client.test.BrokerTestCase;
20 |
21 | import java.io.IOException;
22 |
23 | import org.junit.jupiter.api.Test;
24 |
25 | /**
26 | * See bug 21846:
27 | * Basic.Ack is now required to signal a channel error immediately upon
28 | * detecting an invalid deliveryTag, even if the channel is (Tx-)transacted.
29 | *
30 | * Specifically, a client MUST not acknowledge the same message more than once.
31 | */
32 | public abstract class InvalidAcksBase extends BrokerTestCase {
33 | protected abstract void select() throws IOException;
34 | protected abstract void commit() throws IOException;
35 |
36 | @Test public void doubleAck()
37 | throws IOException
38 | {
39 | select();
40 | String q = channel.queueDeclare().getQueue();
41 | basicPublishVolatile(q);
42 | commit();
43 |
44 | long tag = channel.basicGet(q, false).getEnvelope().getDeliveryTag();
45 | channel.basicAck(tag, false);
46 | channel.basicAck(tag, false);
47 |
48 | expectError(AMQP.PRECONDITION_FAILED);
49 | }
50 |
51 | @Test public void crazyAck()
52 | throws IOException
53 | {
54 | select();
55 | channel.basicAck(123456, false);
56 | expectError(AMQP.PRECONDITION_FAILED);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/impl/recovery/TopologyRecoveryFilter.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018-2023 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 | package com.rabbitmq.client.impl.recovery;
17 |
18 | /**
19 | * Filter to know whether entities should be recovered or not.
20 | * @since 4.8.0
21 | */
22 | public interface TopologyRecoveryFilter {
23 |
24 | /**
25 | * Decides whether an exchange is recovered or not.
26 | * @param recordedExchange
27 | * @return true to recover the exchange, false otherwise
28 | */
29 | default boolean filterExchange(RecordedExchange recordedExchange) {
30 | return true;
31 | }
32 |
33 | /**
34 | * Decides whether a queue is recovered or not.
35 | * @param recordedQueue
36 | * @return true to recover the queue, false otherwise
37 | */
38 | default boolean filterQueue(RecordedQueue recordedQueue) {
39 | return true;
40 | }
41 |
42 | /**
43 | * Decides whether a binding is recovered or not.
44 | * @param recordedBinding
45 | * @return true to recover the binding, false otherwise
46 | */
47 | default boolean filterBinding(RecordedBinding recordedBinding) {
48 | return true;
49 | }
50 |
51 | /**
52 | * Decides whether a consumer is recovered or not.
53 | * @param recordedConsumer
54 | * @return true to recover the consumer, false otherwise
55 | */
56 | default boolean filterConsumer(RecordedConsumer recordedConsumer) {
57 | return true;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/UnexpectedMethodError.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 |
17 | package com.rabbitmq.client;
18 |
19 | /**
20 | * Indicates that a {@link Method} object was supplied that was not
21 | * expected. For instance, {@link Channel#basicGet} throws this if it
22 | * receives anything other than {@link AMQP.Basic.GetOk} or
23 | * {@link AMQP.Basic.GetEmpty}, and the
24 | * {@link com.rabbitmq.client.impl.AMQImpl.DefaultMethodVisitor DefaultMethodVisitor}
25 | * throws this as the action within each visitor case.
26 | */
27 | public class UnexpectedMethodError extends RuntimeException {
28 | private static final long serialVersionUID = 1L;
29 | private final Method _method;
30 |
31 | /**
32 | * Construct an UnexpectedMethodError with the given method parameter
33 | * @param method the unexpected method
34 | */
35 | public UnexpectedMethodError(Method method) {
36 | _method = method;
37 | }
38 |
39 | /**
40 | * Return a string representation of this error.
41 | * @return a string describing the error
42 | */
43 | @Override
44 | public String toString() {
45 | return super.toString() + ": " + _method;
46 | }
47 |
48 | /**
49 | * Return the wrapped method.
50 | * @return the method whose appearance was "unexpected" and was deemed an error
51 | */
52 | public Method getMethod() {
53 | return _method;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/.github/workflows/codeql-analysis.yml:
--------------------------------------------------------------------------------
1 | # For most projects, this workflow file will not need changing; you simply need
2 | # to commit it to your repository.
3 | #
4 | # You may wish to alter this file to override the set of languages analyzed,
5 | # or to provide custom queries or build logic.
6 | #
7 | # ******** NOTE ********
8 | # We have attempted to detect the languages in your repository. Please check
9 | # the `language` matrix defined below to confirm you have the correct set of
10 | # supported CodeQL languages.
11 | #
12 | name: "CodeQL"
13 |
14 | on:
15 | push:
16 | branches: [ main ]
17 | pull_request:
18 | # The branches below must be a subset of the branches above
19 | branches: [ main ]
20 | schedule:
21 | - cron: '21 11 * * 6'
22 |
23 | jobs:
24 | analyze:
25 | name: Analyze
26 | runs-on: ubuntu-latest
27 | permissions:
28 | actions: read
29 | contents: read
30 | security-events: write
31 |
32 | strategy:
33 | fail-fast: false
34 | matrix:
35 | language: [ 'java', 'python' ]
36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
37 | # Learn more:
38 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
39 |
40 | steps:
41 | - name: Checkout repository
42 | uses: actions/checkout@v6
43 |
44 | # Initializes the CodeQL tools for scanning.
45 | - name: Initialize CodeQL
46 | uses: github/codeql-action/init@v4
47 | with:
48 | languages: ${{ matrix.language }}
49 | # If you wish to specify custom queries, you can do so here or in a config file.
50 | # By default, queries listed here will override any specified in a config file.
51 | # Prefix the list here with "+" to use these queries and those in the config file.
52 | # queries: ./path/to/local/query, your-org/your-repo/queries@main
53 |
54 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
55 | # If this step fails, then you should remove it and run the build manually (see below)
56 |
57 | - run: |
58 | make
59 |
60 | - name: Perform CodeQL Analysis
61 | uses: github/codeql-action/analyze@v4
62 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/impl/CRDemoMechanism.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 | package com.rabbitmq.client.impl;
17 |
18 | import com.rabbitmq.client.LongString;
19 | import com.rabbitmq.client.SaslConfig;
20 | import com.rabbitmq.client.SaslMechanism;
21 |
22 | import java.util.Arrays;
23 |
24 | /**
25 | Provides equivalent security to PLAIN but demos use of Connection.Secure(Ok)
26 | START-OK: Username
27 | SECURE: "Please tell me your password"
28 | SECURE-OK: Password
29 | */
30 |
31 | public class CRDemoMechanism implements SaslMechanism {
32 | private static final String NAME = "RABBIT-CR-DEMO";
33 |
34 | private int round = 0;
35 |
36 | @Override
37 | public String getName() {
38 | return NAME;
39 | }
40 |
41 | @Override
42 | public LongString handleChallenge(LongString challenge, String username, String password) {
43 | round++;
44 | if (round == 1) {
45 | return LongStringHelper.asLongString(username);
46 | } else {
47 | return LongStringHelper.asLongString("My password is " + password);
48 | }
49 | }
50 |
51 | public static class CRDemoSaslConfig implements SaslConfig {
52 | @Override
53 | public SaslMechanism getSaslMechanism(String[] mechanisms) {
54 | if (Arrays.asList(mechanisms).contains(NAME)) {
55 | return new CRDemoMechanism();
56 | }
57 | else {
58 | return null;
59 | }
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/impl/CredentialsProvider.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018-2023 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 | package com.rabbitmq.client.impl;
17 |
18 | import java.time.Duration;
19 |
20 | /**
21 | * Provider interface for establishing credentials for connecting to the broker. Especially useful
22 | * for situations where credentials might expire or change before a recovery takes place or where it is
23 | * convenient to plug in an outside custom implementation.
24 | *
25 | * @see CredentialsRefreshService
26 | * @since 5.2.0
27 | */
28 | public interface CredentialsProvider {
29 |
30 | /**
31 | * Username to use for authentication
32 | *
33 | * @return username
34 | */
35 | String getUsername();
36 |
37 | /**
38 | * Password/secret/token to use for authentication
39 | *
40 | * @return password/secret/token
41 | */
42 | String getPassword();
43 |
44 | /**
45 | * The time before the credentials expire, if they do expire.
46 | *
47 | * If credentials do not expire, must return null. Default
48 | * behavior is to return null, assuming credentials never
49 | * expire.
50 | *
51 | * @return time before expiration
52 | */
53 | default Duration getTimeBeforeExpiration() {
54 | return null;
55 | }
56 |
57 | /**
58 | * Instructs the provider to refresh or renew credentials.
59 | *
60 | * Default behavior is no-op.
61 | */
62 | default void refresh() {
63 | // no need to refresh anything by default
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/src/test/java/com/rabbitmq/client/test/server/PersistenceGuarantees.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 | package com.rabbitmq.client.test.server;
17 |
18 | import static org.junit.jupiter.api.Assertions.assertEquals;
19 |
20 | import java.io.IOException;
21 |
22 | import org.junit.jupiter.api.Test;
23 |
24 | import com.rabbitmq.client.MessageProperties;
25 | import com.rabbitmq.client.test.BrokerTestCase;
26 |
27 | public class PersistenceGuarantees extends BrokerTestCase {
28 | private static final int COUNT = 10000;
29 | private String queue;
30 |
31 | protected void declareQueue() throws IOException {
32 | queue = channel.queueDeclare("", true, false, false, null).getQueue();
33 | }
34 |
35 | @Test public void txPersistence() throws Exception {
36 | declareQueue();
37 | channel.txSelect();
38 | publish();
39 | channel.txCommit();
40 | restart();
41 | assertPersisted();
42 | }
43 |
44 | @Test public void confirmPersistence() throws Exception {
45 | declareQueue();
46 | channel.confirmSelect();
47 | publish();
48 | channel.waitForConfirms();
49 | restart();
50 | assertPersisted();
51 | }
52 |
53 | private void assertPersisted() throws IOException {
54 | assertEquals(COUNT, channel.queueDelete(queue).getMessageCount());
55 | }
56 |
57 | private void publish() throws IOException {
58 | for (int i = 0; i < COUNT; i++) {
59 | channel.basicPublish("", queue, false, false, MessageProperties.PERSISTENT_BASIC, "".getBytes());
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/tools/jsonrpc/JsonRpcException.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 | package com.rabbitmq.tools.jsonrpc;
17 |
18 | /**
19 | * Thrown when a JSON-RPC service indicates an error occurred during a call.
20 | */
21 | public class JsonRpcException extends Exception {
22 |
23 | /**
24 | * Default serialized version ID
25 | */
26 | private static final long serialVersionUID = 1L;
27 | /**
28 | * Usually the constant string, "JSONRPCError"
29 | */
30 | private final String name;
31 | /**
32 | * Error code
33 | */
34 | private final int code;
35 | /**
36 | * Error message
37 | */
38 | private final String message;
39 | /**
40 | * Error detail object - may not always be present or meaningful
41 | */
42 | private final Object error;
43 |
44 | public JsonRpcException() {
45 | this.name = null;
46 | this.code = -1;
47 | this.message = null;
48 | this.error = null;
49 | }
50 |
51 | public JsonRpcException(String detailMessage, String name, int code, String message, Object error) {
52 | super(detailMessage);
53 | this.name = name;
54 | this.code = code;
55 | this.message = message;
56 | this.error = error;
57 | }
58 |
59 | public String getName() {
60 | return name;
61 | }
62 |
63 | public int getCode() {
64 | return code;
65 | }
66 |
67 | @Override
68 | public String getMessage() {
69 | return message;
70 | }
71 |
72 | public Object getError() {
73 | return error;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/observation/micrometer/DeliverContext.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007-2025 Broadcom. All Rights Reserved.
2 | // The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
3 | //
4 | // This software, the RabbitMQ Java client library, is triple-licensed under the
5 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
6 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
7 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
8 | // please see LICENSE-APACHE2.
9 | //
10 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
11 | // either express or implied. See the LICENSE file for specific language governing
12 | // rights and limitations of this software.
13 | //
14 | // If you have any questions regarding licensing, please contact us at
15 | // info@rabbitmq.com.
16 | package com.rabbitmq.client.observation.micrometer;
17 |
18 | import io.micrometer.observation.transport.ReceiverContext;
19 | import java.util.Map;
20 |
21 | /**
22 | * {@link io.micrometer.observation.Observation.Context} for use with RabbitMQ client {@link
23 | * io.micrometer.observation.Observation} instrumentation.
24 | *
25 | * @since 5.19.0
26 | */
27 | public class DeliverContext extends ReceiverContextTRACE log level
12 | * is enabled before logging anything. This {@link TrafficListener}
13 | * should only be activated for debugging purposes, not in a production
14 | * environment.
15 | *
16 | * @see TrafficListener
17 | * @see com.rabbitmq.client.ConnectionFactory#setTrafficListener(TrafficListener)
18 | * @since 5.5.0
19 | */
20 | public class LogTrafficListener implements TrafficListener {
21 |
22 | private static final Logger LOGGER = LoggerFactory.getLogger(LogTrafficListener.class);
23 |
24 | @Override
25 | public void write(Command outboundCommand) {
26 | if (shouldLog(outboundCommand)) {
27 | LOGGER.trace("Outbound command: {}", outboundCommand);
28 | }
29 | }
30 |
31 | @Override
32 | public void read(Command inboundCommand) {
33 | if (shouldLog(inboundCommand)) {
34 | LOGGER.trace("Inbound command: {}", inboundCommand);
35 | }
36 | }
37 |
38 | protected boolean shouldLog(Command command) {
39 | return LOGGER.isTraceEnabled();
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/impl/recovery/BackoffPolicy.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018-2023 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 | package com.rabbitmq.client.impl.recovery;
17 |
18 | /**
19 | * Backoff policy for topology recovery retry attempts.
20 | *
21 | * @see DefaultRetryHandler
22 | * @see TopologyRecoveryRetryHandlerBuilder
23 | * @since 5.4.0
24 | */
25 | @FunctionalInterface
26 | public interface BackoffPolicy {
27 |
28 | /**
29 | * Wait depending on the current attempt number (1, 2, 3, etc)
30 | * @param attemptNumber current attempt number
31 | * @throws InterruptedException
32 | */
33 | void backoff(int attemptNumber) throws InterruptedException;
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/observation/micrometer/DeliverObservationConvention.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007-2025 Broadcom. All Rights Reserved.
2 | // The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
3 | //
4 | // This software, the RabbitMQ Java client library, is triple-licensed under the
5 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
6 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
7 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
8 | // please see LICENSE-APACHE2.
9 | //
10 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
11 | // either express or implied. See the LICENSE file for specific language governing
12 | // rights and limitations of this software.
13 | //
14 | // If you have any questions regarding licensing, please contact us at
15 | // info@rabbitmq.com.
16 | package com.rabbitmq.client.observation.micrometer;
17 |
18 | import io.micrometer.observation.Observation;
19 | import io.micrometer.observation.ObservationConvention;
20 |
21 | /**
22 | * {@link ObservationConvention} for RabbitMQ client instrumentation.
23 | *
24 | * @since 5.19.0
25 | */
26 | public interface DeliverObservationConvention extends ObservationConventionObject as the underlying
15 | * object that performs the call might
16 | * not be an implementation of {@link Channel}.
17 | */
18 | private final Object channel;
19 |
20 | /**
21 | * The number of the channel that performed the call.
22 | */
23 | private final int channelNumber;
24 |
25 | /**
26 | * The request method that timed out.
27 | */
28 | private final Method method;
29 |
30 | public ChannelContinuationTimeoutException(TimeoutException cause, Object channel, int channelNumber, Method method) {
31 | super(
32 | "Continuation call for method " + method + " on channel " + channel + " (#" + channelNumber + ") timed out",
33 | cause
34 | );
35 | this.channel = channel;
36 | this.channelNumber = channelNumber;
37 | this.method = method;
38 | }
39 |
40 | /**
41 | *
42 | * @return request method that timed out
43 | */
44 | public Method getMethod() {
45 | return method;
46 | }
47 |
48 | /**
49 | * channel that performed the call
50 | * @return
51 | */
52 | public Object getChannel() {
53 | return channel;
54 | }
55 |
56 | /**
57 | *
58 | * @return number of the channel that performed the call
59 | */
60 | public int getChannelNumber() {
61 | return channelNumber;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/Command.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 |
17 | package com.rabbitmq.client;
18 |
19 | /**
20 | * Interface to a container for an AMQP method-and-arguments, with optional content header and body.
21 | */
22 | public interface Command {
23 | /**
24 | * Retrieves the {@link Method} held within this Command. Downcast to
25 | * concrete (implementation-specific!) subclasses as necessary.
26 | *
27 | * @return the command's method.
28 | */
29 | Method getMethod();
30 |
31 | /**
32 | * Retrieves the ContentHeader subclass instance held as part of this Command, if any.
33 | *
34 | * Downcast to one of the inner classes of AMQP,
35 | * for instance {@link AMQP.BasicProperties}, as appropriate.
36 | *
37 | * @return the Command's {@link ContentHeader}, or null if none
38 | */
39 | ContentHeader getContentHeader();
40 |
41 | /**
42 | * Retrieves the body byte array that travelled as part of this
43 | * Command, if any.
44 | *
45 | * @return the Command's content body, or null if none
46 | */
47 | byte[] getContentBody();
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/Delivery.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017-2023 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 | package com.rabbitmq.client;
17 |
18 | /**
19 | * Encapsulates an arbitrary message - simple "bean" holder structure.
20 | */
21 | public class Delivery {
22 | private final Envelope _envelope;
23 | private final AMQP.BasicProperties _properties;
24 | private final byte[] _body;
25 |
26 | public Delivery(Envelope envelope, AMQP.BasicProperties properties, byte[] body) {
27 | _envelope = envelope;
28 | _properties = properties;
29 | _body = body;
30 | }
31 |
32 | /**
33 | * Retrieve the message envelope.
34 | * @return the message envelope
35 | */
36 | public Envelope getEnvelope() {
37 | return _envelope;
38 | }
39 |
40 | /**
41 | * Retrieve the message properties.
42 | * @return the message properties
43 | */
44 | public AMQP.BasicProperties getProperties() {
45 | return _properties;
46 | }
47 |
48 | /**
49 | * Retrieve the message body.
50 | * @return the message body
51 | */
52 | public byte[] getBody() {
53 | return _body;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/impl/recovery/RetryResult.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2018-2023 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 | package com.rabbitmq.client.impl.recovery;
17 |
18 | /**
19 | * The retry of a retriable topology recovery operation.
20 | *
21 | * @since 5.4.0
22 | */
23 | public class RetryResult {
24 |
25 | /**
26 | * The entity to recover.
27 | */
28 | private final RecordedEntity recordedEntity;
29 |
30 | /**
31 | * The result of the recovery operation.
32 | * E.g. a consumer tag when recovering a consumer.
33 | */
34 | private final Object result;
35 |
36 | public RetryResult(RecordedEntity recordedEntity, Object result) {
37 | this.recordedEntity = recordedEntity;
38 | this.result = result;
39 | }
40 |
41 | /**
42 | * The entity to recover.
43 | *
44 | * @return
45 | */
46 | public RecordedEntity getRecordedEntity() {
47 | return recordedEntity;
48 | }
49 |
50 | /**
51 | * The result of the recovery operation.
52 | * E.g. a consumer tag when recovering a consumer.
53 | */
54 | public Object getResult() {
55 | return result;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | Thank you for using RabbitMQ and for taking the time to report an
2 | issue.
3 |
4 | ## Does This Belong to GitHub or RabbitMQ Mailing List?
5 |
6 | *Important:* please first read the `CONTRIBUTING.md` document in the
7 | root of this repository. It will help you determine whether your
8 | feedback should be directed to the RabbitMQ mailing list [1] instead.
9 |
10 | ## Please Help Maintainers and Contributors Help You
11 |
12 | In order for the RabbitMQ team to investigate your issue, please provide
13 | **as much as possible** of the following details:
14 |
15 | * RabbitMQ version
16 | * Erlang version
17 | * RabbitMQ server and client application log files
18 | * A runnable code sample, terminal transcript or detailed set of
19 | instructions that can be used to reproduce the issue
20 | * RabbitMQ plugin information via `rabbitmq-plugins list`
21 | * Client library version (for all libraries used)
22 | * Operating system, version, and patch level
23 |
24 | Running the `rabbitmq-collect-env` [2] script can provide most of the
25 | information needed. Please make the archive available via a third-party
26 | service and note that **the script does not attempt to scrub any
27 | sensitive data**.
28 |
29 | If your issue involves RabbitMQ management UI or HTTP API, please also provide
30 | the following:
31 |
32 | * Browser and its version
33 | * What management UI page was used (if applicable)
34 | * How the HTTP API requests performed can be reproduced with `curl`
35 | * Operating system on which you are running your browser, and its version
36 | * Errors reported in the JavaScript console (if any)
37 |
38 | This information **greatly speeds up issue investigation** (or makes it
39 | possible to investigate it at all). Please help project maintainers and
40 | contributors to help you by providing it!
41 |
42 | 1. https://groups.google.com/forum/#!forum/rabbitmq-users
43 | 2. https://github.com/rabbitmq/support-tools/blob/master/scripts/rabbitmq-collect-env
44 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/SocketConfigurator.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 | package com.rabbitmq.client;
17 |
18 | import java.io.IOException;
19 | import java.net.Socket;
20 | import java.util.Objects;
21 |
22 | @FunctionalInterface
23 | public interface SocketConfigurator {
24 |
25 | /**
26 | * Provides a hook to insert custom configuration of the sockets
27 | * used to connect to an AMQP server before they connect.
28 | */
29 | void configure(Socket socket) throws IOException;
30 |
31 | /**
32 | * Returns a composed configurator that performs, in sequence, this
33 | * operation followed by the {@code after} operation.
34 | *
35 | * @param after the operation to perform after this operation
36 | * @return a composed configurator that performs in sequence this
37 | * operation followed by the {@code after} operation
38 | * @throws NullPointerException if {@code after} is null
39 | */
40 | default SocketConfigurator andThen(SocketConfigurator after) {
41 | Objects.requireNonNull(after);
42 | return t -> {
43 | configure(t);
44 | after.configure(t);
45 | };
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/test/java/SanityCheck.java:
--------------------------------------------------------------------------------
1 | ///usr/bin/env jbang "$0" "$@" ; exit $?
2 | //DEPS com.rabbitmq:amqp-client:${env.RABBITMQ_LIBRARY_VERSION}
3 | //DEPS org.slf4j:slf4j-simple:1.7.36
4 |
5 | import com.rabbitmq.client.AMQP;
6 | import com.rabbitmq.client.Channel;
7 | import com.rabbitmq.client.Connection;
8 | import com.rabbitmq.client.ConnectionFactory;
9 | import com.rabbitmq.client.DefaultConsumer;
10 | import com.rabbitmq.client.Envelope;
11 | import com.rabbitmq.client.impl.ClientVersion;
12 | import java.util.concurrent.CountDownLatch;
13 | import java.util.concurrent.TimeUnit;
14 | import org.slf4j.Logger;
15 | import org.slf4j.LoggerFactory;
16 |
17 | public class SanityCheck {
18 |
19 | private static final Logger LOGGER = LoggerFactory.getLogger("rabbitmq");
20 |
21 | public static void main(String[] args) {
22 | try (Connection connection = new ConnectionFactory().newConnection()) {
23 | Channel ch = connection.createChannel();
24 | String queue = ch.queueDeclare().getQueue();
25 | CountDownLatch latch = new CountDownLatch(1);
26 | ch.basicConsume(
27 | queue,
28 | true,
29 | new DefaultConsumer(ch) {
30 | @Override
31 | public void handleDelivery(
32 | String consumerTag,
33 | Envelope envelope,
34 | AMQP.BasicProperties properties,
35 | byte[] body) {
36 | latch.countDown();
37 | }
38 | });
39 | ch.basicPublish("", queue, null, "test".getBytes());
40 | boolean received = latch.await(5, TimeUnit.SECONDS);
41 | if (!received) {
42 | throw new IllegalStateException("Didn't receive message in 5 seconds");
43 | }
44 | LOGGER.info("Test succeeded with Java client {}", ClientVersion.VERSION);
45 | System.exit(0);
46 | } catch (Exception e) {
47 | LOGGER.info("Test failed with Java client {}", ClientVersion.VERSION, e);
48 | System.exit(1);
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/AlreadyClosedException.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 |
17 | package com.rabbitmq.client;
18 |
19 | /**
20 | * Thrown when application tries to perform an action on connection/channel
21 | * which was already closed
22 | */
23 | public class AlreadyClosedException extends ShutdownSignalException {
24 | /** Default for suppressing warnings without version check. */
25 | private static final long serialVersionUID = 1L;
26 |
27 | public AlreadyClosedException(ShutdownSignalException sse) {
28 | this(sse, null);
29 | }
30 |
31 | public AlreadyClosedException(ShutdownSignalException sse, Throwable cause) {
32 | super(sse.isHardError(),
33 | sse.isInitiatedByApplication(),
34 | sse.getReason(),
35 | sse.getReference(),
36 | composeMessagePrefix(sse),
37 | ((cause == null) ? sse.getCause() : cause));
38 | }
39 |
40 | private static String composeMessagePrefix(ShutdownSignalException sse) {
41 | String connectionOrChannel = sse.isHardError() ? "connection " : "channel ";
42 | return connectionOrChannel + "is already closed due to ";
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/test/java/com/rabbitmq/client/test/functional/UnbindAutoDeleteExchange.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 | package com.rabbitmq.client.test.functional;
17 |
18 | import static org.junit.jupiter.api.Assertions.fail;
19 |
20 | import java.io.IOException;
21 |
22 | import org.junit.jupiter.api.Test;
23 |
24 | import com.rabbitmq.client.AMQP;
25 | import com.rabbitmq.client.test.BrokerTestCase;
26 |
27 | /**
28 | * Test that unbinding from an auto-delete exchange causes the exchange to go
29 | * away
30 | */
31 | public class UnbindAutoDeleteExchange extends BrokerTestCase {
32 | @Test public void unbind() throws IOException, InterruptedException {
33 | String exchange = "myexchange";
34 | channel.exchangeDeclare(exchange, "fanout", false, true, null);
35 | String queue = channel.queueDeclare().getQueue();
36 | channel.queueBind(queue, exchange, "");
37 | channel.queueUnbind(queue, exchange, "");
38 |
39 | try {
40 | channel.exchangeDeclarePassive(exchange);
41 | fail("exchange should no longer be there");
42 | }
43 | catch (IOException e) {
44 | checkShutdownSignal(AMQP.NOT_FOUND, e);
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## Proposed Changes
2 |
3 | Please describe the big picture of your changes here to communicate to the
4 | RabbitMQ team why we should accept this pull request. If it fixes a bug or
5 | resolves a feature request, be sure to link to that issue.
6 |
7 | A pull request that doesn't explain **why** the change was made has a much
8 | lower chance of being accepted.
9 |
10 | If English isn't your first language, don't worry about it and try to
11 | communicate the problem you are trying to solve to the best of your abilities.
12 | As long as we can understand the intent, it's all good.
13 |
14 | ## Types of Changes
15 |
16 | What types of changes does your code introduce to this project?
17 | _Put an `x` in the boxes that apply_
18 |
19 | - [ ] Bugfix (non-breaking change which fixes issue #NNNN)
20 | - [ ] New feature (non-breaking change which adds functionality)
21 | - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
22 | - [ ] Documentation (correction or otherwise)
23 | - [ ] Cosmetics (whitespace, appearance)
24 |
25 | ## Checklist
26 |
27 | _Put an `x` in the boxes that apply. You can also fill these out after creating
28 | the PR. If you're unsure about any of them, don't hesitate to ask on the
29 | mailing list. We're here to help! This is simply a reminder of what we are
30 | going to look for before merging your code._
31 |
32 | - [ ] I have read the `CONTRIBUTING.md` document
33 | - [ ] I have signed the CA (see https://cla.pivotal.io/sign/rabbitmq)
34 | - [ ] All tests pass locally with my changes
35 | - [ ] I have added tests that prove my fix is effective or that my feature works
36 | - [ ] I have added necessary documentation (if appropriate)
37 | - [ ] Any dependent changes have been merged and published in related repositories
38 |
39 | ## Further Comments
40 |
41 | If this is a relatively large or complex change, kick off the discussion by
42 | explaining why you chose the solution you did and what alternatives you
43 | considered, etc.
44 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/impl/CompletableFutureRpcWrapper.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2017-2023 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 | package com.rabbitmq.client.impl;
17 |
18 | import com.rabbitmq.client.*;
19 | import com.rabbitmq.client.Method;
20 |
21 | import java.util.concurrent.CompletableFuture;
22 |
23 | /**
24 | *
25 | */
26 | public class CompletableFutureRpcWrapper implements RpcWrapper {
27 |
28 | private final com.rabbitmq.client.Method request;
29 |
30 | private final CompletableFuturebasic.deliver is received for this consumer.
37 | * @param consumerTag the consumer tag associated with the consumer
38 | * @param message the delivered message
39 | * @throws IOException if the consumer encounters an I/O error while processing the message
40 | */
41 | void handle(String consumerTag, Delivery message) throws IOException;
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/com/rabbitmq/client/AddressResolver.java:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2007-2025 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
2 | //
3 | // This software, the RabbitMQ Java client library, is triple-licensed under the
4 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
5 | // ("GPL") and the Apache License version 2 ("ASL"). For the MPL, please see
6 | // LICENSE-MPL-RabbitMQ. For the GPL, please see LICENSE-GPL2. For the ASL,
7 | // please see LICENSE-APACHE2.
8 | //
9 | // This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
10 | // either express or implied. See the LICENSE file for specific language governing
11 | // rights and limitations of this software.
12 | //
13 | // If you have any questions regarding licensing, please contact us at
14 | // info@rabbitmq.com.
15 |
16 | package com.rabbitmq.client;
17 |
18 | import java.io.IOException;
19 | import java.util.ArrayList;
20 | import java.util.Collections;
21 | import java.util.List;
22 |
23 | /** Strategy interface to get the potential servers to connect to. */
24 | public interface AddressResolver {
25 |
26 | /**
27 | * Get the potential {@link Address}es to connect to.
28 | *
29 | * @return candidate {@link Address}es
30 | * @throws IOException if it encounters a problem
31 | */
32 | List getAddresses() throws IOException;
33 |
34 | /**
35 | * Optionally shuffle the list of addresses returned by {@link #getAddresses()}.
36 | *
37 | *