问题
我有一个spring mvc使用 apache camel 的应用程序。我对 RouteBuilder 类所扮演的角色以及它实际上是如何初始化的感到困惑。我知道docs假设configure()方法是:
Called on initialization to build the routes using the fluent builder syntax.
但是这个初始化什么时候发生呢?它是在应用程序启动时发生还是在稍后将要使用路由时发生?
这个问题的目的最终是想问我如何在运行时修改路由。我希望能够根据需要构建不同的路线。
示例
xml 定义:
<service name="myService" tier="3">
<requestType>my.package.RequestType</requestType>
<responseType>my.package.ResponseType</responseType>
<endpoint>
<httpEndpoint>
<url default="true" value="someUrl"/>
<timeout value="5000"/>
</httpEndpoint>
</endpoint>
</service>
路线生成器模板:
public class myRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
// When does this method get executed?
}
}
问题
- configure()什么时候执行?
- 如何动态设置端点 URL?
最佳答案
您可以使用 toD 在运行时根据表达式动态更改端点。请参阅the documentation
如果您想更改更多路由或添加全新路由,请查看 CamelContext 上的 API。这个Stackoverflow question有一个添加全新路线的示例。
关于java - 如何在运行时修改 Camel 端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39023494/