Class RepublishMessageRecoverer

  • All Implemented Interfaces:
    MessageRecoverer
    Direct Known Subclasses:
    RepublishMessageRecovererWithConfirms

    public class RepublishMessageRecoverer
    extends java.lang.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.

    Since:
    1.3
    • Constructor Summary

      Constructors 
      Constructor Description
      RepublishMessageRecoverer​(org.springframework.amqp.core.AmqpTemplate errorTemplate)  
      RepublishMessageRecoverer​(org.springframework.amqp.core.AmqpTemplate errorTemplate, java.lang.String errorExchange)  
      RepublishMessageRecoverer​(org.springframework.amqp.core.AmqpTemplate errorTemplate, java.lang.String errorExchange, java.lang.String errorRoutingKey)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.util.Map<? extends java.lang.String,​?> additionalHeaders​(org.springframework.amqp.core.Message message, java.lang.Throwable cause)
      Subclasses can override this method to add more headers to the republished message.
      protected void doSend​(java.lang.String exchange, java.lang.String routingKey, org.springframework.amqp.core.Message message)
      Send the message.
      RepublishMessageRecoverer errorRoutingKeyPrefix​(java.lang.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 org.springframework.amqp.core.MessageDeliveryMode getDeliveryMode()  
      protected java.lang.String getErrorRoutingKeyPrefix()  
      void recover​(org.springframework.amqp.core.Message message, java.lang.Throwable cause)
      Callback for message that was consumed but failed all retry attempts.
      void setDeliveryMode​(org.springframework.amqp.core.MessageDeliveryMode deliveryMode)
      Specify a MessageDeliveryMode to set into the message to republish if the message doesn't have it already.
      void setErrorRoutingKeyPrefix​(java.lang.String errorRoutingKeyPrefix)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • X_EXCEPTION_STACKTRACE

        public static final java.lang.String X_EXCEPTION_STACKTRACE
        See Also:
        Constant Field Values
      • X_EXCEPTION_MESSAGE

        public static final java.lang.String X_EXCEPTION_MESSAGE
        See Also:
        Constant Field Values
      • X_ORIGINAL_EXCHANGE

        public static final java.lang.String X_ORIGINAL_EXCHANGE
        See Also:
        Constant Field Values
      • X_ORIGINAL_ROUTING_KEY

        public static final java.lang.String X_ORIGINAL_ROUTING_KEY
        See Also:
        Constant Field Values
      • DEFAULT_FRAME_MAX_HEADROOM

        public static final int DEFAULT_FRAME_MAX_HEADROOM
        See Also:
        Constant Field Values
      • logger

        protected final org.apache.commons.logging.Log logger
      • errorTemplate

        protected final org.springframework.amqp.core.AmqpTemplate errorTemplate
      • errorRoutingKey

        protected final java.lang.String errorRoutingKey
      • errorExchangeName

        protected final java.lang.String errorExchangeName
    • Constructor Detail

      • RepublishMessageRecoverer

        public RepublishMessageRecoverer​(org.springframework.amqp.core.AmqpTemplate errorTemplate)
      • RepublishMessageRecoverer

        public RepublishMessageRecoverer​(org.springframework.amqp.core.AmqpTemplate errorTemplate,
                                         java.lang.String errorExchange)
      • RepublishMessageRecoverer

        public RepublishMessageRecoverer​(org.springframework.amqp.core.AmqpTemplate errorTemplate,
                                         java.lang.String errorExchange,
                                         java.lang.String errorRoutingKey)
    • Method Detail

      • errorRoutingKeyPrefix

        public RepublishMessageRecoverer errorRoutingKeyPrefix​(java.lang.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. Use an empty string ("") for no prefixing.
        Parameters:
        errorRoutingKeyPrefix - The prefix (default "error.").
        Returns:
        this.
      • frameMaxHeadroom

        public RepublishMessageRecoverer frameMaxHeadroom​(int headroom)
        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

        public void setErrorRoutingKeyPrefix​(java.lang.String errorRoutingKeyPrefix)
        Parameters:
        errorRoutingKeyPrefix - The prefix (default "error.").
        See Also:
        errorRoutingKeyPrefix(String)
      • getErrorRoutingKeyPrefix

        protected java.lang.String getErrorRoutingKeyPrefix()
      • setDeliveryMode

        public void setDeliveryMode​(org.springframework.amqp.core.MessageDeliveryMode deliveryMode)
        Specify a MessageDeliveryMode 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

        protected org.springframework.amqp.core.MessageDeliveryMode getDeliveryMode()
      • recover

        public void recover​(org.springframework.amqp.core.Message message,
                            java.lang.Throwable cause)
        Description copied from interface: MessageRecoverer
        Callback for message that was consumed but failed all retry attempts.
        Specified by:
        recover in interface MessageRecoverer
        Parameters:
        message - the message to recover
        cause - the cause of the error
      • doSend

        protected void doSend​(@Nullable
                              java.lang.String exchange,
                              java.lang.String routingKey,
                              org.springframework.amqp.core.Message message)
        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

        protected java.util.Map<? extends java.lang.String,​?> additionalHeaders​(org.springframework.amqp.core.Message message,
                                                                                      java.lang.Throwable cause)
        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.