public abstract class RabbitUtils extends Object
Modifier and Type | Field and Description |
---|---|
static int |
BASIC_CLASS_ID_60
AMQP basic class id.
|
static int |
CHANNEL_PROTOCOL_CLASS_ID_20
AMQP Channel protocol class id.
|
static int |
CONNECTION_PROTOCOL_CLASS_ID_10
AMQP Connection protocol class id.
|
static int |
CONSUME_METHOD_ID_20
AMQP consume method.
|
static int |
DECLARE_METHOD_ID_10
AMQP declare method.
|
static int |
EXCHANGE_CLASS_ID_40
AMQP exchange class id.
|
static int |
QUEUE_CLASS_ID_50
AMQP queue class id.
|
Constructor and Description |
---|
RabbitUtils() |
Modifier and Type | Method and Description |
---|---|
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 int |
getMaxFrame(ConnectionFactory connectionFactory)
Return the negotiated frame_max.
|
static boolean |
isExchangeDeclarationFailure(Exception e)
Return true if there is a
ShutdownSignalException 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 the
ShutdownSignalException reason is AMQP.Channel.Close
and the operation that failed was basicConsumer and the failure text contains
"exclusive". |
static boolean |
isMismatchedQueueArgs(Exception e)
Return true if there is a
ShutdownSignalException 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 the
ShutdownSignalException 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 the
ShutdownSignalException 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 the
ShutdownSignalException reason is AMQP.Channel.Close
and the operation that failed was exchangeDeclare or queueDeclare. |
static boolean |
isPhysicalCloseRequired()
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 a
SaslConfig . |
public static final int DECLARE_METHOD_ID_10
public static final int CONSUME_METHOD_ID_20
public static final int EXCHANGE_CLASS_ID_40
public static final int QUEUE_CLASS_ID_50
public static final int BASIC_CLASS_ID_60
public static final int CONNECTION_PROTOCOL_CLASS_ID_10
public static final int CHANNEL_PROTOCOL_CLASS_ID_20
public static void closeConnection(@Nullable Connection connection)
finally
blocks in manual RabbitMQ code.connection
- the RabbitMQ Connection to close (may be null
)public static void closeChannel(@Nullable com.rabbitmq.client.Channel channel)
finally
blocks in manual RabbitMQ code.channel
- the RabbitMQ Channel to close (may be null
)public static void commitIfNecessary(com.rabbitmq.client.Channel channel)
channel
- the RabbitMQ Channel to commitpublic static void rollbackIfNecessary(com.rabbitmq.client.Channel channel)
public static void closeMessageConsumer(com.rabbitmq.client.Channel channel, Collection<String> consumerTags, boolean transactional)
public static void declareTransactional(com.rabbitmq.client.Channel channel)
channel
- the channel to usepublic static void setPhysicalCloseRequired(com.rabbitmq.client.Channel channel, boolean b)
channel
- the channel.b
- true if the channel must be closed (if it's a proxy).public static boolean isPhysicalCloseRequired()
public static boolean isNormalShutdown(com.rabbitmq.client.ShutdownSignalException sig)
ShutdownSignalException
reason is AMQP.Connection.Close and
the reply code was AMQP.REPLY_SUCCESS (200) and the text equals "OK".sig
- the exception.public static boolean isNormalChannelClose(com.rabbitmq.client.ShutdownSignalException sig)
ShutdownSignalException
reason is AMQP.Channel.Close and
the reply code was AMQP.REPLY_SUCCESS (200) and the text equals "OK".sig
- the exception.public static boolean isPassiveDeclarationChannelClose(com.rabbitmq.client.ShutdownSignalException sig)
ShutdownSignalException
reason is AMQP.Channel.Close
and the operation that failed was exchangeDeclare or queueDeclare.sig
- the exception.public static boolean isExclusiveUseChannelClose(com.rabbitmq.client.ShutdownSignalException sig)
ShutdownSignalException
reason is AMQP.Channel.Close
and the operation that failed was basicConsumer and the failure text contains
"exclusive".sig
- the exception.public static boolean isMismatchedQueueArgs(Exception e)
ShutdownSignalException
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).e
- the exception.public static boolean isExchangeDeclarationFailure(Exception e)
ShutdownSignalException
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.e
- the exception.public static int getMaxFrame(ConnectionFactory connectionFactory)
connectionFactory
- the connection factory.public static com.rabbitmq.client.SaslConfig stringToSaslConfig(String saslConfig, com.rabbitmq.client.ConnectionFactory connectionFactory)
SaslConfig
.
Valid string values:
DefaultSaslConfig.PLAIN
DefaultSaslConfig.EXTERNAL
JDKSaslConfig
CRDemoSaslConfig
saslConfig
- the string value.connectionFactory
- the connection factory to get the name, pw, host.