Class RabbitUtils
- java.lang.Object
-
- org.springframework.amqp.rabbit.connection.RabbitUtils
-
public abstract class RabbitUtils extends Object
- Author:
- Mark Fisher, Mark Pollack, Gary Russell, Artem Bilan
-
-
Field Summary
Fields Modifier and Type Field Description static intBASIC_CLASS_ID_60AMQP basic class id.static intCHANNEL_PROTOCOL_CLASS_ID_20AMQP Channel protocol class id.static intCONNECTION_PROTOCOL_CLASS_ID_10AMQP Connection protocol class id.static intCONSUME_METHOD_ID_20AMQP consume method.static intDECLARE_METHOD_ID_10AMQP declare method.static intEXCHANGE_CLASS_ID_40AMQP exchange class id.static intQUEUE_CLASS_ID_50AMQP queue class id.
-
Constructor Summary
Constructors Constructor Description RabbitUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcancel(com.rabbitmq.client.Channel channel, String consumerTag)static voidclearPhysicalCloseRequired()Clear the physicalCloseRequired flag.static voidcloseChannel(com.rabbitmq.client.Channel channel)Close the given RabbitMQ Channel and ignore any thrown exception.static voidcloseConnection(Connection connection)Close the given RabbitMQ Connection and ignore any thrown exception.static voidcloseMessageConsumer(com.rabbitmq.client.Channel channel, Collection<String> consumerTags, boolean transactional)static voidcommitIfNecessary(com.rabbitmq.client.Channel channel)Commit the Channel if not within a JTA transaction.static voiddeclareTransactional(com.rabbitmq.client.Channel channel)Declare to that broker that a channel is going to be used transactionally, and convert exceptions that arise.static intgetMaxFrame(ConnectionFactory connectionFactory)Return the negotiated frame_max.static booleanisExchangeDeclarationFailure(Exception e)Return true if there is aShutdownSignalExceptionin the cause tree and its reason is "COMMAND_INVALID" and the operation being performed was exchangeDeclare.static booleanisExclusiveUseChannelClose(com.rabbitmq.client.ShutdownSignalException sig)Return true if theShutdownSignalExceptionreason is AMQP.Channel.Close and the operation that failed was basicConsumer and the failure text contains "exclusive".static booleanisMismatchedQueueArgs(Exception e)Return true if there is aShutdownSignalExceptionin the cause tree and its reason is "PRECONDITION_FAILED" and the operation being performed was queueDeclare.static booleanisNormalChannelClose(com.rabbitmq.client.ShutdownSignalException sig)Return true if theShutdownSignalExceptionreason is AMQP.Channel.Close and the reply code was AMQP.REPLY_SUCCESS (200) and the text equals "OK".static booleanisNormalShutdown(com.rabbitmq.client.ShutdownSignalException sig)Return true if theShutdownSignalExceptionreason is AMQP.Connection.Close and the reply code was AMQP.REPLY_SUCCESS (200) and the text equals "OK".static booleanisPassiveDeclarationChannelClose(com.rabbitmq.client.ShutdownSignalException sig)Return true if theShutdownSignalExceptionreason is AMQP.Channel.Close and the operation that failed was exchangeDeclare or queueDeclare.static booleanisPhysicalCloseRequired()Gets and removes a ThreadLocal indicating the channel MUST be physically closed.static voidrollbackIfNecessary(com.rabbitmq.client.Channel channel)static voidsetPhysicalCloseRequired(com.rabbitmq.client.Channel channel, boolean b)Sets a ThreadLocal indicating the channel MUST be physically closed.static com.rabbitmq.client.SaslConfigstringToSaslConfig(String saslConfig, com.rabbitmq.client.ConnectionFactory connectionFactory)Convert a String value to aSaslConfig.
-
-
-
Field Detail
-
DECLARE_METHOD_ID_10
public static final int DECLARE_METHOD_ID_10
AMQP declare method.- See Also:
- Constant Field Values
-
CONSUME_METHOD_ID_20
public static final int CONSUME_METHOD_ID_20
AMQP consume method.- See Also:
- Constant Field Values
-
EXCHANGE_CLASS_ID_40
public static final int EXCHANGE_CLASS_ID_40
AMQP exchange class id.- See Also:
- Constant Field Values
-
QUEUE_CLASS_ID_50
public static final int QUEUE_CLASS_ID_50
AMQP queue class id.- See Also:
- Constant Field Values
-
BASIC_CLASS_ID_60
public static final int BASIC_CLASS_ID_60
AMQP basic class id.- See Also:
- Constant Field Values
-
CONNECTION_PROTOCOL_CLASS_ID_10
public static final int CONNECTION_PROTOCOL_CLASS_ID_10
AMQP Connection protocol class id.- See Also:
- Constant Field Values
-
CHANNEL_PROTOCOL_CLASS_ID_20
public static final int CHANNEL_PROTOCOL_CLASS_ID_20
AMQP Channel protocol class id.- See Also:
- Constant Field Values
-
-
Method Detail
-
closeConnection
public static void closeConnection(@Nullable Connection connection)
Close the given RabbitMQ Connection and ignore any thrown exception. This is useful for typicalfinallyblocks in manual RabbitMQ code.- Parameters:
connection- the RabbitMQ Connection to close (may benull)
-
closeChannel
public static void closeChannel(@Nullable com.rabbitmq.client.Channel channel)
Close the given RabbitMQ Channel and ignore any thrown exception. This is useful for typicalfinallyblocks 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
public static void cancel(com.rabbitmq.client.Channel channel, String consumerTag)
-
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 theShutdownSignalExceptionreason 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 theShutdownSignalExceptionreason 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 theShutdownSignalExceptionreason 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 theShutdownSignalExceptionreason 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
public static boolean isMismatchedQueueArgs(Exception e)
Return true if there is aShutdownSignalExceptionin 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
public static boolean isExchangeDeclarationFailure(Exception e)
Return true if there is aShutdownSignalExceptionin 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
public static int getMaxFrame(ConnectionFactory connectionFactory)
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.PLAINDefaultSaslConfig.EXTERNALJDKSaslConfigCRDemoSaslConfig
- Parameters:
saslConfig- the string value.connectionFactory- the connection factory to get the name, pw, host.- Returns:
- the saslConfig.
-
-