[
https://issues.apache.org/activemq/browse/CAMEL-1129?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=47801#action_47801
]
Willem Jiang commented on CAMEL-1129:
-------------------------------------
DeadLetterChannel need to process the sync processor and the async processor.
Since we can't make the sync processor give up it's calling thread for the
exchange message processing,
my patch just put the async processor's redelivery call into a timer thread.
Here is the async processor's example code
{code}
protected RouteBuilder createRouteBuilder() {
final Processor processor = new AsyncProcessor() {
public void process(Exchange exchange) {
Integer counter =
exchange.getIn().getHeader(DeadLetterChannel.REDELIVERY_COUNTER,
Integer.class);
int attempt = (counter == null) ? 1 : counter + 1;
if (attempt < failUntilAttempt) {
throw new RuntimeException("Failed to process due to
attempt: " + attempt
+ " being less than: " +
failUntilAttempt);
}
}
// START SNIPPET: AsyncProcessor
public boolean process(Exchange exchange, AsyncCallback callback) {
Integer counter =
exchange.getIn().getHeader(DeadLetterChannel.REDELIVERY_COUNTER,
Integer.class);
int attempt = (counter == null) ? 1 : counter + 1;
if (attempt > 1) {
assertEquals("Now we should use TimerThread to call the
process", Thread.currentThread().getName(), "Timer-0");
}
if (attempt < failUntilAttempt) {
// we can't throw the exception here , or the callback will
not be invoked.
exchange.setException(new RuntimeException("Failed to
process due to attempt: " + attempt
+ " being less than: " +
failUntilAttempt));
}
callback.done(false);
return false;
}
// END SNIPPET: AsyncProcessor
};
return new RouteBuilder() {
public void configure() {
from("direct:start").errorHandler(
deadLetterChannel("mock:failed").maximumRedeliveries(2)
.delay(1000)
.loggingLevel(LoggingLevel.DEBUG)
).process(processor).to("mock:success");
}
};
}
{code}
> Enhance ErrorHandler RedeliveryPolicy with a Timer manager to avoid locking
> current thread while sleeping
> ---------------------------------------------------------------------------------------------------------
>
> Key: CAMEL-1129
> URL: https://issues.apache.org/activemq/browse/CAMEL-1129
> Project: Apache Camel
> Issue Type: Improvement
> Components: camel-core
> Affects Versions: 1.5.0
> Reporter: Ron Gavlin
> Assignee: Willem Jiang
>
> The ErrorHandler RedeliveryPolicy appears to lock threads while sleeping
> until the next redelivery. With lots of concurrent requests requiring
> increasing redelivery times, this can be a scalability problem.
> The RedeliveryPolicy should support the use of a timer thread that would be
> responsible for managing the "timeouts" and firing the redelivery.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.