camel-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sergey Zhemzhitsky (Commented) (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CAMEL-4760) Unable to set logName on DefaultErrorHandler as well as executorService on LoggingErrorHandler
Date Fri, 09 Dec 2011 14:38:40 GMT

    [ https://issues.apache.org/jira/browse/CAMEL-4760?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13166209#comment-13166209
] 

Sergey Zhemzhitsky commented on CAMEL-4760:
-------------------------------------------

Here is the unit test that proves asyncDelayedRedelivery can be used with logging error handler.

{code:title=AsyncDelayedRedeliveryLogErrorHandlerTest.java}
package org.foo.bar;

import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.processor.RedeliveryPolicy;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;

import javax.naming.Context;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class AsyncDelayedRedeliveryLogErrorHandlerTest extends CamelTestSupport {

    @Test
    public void asyncRedeliveryTimer() throws Exception {
        context().addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("direct:start")
                    .to("seda:next?waitForTaskToComplete=Never&size=10");

                from("seda:next")
                    .errorHandler(loggingErrorHandler())
                    .onException(Exception.class)
                        .redeliveryPolicyRef("redeliveryPolicy")
                        .handled(true)
                        .to("mock:exception")
                    .end()
                    .process(new Processor() {
                        private AtomicInteger counter = new AtomicInteger();
                        @Override
                        public void process(Exchange exchange) throws Exception {
                            if (counter.compareAndSet(1, 2)) {
                                exchange.setProperty("ThrowException", Boolean.TRUE);
                                exchange.getIn().setBody(counter.get() - 1);
                            } else {
                                exchange.getIn().setBody(counter.getAndIncrement());
                            }
                        }
                    })
                    .process(new Processor() {
                        @Override
                        public void process(Exchange exchange) throws Exception {
                            if (Boolean.TRUE.equals(exchange.getProperty("ThrowException",
Boolean.class))) {
                                exchange.removeProperty("ThrowException");
                                throw new RuntimeException("Test Exception!");
                            }
                        }
                    })
                    .to("mock:result");
            }
        });

        MockEndpoint result = getMockEndpoint("mock:result");
        result.expectedMessageCount(5);
        result.allMessages().property("ThrowException").isNull();

        // the 2nd sent message must be delivered 5th
        result.message(4).body().isEqualTo(1);
        // ensure there is no delay between the 1st and the 3rd sent messages
        result.message(1).arrives().noLaterThan(100).millis().afterPrevious();

        startCamelContext();

        for(int i = 0; i < 5; i++) {
            sendBody("direct:start", i);
        }

        assertMockEndpointsSatisfied(10, TimeUnit.SECONDS);
    }

    @Override
    protected Context createJndiContext() throws Exception {
        Context jndiContext = super.createJndiContext();

        RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
        redeliveryPolicy.setAsyncDelayedRedelivery(true);
        redeliveryPolicy.setMaximumRedeliveries(1);
        redeliveryPolicy.setRedeliveryDelay(5000);
        jndiContext.bind("redeliveryPolicy", redeliveryPolicy);

        return jndiContext;
    }

    @Override
    public boolean isUseRouteBuilder() {
        return false;
    }

}
{code}

Please take a loot at assertions:

{code}
// the 2nd sent message must be delivered 5th
result.message(4).body().isEqualTo(1);
// ensure there is no delay between the 1st and the 3rd sent messages
result.message(1).arrives().noLaterThan(100).millis().afterPrevious();
{code}

The 2nd sent message is delivered 5th because of redelivery and the 2nd delivered message
which is equal to 3rd sent message arrives no later than 100 millis after the first delivered
message although _redeliveryDelay_ is equal to 5 seconds. That means I can configure async.
redelivery with logging error handler, so I have two questions:

# If I can configure async. redelivery with logging error handler why I cannot specify custom
executor service, although logging error handler extends default error handler?
# Is it possible to specify logName for default error handler, because it seems that spring
dsl does not allow to specify logName for loggers although java dsl does?
                
> Unable to set logName on DefaultErrorHandler as well as executorService on LoggingErrorHandler
> ----------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-4760
>                 URL: https://issues.apache.org/jira/browse/CAMEL-4760
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-spring
>    Affects Versions: 2.8.3
>            Reporter: Sergey Zhemzhitsky
>            Assignee: Claus Ibsen
>            Priority: Minor
>             Fix For: 2.8.4, 2.9.0
>
>
> The following snippets do not work, although each of the specified error handlers supports
_logName_ and _executorServiceRef_. The issue is actual for the _DeadLetterChannel_ error
handler too.
> {code:title=LoggingErrorHandler}
> <errorHandler id="errorHandler" type="LoggingErrorHandler" logName="${router.logger.name}"
executorServiceRef="redeliveryExecutor"/>
> {code}
> {code:title=DefaultErrorHandler}
> <errorHandler id="errorHandler" type="DefaultErrorHandler" logName="${router.logger.name}"
executorServiceRef="redeliveryExecutor"/>
> {code}
> {code:title=StackTrace}
> Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected
exception parsing XML document from class path resource [META-INF/spring/camel-context.xml];
nested exception is java.lang.IllegalArgumentException: Attribute executorServiceRef is not
supported by error handler type: LoggingErrorHandler, in error handler with id: errorHandler
> 	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412)
> 	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
> 	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
> 	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
> 	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
> 	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:186)
> 	... 42 more
> Caused by: java.lang.IllegalArgumentException: Attribute executorServiceRef is not supported
by error handler type: LoggingErrorHandler, in error handler with id: errorHandler
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message