异常时camel路由流更改

hlswsv35  于 2021-07-07  发布在  Java
关注(0)|答案(0)|浏览(248)

我已经成功地创建了几个路由覆盖routebuilder的configure()方法。for循环用于在应用程序启动时生成路由,例如:
路由1:从(“direct:route1“”。到(“内蒂-http:http://localhost:8080/route1)
路由2:从(“direct:route2“”。到(“内蒂-http:http://localhost:8081/route2)
路由3:从(“direct:route3“”。到(“内蒂-http:http://localhost:8082/route3)
路由4:从(“direct:route4“”。到(“内蒂-http:http://localhost:8083/route4)
路线5:从(“direct:route5“”。到(“内蒂-http:http://localhost:8084/route5)

for (endpoint in endpoints.iterator()) {

        from("direct:" + endpoint.getEndpointRouteName())
                .process(getProcessor(endpoint.getEndpointProcessor(), endpoint.getEndpointRouteName(), objectMapper))
                .setHeader(Exchange.HTTP_METHOD, simple(endpoint.getEndpointRequestMethod()))
                .setHeader(Exchange.CONTENT_TYPE, constant(endpoint.getEndpointContentType()))
                .to("netty-http:" + endpoint.getEndpointUrl())
    }

private fun getProcessor(processorClassName: String, name: String, objectMapper: ObjectMapper): Processor {
    var processorClass = Class.forName("com.demo.camelpoc.processors.$name.$processorClassName")

    return processorClass.getDeclaredConstructor(ObjectMapper::class.java).newInstance(objectMapper) as Processor
}

还有一个启动工作流的源端点。例如,运行时生成的默认工作流:
从(sourceurl).pipeline(“direct:route1", "direct:route2", "direct:route3", "direct:route4", "direct:route5")

from("netty-http:$sourceUrl")
            .pipeline(*endpointNames.toTypedArray())

其中endpointnames是端点字符串的vararg,如“direct:route1"... 等
要求:在任何路由中引发异常时如何更改工作流
例如:
正常流量应为:源->“direct:route1" -> "direct:route2" -> "direct:route3" ->"direct:route4"-> "direct:route5"
但是,假设在direct:route2,我想将流更改为
direct:routenew -> "direct:route3" ->"direct:route4"-> "direct:route5"
以及输入到direct:routenew should 是“的输出”direct:route1"
我尝试过各种异常处理技术,但找不到解决方案。

onException(Route2Exception::class.java)
                .useOriginalMessage()
                .handled(true)
                .to("direct:routeNew")

**The pipeline breaks and an error is returned back to consumer.**
**Using "useOriginalMessage()" the message in exchange is set as it was during route2 and not route1**

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题