-
Notifications
You must be signed in to change notification settings - Fork 628
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AMQP-813: Requeue after retry exhausted option
JIRA: https://jira.spring.io/browse/AMQP-813 * Add `ImmediateRequeueAmqpException` to let `ContainerUtils.shouldRequeue()` to return `true` immediately and requeue the message in the container * Add `ImmediateRequeueMessageRecoverer` to throw a mentioned above `ImmediateRequeueAmqpException` * Refactor `RetryInterceptorBuilder` to avoid duplicated code * Mention changes in the Docs * Mention `ImmediateRequeueAmqpException` in Docs alongside with the `defaultRequeueRejected` Doc Polishing
- Loading branch information
1 parent
88f57fa
commit d75777d
Showing
7 changed files
with
182 additions
and
90 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
spring-amqp/src/main/java/org/springframework/amqp/ImmediateRequeueAmqpException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2018 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.amqp; | ||
|
||
/** | ||
* The special {@link AmqpException} to be thrown from the listener (e.g. retry recoverer callback) | ||
* to {@code requeue) failed message. | ||
* | ||
* @author Artem Bilan | ||
* | ||
* @since 2.1 | ||
*/ | ||
@SuppressWarnings("serial") | ||
public class ImmediateRequeueAmqpException extends AmqpException { | ||
|
||
public ImmediateRequeueAmqpException(String message) { | ||
super(message); | ||
} | ||
|
||
public ImmediateRequeueAmqpException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
public ImmediateRequeueAmqpException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...src/main/java/org/springframework/amqp/rabbit/retry/ImmediateRequeueMessageRecoverer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2018 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.amqp.rabbit.retry; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
import org.springframework.amqp.ImmediateRequeueAmqpException; | ||
import org.springframework.amqp.core.Message; | ||
|
||
/** | ||
* The {@link MessageRecoverer} implementation to throw an {@link ImmediateRequeueAmqpException} | ||
* for subsequent requeuing in the listener container. | ||
* | ||
* @author Artem Bilan | ||
* | ||
* @since 2.1 | ||
*/ | ||
public class ImmediateRequeueMessageRecoverer implements MessageRecoverer { | ||
|
||
protected Log logger = LogFactory.getLog(ImmediateRequeueMessageRecoverer.class); | ||
|
||
@Override | ||
public void recover(Message message, Throwable cause) { | ||
if (this.logger.isWarnEnabled()) { | ||
this.logger.warn("Retries exhausted for message " + message + "; requeuing...", cause); | ||
} | ||
throw new ImmediateRequeueAmqpException(cause); | ||
} | ||
|
||
} |
Oops, something went wrong.