public abstract class RabbitUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_PORT |
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,
java.util.Collection<java.lang.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 |
isExchangeDeclarationFailure(java.lang.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(java.lang.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(boolean b)
Deprecated.
use
setPhysicalCloseRequired(Channel, boolean) ; the
ThreadLocal must only be set if the channel is a proxy. |
static void |
setPhysicalCloseRequired(com.rabbitmq.client.Channel channel,
boolean b)
Sets a ThreadLocal indicating the channel MUST be physically closed.
|
static boolean |
shouldRequeue(boolean defaultRequeueRejected,
java.lang.Throwable throwable,
org.apache.commons.logging.Log logger)
Determine whether a message should be requeued; returns true if the throwable is a
MessageRejectedWhileStoppingException or defaultRequeueRejected is true and
there is not an AmqpRejectAndDontRequeueException in the cause chain. |
public static final int DEFAULT_PORT
public static void closeConnection(Connection connection)
finally
blocks in manual RabbitMQ code.connection
- the RabbitMQ Connection to close (may be null
)public static void closeChannel(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, java.util.Collection<java.lang.String> consumerTags, boolean transactional)
public static void declareTransactional(com.rabbitmq.client.Channel channel)
channel
- the channel to use@Deprecated public static void setPhysicalCloseRequired(boolean b)
setPhysicalCloseRequired(Channel, boolean)
; the
ThreadLocal must only be set if the channel is a proxy.b
- true if the channel must be closed.public 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(java.lang.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(java.lang.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 boolean shouldRequeue(boolean defaultRequeueRejected, java.lang.Throwable throwable, org.apache.commons.logging.Log logger)
MessageRejectedWhileStoppingException
or defaultRequeueRejected is true and
there is not an AmqpRejectAndDontRequeueException
in the cause chain.defaultRequeueRejected
- the default requeue rejected.throwable
- the throwable.logger
- the logger to use for debug.