Writing custom methods in Java DSL for apache camel routes

Can I write my own cpu detection methods in Camel and use that in my route like below?

from(uri)
.to("http://host:port/testData")
.**setTimeOut(long milliseconds)**

      

from is implemented in RouteDefinition and to is implemented in ProcessorDefinition. For example, if I want to implement setTimeOut method and use it in java DSL, how can I do that?

PS: I don't want to pass timeOut as an Httpclient request parameter to HttpUri.

Can anyone help with this?

+3


source to share


1 answer


No, you cannot do this.

Fixed methods / eips you can use in Java DSL form. To expand on this needs to be extended RouteBuilder

to allow new methods to be added to new start methods. You cannot add setTimeOut

which can work together with to

etc.

You will need to add the code to camel kernel and recompile, which is not recommended.



However, you can implement a processor and then call it setTimeout and then use .process

Processor setTimeout = new MySetTimeout(1000);

from
  .to
  .process(setTimeout);

      

And then use it as a processor from the method .process

.

+1


source







All Articles