You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by tor86 <t....@ceres.no> on 2017/05/29 13:34:51 UTC

Dynamic properties in a camel route

I have a problem with dynamically altering properties of a given route. I
have a timer which calls an endpoint. This endpoint fetches xx amount of
rows from a DB and uses the offset=$property.testproperty to know where to
begin fetching data from DB. If offset is 100 it starts at row 100 and moves
500 rows. Then when the timer starts the next round the offset will be
100+500=600 so starting from row 600 instead of row 100. I try to use
properties to do this. First starting from zero and retrieving the last row
from header from the endpoint. Then I try to add this header to setProperty
and then this property will be updated before the next run on the quartz
endpoint.

The problem is this property does not update in the route. I can see it gets
value in both processor and route but when it is updated it is not
registered in the route.

CODE:

@Override
	public void configure() throws Exception {
		// TODO Auto-generated method stub

        from("quartz2:" + BASE_URL +
"?trigger.repeatCount=-1&trigger.repeatInterval=3000")
            .routeId("Update Solr quartz route").log(LoggingLevel.INFO,
log.getName(), "Tick tack")
           
.choice().when(property("testproperty").isNull()).setProperty("testproperty").simple("0")
            .recipientList(
               
simple("http4://localhost:8080/criswsint/hentPerson/alle?offset=${property.testproperty}"))
            .setProperty("testproperty", simple("${in.header.lastid}"))
            .to("direct:foo");

        from("direct:foo")
            .routeId("Direct foo")
            .process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    String theString = IOUtils.toString((InputStream)
exchange.getIn().getBody(), "UTF-8");
                    log.info(theString);
                    log.info((String) exchange.getProperty("testproperty"));
                }

            });
	}



--
View this message in context: http://camel.465427.n5.nabble.com/Dynamic-properties-in-a-camel-route-tp5801295.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Dynamic properties in a camel route

Posted by tor86 <t....@ceres.no>.
Thanks, got it to work now



--
View this message in context: http://camel.465427.n5.nabble.com/Dynamic-properties-in-a-camel-route-tp5801295p5801371.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Dynamic properties in a camel route

Posted by Claus Ibsen <cl...@gmail.com>.
You need to store the state of this offset outside a Camel exchange
property. Instead create a bean to hold that state, and then call that
bean from the camel route to get the new offset, which you can then
increment for the next call.

On Mon, May 29, 2017 at 3:34 PM, tor86 <t....@ceres.no> wrote:
> I have a problem with dynamically altering properties of a given route. I
> have a timer which calls an endpoint. This endpoint fetches xx amount of
> rows from a DB and uses the offset=$property.testproperty to know where to
> begin fetching data from DB. If offset is 100 it starts at row 100 and moves
> 500 rows. Then when the timer starts the next round the offset will be
> 100+500=600 so starting from row 600 instead of row 100. I try to use
> properties to do this. First starting from zero and retrieving the last row
> from header from the endpoint. Then I try to add this header to setProperty
> and then this property will be updated before the next run on the quartz
> endpoint.
>
> The problem is this property does not update in the route. I can see it gets
> value in both processor and route but when it is updated it is not
> registered in the route.
>
> CODE:
>
> @Override
>         public void configure() throws Exception {
>                 // TODO Auto-generated method stub
>
>         from("quartz2:" + BASE_URL +
> "?trigger.repeatCount=-1&trigger.repeatInterval=3000")
>             .routeId("Update Solr quartz route").log(LoggingLevel.INFO,
> log.getName(), "Tick tack")
>
> .choice().when(property("testproperty").isNull()).setProperty("testproperty").simple("0")
>             .recipientList(
>
> simple("http4://localhost:8080/criswsint/hentPerson/alle?offset=${property.testproperty}"))
>             .setProperty("testproperty", simple("${in.header.lastid}"))
>             .to("direct:foo");
>
>         from("direct:foo")
>             .routeId("Direct foo")
>             .process(new Processor() {
>
>                 @Override
>                 public void process(Exchange exchange) throws Exception {
>                     String theString = IOUtils.toString((InputStream)
> exchange.getIn().getBody(), "UTF-8");
>                     log.info(theString);
>                     log.info((String) exchange.getProperty("testproperty"));
>                 }
>
>             });
>         }
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Dynamic-properties-in-a-camel-route-tp5801295.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2