public class RepublishMessageRecoverer extends Object implements MessageRecoverer
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.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_FRAME_MAX_HEADROOM |
protected String |
errorExchangeName |
protected String |
errorRoutingKey |
protected AmqpTemplate |
errorTemplate |
protected Log |
logger |
static String |
X_EXCEPTION_MESSAGE |
static String |
X_EXCEPTION_STACKTRACE |
static String |
X_ORIGINAL_EXCHANGE |
static String |
X_ORIGINAL_ROUTING_KEY |
Constructor and Description |
---|
RepublishMessageRecoverer(AmqpTemplate errorTemplate) |
RepublishMessageRecoverer(AmqpTemplate errorTemplate,
String errorExchange) |
RepublishMessageRecoverer(AmqpTemplate errorTemplate,
String errorExchange,
String errorRoutingKey) |
Modifier and Type | Method and Description |
---|---|
protected Map<? extends String,? extends Object> |
additionalHeaders(Message message,
Throwable cause)
Subclasses can override this method to add more headers to the republished message.
|
RepublishMessageRecoverer |
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.
|
RepublishMessageRecoverer |
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 |
getDeliveryMode() |
protected String |
getErrorRoutingKeyPrefix() |
void |
recover(Message message,
Throwable cause)
Callback for message that was consumed but failed all retry attempts.
|
void |
setDeliveryMode(MessageDeliveryMode deliveryMode)
Specify a
MessageDeliveryMode to set into the message to republish
if the message doesn't have it already. |
void |
setErrorRoutingKeyPrefix(String errorRoutingKeyPrefix) |
public static final String X_EXCEPTION_STACKTRACE
public static final String X_EXCEPTION_MESSAGE
public static final String X_ORIGINAL_EXCHANGE
public static final String X_ORIGINAL_ROUTING_KEY
public static final int DEFAULT_FRAME_MAX_HEADROOM
protected final Log logger
protected final AmqpTemplate errorTemplate
protected final String errorRoutingKey
protected final String errorExchangeName
public RepublishMessageRecoverer(AmqpTemplate errorTemplate)
public RepublishMessageRecoverer(AmqpTemplate errorTemplate, String errorExchange)
public RepublishMessageRecoverer(AmqpTemplate errorTemplate, String errorExchange, String errorRoutingKey)
public RepublishMessageRecoverer errorRoutingKeyPrefix(String errorRoutingKeyPrefix)
errorRoutingKeyPrefix
- The prefix (default "error.").public RepublishMessageRecoverer frameMaxHeadroom(int headroom)
headroom
- the headroompublic void setErrorRoutingKeyPrefix(String errorRoutingKeyPrefix)
errorRoutingKeyPrefix
- The prefix (default "error.").errorRoutingKeyPrefix(String)
protected String getErrorRoutingKeyPrefix()
public void setDeliveryMode(MessageDeliveryMode deliveryMode)
MessageDeliveryMode
to set into the message to republish
if the message doesn't have it already.deliveryMode
- the delivery mode to set to message.protected MessageDeliveryMode getDeliveryMode()
public void recover(Message message, Throwable cause)
MessageRecoverer
recover
in interface MessageRecoverer
message
- the message to recovercause
- the cause of the errorprotected Map<? extends String,? extends Object> additionalHeaders(Message message, Throwable cause)
message
- The failed message.cause
- The cause.Map
of additional headers to add.