Class RepublishMessageRecoverer
java.lang.Object
org.springframework.amqp.rabbit.retry.RepublishMessageRecoverer
- All Implemented Interfaces:
MessageRecoverer
- Direct Known Subclasses:
RepublishMessageRecovererWithConfirms
MessageRecoverer
implementation that republishes recovered messages
to a specified exchange with the exception stack trace stored in the
message header x-exception.
If no routing key is provided, the original routing key for the message,
prefixed with setErrorRoutingKeyPrefix(String)
(default "error.")
will be used to publish the message to the exchange provided in
name, or the template's default exchange if none is set.
- Since:
- 1.3
- Author:
- James Carr, Gary Russell, Artem Bilan
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
protected final Expression
protected final Expression
protected final AmqpTemplate
protected final EvaluationContext
protected final Log
static final String
static final String
static final String
static final String
-
Constructor Summary
ConstructorDescriptionRepublishMessageRecoverer
(AmqpTemplate errorTemplate) Create an instance with the provided template.RepublishMessageRecoverer
(AmqpTemplate errorTemplate, String errorExchange) Create an instance with the provided properties.RepublishMessageRecoverer
(AmqpTemplate errorTemplate, String errorExchange, String errorRoutingKey) Create an instance with the provided properties.RepublishMessageRecoverer
(AmqpTemplate errorTemplate, Expression errorExchange, Expression errorRoutingKey) Create an instance with the provided properties. -
Method Summary
Modifier and TypeMethodDescriptionadditionalHeaders
(Message message, Throwable cause) Subclasses can override this method to add more headers to the republished message.protected void
Send the message.errorRoutingKeyPrefix
(String errorRoutingKeyPrefix) Apply a prefix to the outbound routing key, which will be prefixed to the original message routing key (if no explicit routing key was provided in the constructor; ignored otherwise.frameMaxHeadroom
(int headroom) Set the amount by which the negotiated frame_max is to be reduced when considering truncating the stack trace header.protected MessageDeliveryMode
protected String
protected String
getStackTraceAsString
(Throwable cause) Create a String representation of the stack trace.protected String
prefixedOriginalRoutingKey
(Message message) The default behavior of this method is to append the received routing key to theroutingKeyPrefix
.void
Callback for message that was consumed but failed all retry attempts.void
setDeliveryMode
(MessageDeliveryMode deliveryMode) Specify aMessageDeliveryMode
to set into the message to republish if the message doesn't have it already.void
setErrorRoutingKeyPrefix
(String errorRoutingKeyPrefix)
-
Field Details
-
X_EXCEPTION_STACKTRACE
- See Also:
-
X_EXCEPTION_MESSAGE
- See Also:
-
X_ORIGINAL_EXCHANGE
- See Also:
-
X_ORIGINAL_ROUTING_KEY
- See Also:
-
DEFAULT_FRAME_MAX_HEADROOM
public static final int DEFAULT_FRAME_MAX_HEADROOM- See Also:
-
logger
-
errorTemplate
-
errorRoutingKeyExpression
-
errorExchangeNameExpression
-
evaluationContext
-
-
Constructor Details
-
RepublishMessageRecoverer
Create an instance with the provided template.- Parameters:
errorTemplate
- the template.
-
RepublishMessageRecoverer
Create an instance with the provided properties.- Parameters:
errorTemplate
- the template.errorExchange
- the exchange.
-
RepublishMessageRecoverer
public RepublishMessageRecoverer(AmqpTemplate errorTemplate, @Nullable String errorExchange, @Nullable String errorRoutingKey) Create an instance with the provided properties. If the exchange or routing key is null, the template's default will be used.- Parameters:
errorTemplate
- the template.errorExchange
- the exchange.errorRoutingKey
- the routing key.
-
RepublishMessageRecoverer
public RepublishMessageRecoverer(AmqpTemplate errorTemplate, @Nullable Expression errorExchange, @Nullable Expression errorRoutingKey) Create an instance with the provided properties. If the exchange or routing key evaluate to null, the template's default will be used.- Parameters:
errorTemplate
- the template.errorExchange
- the exchange expression, evaluated against the message.errorRoutingKey
- the routing key, evaluated against the message.
-
-
Method Details
-
errorRoutingKeyPrefix
Apply a prefix to the outbound routing key, which will be prefixed to the original message routing key (if no explicit routing key was provided in the constructor; ignored otherwise. Use an empty string ("") for no prefixing.- Parameters:
errorRoutingKeyPrefix
- The prefix (default "error.").- Returns:
- this.
-
frameMaxHeadroom
Set the amount by which the negotiated frame_max is to be reduced when considering truncating the stack trace header. Defaults to 20000.- Parameters:
headroom
- the headroom- Returns:
- this.
- Since:
- 2.0.5
-
setErrorRoutingKeyPrefix
- Parameters:
errorRoutingKeyPrefix
- The prefix (default "error.").- See Also:
-
getErrorRoutingKeyPrefix
-
setDeliveryMode
Specify aMessageDeliveryMode
to set into the message to republish if the message doesn't have it already.- Parameters:
deliveryMode
- the delivery mode to set to message.- Since:
- 2.0
-
getDeliveryMode
-
recover
Description copied from interface:MessageRecoverer
Callback for message that was consumed but failed all retry attempts.- Specified by:
recover
in interfaceMessageRecoverer
- Parameters:
message
- the message to recovercause
- the cause of the error
-
doSend
Send the message.- Parameters:
exchange
- the exchange or null to use the template's default.routingKey
- the routing key.message
- the message.- Since:
- 2.3.3
-
additionalHeaders
Subclasses can override this method to add more headers to the republished message.- Parameters:
message
- The failed message.cause
- The cause.- Returns:
- A
Map
of additional headers to add.
-
prefixedOriginalRoutingKey
The default behavior of this method is to append the received routing key to theroutingKeyPrefix
. This is only invoked if the routing key is null.- Parameters:
message
- the message.- Returns:
- the routing key.
-
getStackTraceAsString
Create a String representation of the stack trace.- Parameters:
cause
- the throwable.- Returns:
- the String.
- Since:
- 2.4.8
-