简体   繁体   English

在Java DSL中编写自定义方法用于apache camel路由

[英]Writing Custom methods in Java DSL for apache camel routes

Can i write my own Processor Definition methods in Camel and use that in my route as below ? 我可以在Camel中编写自己的处理器定义方法,并在我的路径中使用它,如下所示?

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

from is implemented in RouteDefinition and to is implemented in ProcessorDefinition. from在RouteDefinition中实现,并在ProcessorDefinition中实现。 Like that if i want to implement setTimeOut method and use it in java DSL, how can i do that? 就像那样,如果我想实现setTimeOut方法并在java DSL中使用它,我该怎么做?

PS : I don't want to pass the timeOut as a Httpclient query parameter to HttpUri. PS:我不想将timeOut作为Httpclient查询参数传递给HttpUri。

Can anyone help on this ? 任何人都可以帮忙吗?

No you cannot do this. 不,你不能这样做。

The methods / eips you can use form the Java DSL is fixed. 您可以使用Java DSL的方法/ eips是固定的。 To extend this requires to extend the RouteBuilder which allows to add new methods to new starting methods. 要扩展这一点,需要扩展RouteBuilder ,以允许向新的启动方法添加新方法。 You cannot add a setTimeOut that can work together with to , etc. 您无法添加可与to一起使用的setTimeOut等。

You would need to add the code to camel-core, and recompile it, which is not recommended. 您需要将代码添加到camel-core,并重新编译它,这是不推荐的。

However you can implement a processor, and then name it setTimeout, and then use the .process 但是,您可以实现处理器,然后将其命名为setTimeout,然后使用.process

Processor setTimeout = new MySetTimeout(1000);

from
  .to
  .process(setTimeout);

And then use it as a processor from the .process method. 然后将其用作.process方法的处理器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM