camel-k icon indicating copy to clipboard operation
camel-k copied to clipboard

Cron Trait replaces direct: consumer

Open fhossfel opened this issue 7 months ago • 3 comments

What happened?

We use the enrich-EIP to call another route to obtain credentials for accessing web services. Basically the flow looks like this:

copy_body = {

  Exchange original, Exchange otherExchange -> original.in.setBody(otherExchange.in.getBody())

}


from("cron://run_daily?schedule=0+5+*+*+?")
   .enrich("direct:subroute", copy_body)


from("direct:subroute")
 .setBody(constant('direct: route called'))

This code fails with the error message:

Caused by: org.apache.camel.RuntimeCamelException: Cannot produce to a TimerEndpoint: timer://camel-k-overridden-cron?delay=0&period=1&repeatCount=1
     at org.apache.camel.component.timer.TimerEndpoint.createProducer(TimerEndpoint.java:97)

Looking at the Groovy code reveals that the cron trait not only replaces from("cron:...") endpoint but also the from("direct:...") - and the endpoint in the enrich call enrich("direct:...").

copy_body = {

  Exchange original, Exchange otherExchange -> original.in.setBody(otherExchange.in.getBody())

}


from("timer:camel-k-overridden-cron?delay=0&period=1&repeatCount=1")
   .enrich("timer:camel-k-overridden-cron?delay=0&period=1&repeatCount=1", copy_body)


from("timer:camel-k-overridden-cron?delay=0&period=1&repeatCount=1")
 .setBody(constant('direct: route called'))

This causes the error above.

Steps to reproduce

No response

Relevant log output


Camel K version

2.6.0

fhossfel avatar May 12 '25 17:05 fhossfel

Well spotted. Feel free to contribute with a fix if you can work on it. Thanks!

squakez avatar May 13 '25 13:05 squakez

I can try to if you can point me to a spot where to start.

fhossfel avatar May 13 '25 13:05 fhossfel

I can try to if you can point me to a spot where to start.

Thanks for giving it a try! The piece of code is isolated in this func: https://github.com/apache/camel-k/blob/5c02e049136b1cc2fe327bc52b9c5b5363e0b9d0/pkg/trait/cron.go#L516 - however it can require different changes in each different language DSL. The problem is that we are replacing all URIs, whilst we should spot only the "cron" URI and replace that one.

squakez avatar May 13 '25 13:05 squakez