Search in sources :

Example 1 with RedeliveryPolicy

use of org.apache.camel.processor.RedeliveryPolicy in project camel by apache.

the class XmlErrorHandlerFactoryBean method setProperties.

private void setProperties(DefaultErrorHandlerBuilder builder) throws Exception {
    if (nonNull(handler.getDeadLetterHandleNewException())) {
        builder.setDeadLetterHandleNewException(handler.getDeadLetterHandleNewException());
    }
    builder.setDeadLetterUri(handler.getDeadLetterUri());
    builder.setExecutorServiceRef(handler.getExecutorServiceRef());
    builder.setRetryWhileRef(handler.getRetryWhileRef());
    if (nonNull(handler.getUseOriginalMessage())) {
        builder.setUseOriginalMessage(handler.getUseOriginalMessage());
    }
    if (isNotEmpty(handler.getOnExceptionOccurredRef())) {
        Processor processor = getReferenceByName(manager, handler.getOnExceptionOccurredRef(), Processor.class).orElseThrow(() -> new UnsatisfiedResolutionException(format("No bean with name [%s] to satisfy attribute [%s]", handler.getOnPrepareFailureRef(), "onExceptionOccurredRef")));
        builder.setOnExceptionOccurred(processor);
    }
    if (isNotEmpty(handler.getOnPrepareFailureRef())) {
        Processor processor = getReferenceByName(manager, handler.getOnPrepareFailureRef(), Processor.class).orElseThrow(() -> new UnsatisfiedResolutionException(format("No bean with name [%s] to satisfy attribute [%s]", handler.getOnPrepareFailureRef(), "onPrepareFailureRef")));
        builder.setOnPrepareFailure(processor);
    }
    if (isNotEmpty(handler.getOnRedeliveryRef())) {
        Processor processor = getReferenceByName(manager, handler.getOnRedeliveryRef(), Processor.class).orElseThrow(() -> new UnsatisfiedResolutionException(format("No bean with name [%s] to satisfy attribute [%s]", handler.getOnPrepareFailureRef(), "onRedeliveryRef")));
        builder.setOnRedelivery(processor);
    }
    if (nonNull(handler.getRedeliveryPolicy())) {
        RedeliveryPolicyFactoryBean policy = handler.getRedeliveryPolicy();
        policy.setBeanManager(manager);
        builder.setRedeliveryPolicy(policy.getObject());
    }
    if (isNotEmpty(handler.getRedeliveryPolicyRef())) {
        RedeliveryPolicy policy = getReferenceByName(manager, handler.getRedeliveryPolicyRef(), RedeliveryPolicy.class).orElseThrow(() -> new UnsatisfiedResolutionException(format("No bean with name [%s] to satisfy attribute [%s]", handler.getRedeliveryPolicyRef(), "redeliveryPolicyRef")));
        builder.setRedeliveryPolicy(policy);
    }
}
Also used : Processor(org.apache.camel.Processor) RedeliveryPolicyFactoryBean(org.apache.camel.cdi.xml.RedeliveryPolicyFactoryBean) RedeliveryPolicy(org.apache.camel.processor.RedeliveryPolicy) UnsatisfiedResolutionException(javax.enterprise.inject.UnsatisfiedResolutionException)

Example 2 with RedeliveryPolicy

use of org.apache.camel.processor.RedeliveryPolicy in project camel by apache.

the class AbstractCamelRedeliveryPolicyFactoryBean method getObject.

public RedeliveryPolicy getObject() throws Exception {
    RedeliveryPolicy answer = new RedeliveryPolicy();
    CamelContext context = getCamelContext();
    // copy across the properties - if they are set
    if (maximumRedeliveries != null) {
        answer.setMaximumRedeliveries(CamelContextHelper.parseInteger(context, maximumRedeliveries));
    }
    if (redeliveryDelay != null) {
        answer.setRedeliveryDelay(CamelContextHelper.parseLong(context, redeliveryDelay));
    }
    if (asyncDelayedRedelivery != null) {
        if (CamelContextHelper.parseBoolean(context, asyncDelayedRedelivery)) {
            answer.asyncDelayedRedelivery();
        }
    }
    if (retriesExhaustedLogLevel != null) {
        answer.setRetriesExhaustedLogLevel(retriesExhaustedLogLevel);
    }
    if (retryAttemptedLogLevel != null) {
        answer.setRetryAttemptedLogLevel(retryAttemptedLogLevel);
    }
    if (backOffMultiplier != null) {
        answer.setBackOffMultiplier(CamelContextHelper.parseDouble(context, backOffMultiplier));
    }
    if (useExponentialBackOff != null) {
        answer.setUseExponentialBackOff(CamelContextHelper.parseBoolean(context, useExponentialBackOff));
    }
    if (collisionAvoidanceFactor != null) {
        answer.setCollisionAvoidanceFactor(CamelContextHelper.parseDouble(context, collisionAvoidanceFactor));
    }
    if (useCollisionAvoidance != null) {
        answer.setUseCollisionAvoidance(CamelContextHelper.parseBoolean(context, useCollisionAvoidance));
    }
    if (maximumRedeliveryDelay != null) {
        answer.setMaximumRedeliveryDelay(CamelContextHelper.parseLong(context, maximumRedeliveryDelay));
    }
    if (logStackTrace != null) {
        answer.setLogStackTrace(CamelContextHelper.parseBoolean(context, logStackTrace));
    }
    if (logRetryStackTrace != null) {
        answer.setLogRetryStackTrace(CamelContextHelper.parseBoolean(context, logRetryStackTrace));
    }
    if (logHandled != null) {
        answer.setLogHandled(CamelContextHelper.parseBoolean(context, logHandled));
    }
    if (logContinued != null) {
        answer.setLogContinued(CamelContextHelper.parseBoolean(context, logContinued));
    }
    if (logRetryAttempted != null) {
        answer.setLogRetryAttempted(CamelContextHelper.parseBoolean(context, logRetryAttempted));
    }
    if (logExhausted != null) {
        answer.setLogExhausted(CamelContextHelper.parseBoolean(context, logExhausted));
    }
    if (logExhaustedMessageHistory != null) {
        answer.setLogExhaustedMessageHistory(CamelContextHelper.parseBoolean(context, logExhaustedMessageHistory));
    }
    if (disableRedelivery != null) {
        if (CamelContextHelper.parseBoolean(context, disableRedelivery)) {
            answer.setMaximumRedeliveries(0);
        }
    }
    if (delayPattern != null) {
        answer.setDelayPattern(CamelContextHelper.parseText(context, delayPattern));
    }
    if (allowRedeliveryWhileStopping != null) {
        answer.setAllowRedeliveryWhileStopping(CamelContextHelper.parseBoolean(context, allowRedeliveryWhileStopping));
    }
    if (exchangeFormatterRef != null) {
        answer.setExchangeFormatterRef(exchangeFormatterRef);
    }
    return answer;
}
Also used : CamelContext(org.apache.camel.CamelContext) RedeliveryPolicy(org.apache.camel.processor.RedeliveryPolicy)

Example 3 with RedeliveryPolicy

use of org.apache.camel.processor.RedeliveryPolicy in project camel by apache.

the class ContextErrorHandlerTest method setUp.

protected void setUp() throws Exception {
    setUseRouteBuilder(false);
    super.setUp();
    RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
    redeliveryPolicy.maximumRedeliveries(1);
    redeliveryPolicy.setUseExponentialBackOff(true);
    DeadLetterChannelBuilder deadLetterChannelBuilder = new DeadLetterChannelBuilder("mock:error");
    deadLetterChannelBuilder.setRedeliveryPolicy(redeliveryPolicy);
    context.setErrorHandlerBuilder(deadLetterChannelBuilder);
}
Also used : RedeliveryPolicy(org.apache.camel.processor.RedeliveryPolicy)

Example 4 with RedeliveryPolicy

use of org.apache.camel.processor.RedeliveryPolicy in project camel by apache.

the class ContextErrorHandlerTest method testGetTheDefaultErrorHandlerFromContext.

public void testGetTheDefaultErrorHandlerFromContext() throws Exception {
    RouteBuilder builder = new RouteBuilder() {

        public void configure() {
            from("seda:a").to("seda:b");
            from("direct:c").to("direct:d");
        }
    };
    List<Route> list = getRouteListWithCurrentContext(builder);
    assertEquals("Number routes created" + list, 2, list.size());
    for (Route route : list) {
        EventDrivenConsumerRoute consumerRoute = assertIsInstanceOf(EventDrivenConsumerRoute.class, route);
        Processor processor = consumerRoute.getProcessor();
        Channel channel = unwrapChannel(processor);
        DeadLetterChannel deadLetterChannel = assertIsInstanceOf(DeadLetterChannel.class, channel.getErrorHandler());
        RedeliveryPolicy redeliveryPolicy = deadLetterChannel.getRedeliveryPolicy();
        assertEquals("getMaximumRedeliveries()", 1, redeliveryPolicy.getMaximumRedeliveries());
        assertEquals("isUseExponentialBackOff()", true, redeliveryPolicy.isUseExponentialBackOff());
    }
}
Also used : Processor(org.apache.camel.Processor) SendProcessor(org.apache.camel.processor.SendProcessor) DeadLetterChannel(org.apache.camel.processor.DeadLetterChannel) Channel(org.apache.camel.Channel) DeadLetterChannel(org.apache.camel.processor.DeadLetterChannel) RedeliveryPolicy(org.apache.camel.processor.RedeliveryPolicy) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute) Route(org.apache.camel.Route) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute)

Example 5 with RedeliveryPolicy

use of org.apache.camel.processor.RedeliveryPolicy in project camel by apache.

the class ErrorHandlerDefinitionParserTest method testDefaultErrorHandler.

public void testDefaultErrorHandler() {
    DefaultErrorHandlerBuilder errorHandler = ctx.getBean("defaultErrorHandler", DefaultErrorHandlerBuilder.class);
    assertNotNull(errorHandler);
    RedeliveryPolicy policy = errorHandler.getRedeliveryPolicy();
    assertNotNull(policy);
    assertEquals("Wrong maximumRedeliveries", 2, policy.getMaximumRedeliveries());
    assertEquals("Wrong redeliveryDelay", 0, policy.getRedeliveryDelay());
    assertEquals("Wrong logStackTrace", false, policy.isLogStackTrace());
    errorHandler = ctx.getBean("errorHandler", DefaultErrorHandlerBuilder.class);
    assertNotNull(errorHandler);
}
Also used : DefaultErrorHandlerBuilder(org.apache.camel.builder.DefaultErrorHandlerBuilder) RedeliveryPolicy(org.apache.camel.processor.RedeliveryPolicy)

Aggregations

RedeliveryPolicy (org.apache.camel.processor.RedeliveryPolicy)10 Channel (org.apache.camel.Channel)3 Processor (org.apache.camel.Processor)3 Route (org.apache.camel.Route)3 EventDrivenConsumerRoute (org.apache.camel.impl.EventDrivenConsumerRoute)3 DeadLetterChannel (org.apache.camel.processor.DeadLetterChannel)3 SendProcessor (org.apache.camel.processor.SendProcessor)2 UnsatisfiedResolutionException (javax.enterprise.inject.UnsatisfiedResolutionException)1 CamelContext (org.apache.camel.CamelContext)1 Endpoint (org.apache.camel.Endpoint)1 DeadLetterChannelBuilder (org.apache.camel.builder.DeadLetterChannelBuilder)1 DefaultErrorHandlerBuilder (org.apache.camel.builder.DefaultErrorHandlerBuilder)1 RedeliveryPolicyFactoryBean (org.apache.camel.cdi.xml.RedeliveryPolicyFactoryBean)1 FilterProcessor (org.apache.camel.processor.FilterProcessor)1 LoggingErrorHandler (org.apache.camel.processor.LoggingErrorHandler)1 SpringCamelContext (org.apache.camel.spring.SpringCamelContext)1 CamelLogger (org.apache.camel.util.CamelLogger)1