获取执行时使用的RouteBuilder类。

huangapple go评论51阅读模式
英文:

Get the RouteBuilder class used at execution time

问题

以下是代码部分的中文翻译:

在执行期间通过Exchange检索构建路由的`RouteBuilder`类是否可能例如

    class SimplePingRoute : RouteBuilder() {
    override fun configure() {
        from("timer://foo?fixedRate=true&period=1000")
            .routeId("pong-demo-app")
            .process({exc->
                //***在此点从exc中查找SimplePingRoute*** 
            })
            .to("log:pong")
    }}

请注意,代码中的注释部分没有被翻译,因为它们是代码的一部分。

英文:

Is it possible to retrieve what RouteBuilder class was used to build a Route at execution time via the Exchange? For example;

class SimplePingRoute : RouteBuilder() {
override fun configure() {
    from("timer://foo?fixedRate=true&period=1000")
        .routeId("pong-demo-app")
        .process({exc->
            //***looking for SimplePingRoute at this point from exc*** 
        })
        .to("log:pong")
}}

答案1

得分: 1

Camel 3.20版本及以后会存储每个EIP节点的源文件:行号(需要在Java DSL中启用此功能)。这允许像调试器这样的工具将运行时调试会话与源代码相关联。还有像camel-jbang这样的工具可以输出精确的源代码信息。

也许您的工具也可以使用这个功能。

英文:

Camel 3.20 onwards stores the source file:line-number of the routes for each EIP node (you need to enable this for Java DSL). This allows tooling such as the debugger to correlate the runtime debug session with the source code. And tooling like camel-jbang to output source precise information.

Maybe your tool can use that also.

答案2

得分: 0

.process(exchange -> {
    System.out.println(this.getClass().getSimpleName());
})
英文:

A Java example, but easily transformed to your language of choice:

.process(exchange -> {
    System.out.println(this.getClass().getSimpleName());
})

答案3

得分: 0

将路由生成器存储在交换属性中,以便随时在后续处理中使用。

from("timer://foo?fixedRate=true&period=1000")
    .routeId("pong-demo-app")
    .setProperty("routeBuilder").constant(this.getClass().getName())
    .process(exchange -> System.out.println(exchange.getProperty("routeBuilder")))
    .to("log:pong")
英文:

Why not just store the routebuilder in an exchange property, so that it is always available in the later processing ?

 from("timer://foo?fixedRate=true&period=1000")
        .routeId("pong-demo-app")
        .setProperty("routeBuilder").constant( this.getClass().getName() )
        .process( exc-> System.out.println(exc.getProperty("routeBuilder")) )
        .to("log:pong")

huangapple
  • 本文由 发表于 2023年3月21日 00:59:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75793196.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定