I'm not seeing all the code of course but remember that spring beans by
default are Singletons. So values set at the class level are not thread
safe.

On Fri, Dec 13, 2019, 1:05 AM Ron Cecchini <roncecch...@comcast.net> wrote:

> > On December 12, 2019 at 11:16 AM Claus Ibsen <claus.ib...@gmail.com>
> wrote:
> >
> > You can also name your RouteBuilder class with a bean id, if you use
> > spring / spring-boot or cdi etc. And then refer to this bean ids,
> > where you can have methods that you can refer to in the simple bean
> > function.  Then you dont need to add new classes.
>
> Whaaaat...?  You mean my MyRouteBuilder class can have *more* than just
> the single overridden configure() method...!?
>
> *slaps forehead*  Man, talk about not seeing what was right in front of
> me...
>
> So, I am using Spring Boot, and after I took your elegant advice and made
> the AtomicReference a class variable, and created a getter/setter for it, I
> was able to eliminate the process() and setHeader() calls and go from this:
>
> from("timer:mytimer?period={{polling.interval}}")
>      .process(exchange -> exchange.getIn().setHeader("offset",
> offsetCache.get()))
>      .toD("{{url.base}}/${header.offset}")
>      // process the response and get the new offset from the header into
> the class variable
>      .setHeader("offset", simple("${in.header.NEXT_OFFSET}"))
>      .process(exchange ->
> offsetCache.set(exchange.getIn().getHeader("offset").toString()))
>
> to this sweet thing:
>
> from("timer:mytimer?period={{polling.interval}}")
>      .toD("{{url.base}}/${bean:MyRouteBuilder.getOffset}
>      // process the response and get the new offset from the header into
> the class variable
>      .bean("MyRouteBuilder", "setOffset(${in.header.NEXT_OFFSET})")
>
> Thanks as always - and on to the next thing. (figuring out a unified
> logging for routes and classes...)
>

Reply via email to