Class RabbitUtils
java.lang.Object
org.springframework.amqp.rabbit.connection.RabbitUtils
- Author:
- Mark Fisher, Mark Pollack, Gary Russell, Artem Bilan
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
AMQP basic class id.static final int
AMQP Channel protocol class id.static final int
AMQP Connection protocol class id.static final int
AMQP consume method.static final int
AMQP declare method.static final int
AMQP exchange class id.static final int
AMQP queue class id. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
static void
Clear the physicalCloseRequired flag.static void
closeChannel
(com.rabbitmq.client.Channel channel) Close the given RabbitMQ Channel and ignore any thrown exception.static void
closeConnection
(Connection connection) Close the given RabbitMQ Connection and ignore any thrown exception.static void
closeMessageConsumer
(com.rabbitmq.client.Channel channel, Collection<String> consumerTags, boolean transactional) static void
commitIfNecessary
(com.rabbitmq.client.Channel channel) Commit the Channel if not within a JTA transaction.static void
declareTransactional
(com.rabbitmq.client.Channel channel) Declare to that broker that a channel is going to be used transactionally, and convert exceptions that arise.static boolean
exclusiveAccesssRefused
(Exception exception) Determine whether the exception is due to an access refused for an exclusive consumer.static int
getMaxFrame
(ConnectionFactory connectionFactory) Return the negotiated frame_max.static boolean
Return true if there is aShutdownSignalException
in the cause tree and its reason is "COMMAND_INVALID" and the operation being performed was exchangeDeclare.static boolean
isExclusiveUseChannelClose
(com.rabbitmq.client.ShutdownSignalException sig) Return true if theShutdownSignalException
reason is AMQP.Channel.Close and the operation that failed was basicConsumer and the failure text contains "exclusive".static boolean
Return true if there is aShutdownSignalException
in the cause tree and its reason is "PRECONDITION_FAILED" and the operation being performed was queueDeclare.static boolean
isNormalChannelClose
(com.rabbitmq.client.ShutdownSignalException sig) Return true if theShutdownSignalException
reason is AMQP.Channel.Close and the reply code was AMQP.REPLY_SUCCESS (200) and the text equals "OK".static boolean
isNormalShutdown
(com.rabbitmq.client.ShutdownSignalException sig) Return true if theShutdownSignalException
reason is AMQP.Connection.Close and the reply code was AMQP.REPLY_SUCCESS (200) and the text equals "OK".static boolean
isPassiveDeclarationChannelClose
(com.rabbitmq.client.ShutdownSignalException sig) Return true if theShutdownSignalException
reason is AMQP.Channel.Close and the operation that failed was exchangeDeclare or queueDeclare.static boolean
Gets and removes a ThreadLocal indicating the channel MUST be physically closed.static void
rollbackIfNecessary
(com.rabbitmq.client.Channel channel) static void
setPhysicalCloseRequired
(com.rabbitmq.client.Channel channel, boolean b) Sets a ThreadLocal indicating the channel MUST be physically closed.static com.rabbitmq.client.SaslConfig
stringToSaslConfig
(String saslConfig, com.rabbitmq.client.ConnectionFactory connectionFactory) Convert a String value to aSaslConfig
.
-
Field Details
-
DECLARE_METHOD_ID_10
public static final int DECLARE_METHOD_ID_10AMQP declare method.- See Also:
-
CONSUME_METHOD_ID_20
public static final int CONSUME_METHOD_ID_20AMQP consume method.- See Also:
-
EXCHANGE_CLASS_ID_40
public static final int EXCHANGE_CLASS_ID_40AMQP exchange class id.- See Also:
-
QUEUE_CLASS_ID_50
public static final int QUEUE_CLASS_ID_50AMQP queue class id.- See Also:
-
BASIC_CLASS_ID_60
public static final int BASIC_CLASS_ID_60AMQP basic class id.- See Also:
-
CONNECTION_PROTOCOL_CLASS_ID_10
public static final int CONNECTION_PROTOCOL_CLASS_ID_10AMQP Connection protocol class id.- See Also:
-
CHANNEL_PROTOCOL_CLASS_ID_20
public static final int CHANNEL_PROTOCOL_CLASS_ID_20AMQP Channel protocol class id.- See Also:
-
-
Constructor Details
-
RabbitUtils
public RabbitUtils()
-
-
Method Details
-
closeConnection
Close the given RabbitMQ Connection and ignore any thrown exception. This is useful for typicalfinally
blocks in manual RabbitMQ code.- Parameters:
connection
- the RabbitMQ Connection to close (may benull
)
-
closeChannel
Close the given RabbitMQ Channel and ignore any thrown exception. This is useful for typicalfinally
blocks in manual RabbitMQ code.- Parameters:
channel
- the RabbitMQ Channel to close (may benull
)
-
commitIfNecessary
public static void commitIfNecessary(com.rabbitmq.client.Channel channel) Commit the Channel if not within a JTA transaction.- Parameters:
channel
- the RabbitMQ Channel to commit
-
rollbackIfNecessary
public static void rollbackIfNecessary(com.rabbitmq.client.Channel channel) -
closeMessageConsumer
public static void closeMessageConsumer(com.rabbitmq.client.Channel channel, Collection<String> consumerTags, boolean transactional) -
cancel
-
declareTransactional
public static void declareTransactional(com.rabbitmq.client.Channel channel) Declare to that broker that a channel is going to be used transactionally, and convert exceptions that arise.- Parameters:
channel
- the channel to use
-
setPhysicalCloseRequired
public static void setPhysicalCloseRequired(com.rabbitmq.client.Channel channel, boolean b) Sets a ThreadLocal indicating the channel MUST be physically closed.- Parameters:
channel
- the channel.b
- true if the channel must be closed (if it's a proxy).
-
isPhysicalCloseRequired
public static boolean isPhysicalCloseRequired()Gets and removes a ThreadLocal indicating the channel MUST be physically closed.- Returns:
- true if the channel must be physically closed
-
clearPhysicalCloseRequired
public static void clearPhysicalCloseRequired()Clear the physicalCloseRequired flag. -
isNormalShutdown
public static boolean isNormalShutdown(com.rabbitmq.client.ShutdownSignalException sig) Return true if theShutdownSignalException
reason is AMQP.Connection.Close and the reply code was AMQP.REPLY_SUCCESS (200) and the text equals "OK".- Parameters:
sig
- the exception.- Returns:
- true for a normal connection close.
-
isNormalChannelClose
public static boolean isNormalChannelClose(com.rabbitmq.client.ShutdownSignalException sig) Return true if theShutdownSignalException
reason is AMQP.Channel.Close and the reply code was AMQP.REPLY_SUCCESS (200) and the text equals "OK".- Parameters:
sig
- the exception.- Returns:
- true for a normal channel close.
-
isPassiveDeclarationChannelClose
public static boolean isPassiveDeclarationChannelClose(com.rabbitmq.client.ShutdownSignalException sig) Return true if theShutdownSignalException
reason is AMQP.Channel.Close and the operation that failed was exchangeDeclare or queueDeclare.- Parameters:
sig
- the exception.- Returns:
- true if the failure meets the conditions.
-
isExclusiveUseChannelClose
public static boolean isExclusiveUseChannelClose(com.rabbitmq.client.ShutdownSignalException sig) Return true if theShutdownSignalException
reason is AMQP.Channel.Close and the operation that failed was basicConsumer and the failure text contains "exclusive".- Parameters:
sig
- the exception.- Returns:
- true if the declaration failed because of an exclusive queue.
-
isMismatchedQueueArgs
Return true if there is aShutdownSignalException
in the cause tree and its reason is "PRECONDITION_FAILED" and the operation being performed was queueDeclare. This can happen if a queue has mismatched properties (auto-delete etc) or arguments (x-message-ttl etc).- Parameters:
e
- the exception.- Returns:
- true if the exception was due to queue declaration precondition failed.
- Since:
- 1.6
-
isExchangeDeclarationFailure
Return true if there is aShutdownSignalException
in the cause tree and its reason is "COMMAND_INVALID" and the operation being performed was exchangeDeclare. For example attempting to declare an exchange that is not supported by the broker or its plugins.- Parameters:
e
- the exception.- Returns:
- true if the exception was due to exchange declaration failed.
- Since:
- 1.6
-
getMaxFrame
Return the negotiated frame_max.- Parameters:
connectionFactory
- the connection factory.- Returns:
- the size or -1 if it cannot be determined.
-
stringToSaslConfig
public static com.rabbitmq.client.SaslConfig stringToSaslConfig(String saslConfig, com.rabbitmq.client.ConnectionFactory connectionFactory) Convert a String value to aSaslConfig
. Valid string values:DefaultSaslConfig.PLAIN
DefaultSaslConfig.EXTERNAL
JDKSaslConfig
CRDemoSaslConfig
- Parameters:
saslConfig
- the string value.connectionFactory
- the connection factory to get the name, pw, host.- Returns:
- the saslConfig.
-
exclusiveAccesssRefused
Determine whether the exception is due to an access refused for an exclusive consumer.- Parameters:
exception
- the exception.- Returns:
- true if access refused.
- Since:
- 3.1
-