camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Richard Kettelerij <richardkettele...@gmail.com>
Subject Re: Looking for ideas to reduce code volume and duplication
Date Tue, 01 Apr 2014 20:37:57 GMT
Although I usually favor composition of inheritance I've had pretty good
results with putting code like this in a base class. E.g:

class QoSRouteBuilder extends RouteBuilder {
    public void configureQoS() {
       // your onException() code .......
    }
}

class RouteA extends QoSRouteBuilder {
     public void configure() {
         configureQoS();

          // your routing code
     }
}

class RouteB extends QoSRouteBuilder {
     public void configure() {
         configureQoS();

          // your routing code
     }
}

It's just Java code after all.

Regards,
Richard
http://richardlog.com

On Tue, Apr 1, 2014 at 4:51 PM, kraythe . <kraythe@gmail.com> wrote:

> Greetings:
>
> I have dozens of routes currently in our system and they have one of two
> variants of the following code:
>
>         .onException(Exception.class).useOriginalMessage().handled(true) //
> catch exceptions
> .setHeader(Exchange.FAILURE_ROUTE_ID, property(Exchange.FAILURE_ROUTE_ID))
> // set route that errored
> .setHeader(Exchange.EXCEPTION_CAUGHT, simple("${exception.stacktrace}")) //
> Store reason for error
> .to(ExchangePattern.InOnly,
> endpointAMQ(config.queueCaseAutomationDead())).end() // to DLQ
>
> The problem is I am getting more than annoyed at having to copy paste this
> all over the place but since there are a couple of variants, I cant declare
> a global handler. Making a direct is all well and good but doesnt really
> buy me much as I still have half the handler on every route.
>
> Any ideas how I could reduce code volume here ?
>
> *Robert Simmons Jr. MSc. - Lead Java Architect @ EA*
> *Author of: Hardcore Java (2003) and Maintainable Java (2012)*
> *LinkedIn: **http://www.linkedin.com/pub/robert-simmons/40/852/a39
> <http://www.linkedin.com/pub/robert-simmons/40/852/a39>*
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message