我正在尋找解決方案,通過在運行時動態決定的處理器發送郵件,具體取決於郵件頭或主體上的某個屬性。根據郵件正文或郵件頭中的屬性動態加載駱駝處理器
假設我有兩個消息處理器(例如:Type1RequestProcessor
,Type2RequestProcessor
),如下所述。
我想要做的是在執行任一Type1RequestProcessor
Type2RequestProcesso
或中的R消息頭OT體使用屬性動態地決定的。(在這裏,我不想創建每處理器類型的多個路由器。)
我試圖如下所述(在標題中傳遞typeId)。但它顯然給出了下面的錯誤說No bean could be found in the registry for: ${header.messageId}RequestProcessor of type: org.apache.camel.Processor
。
HTTPRouter.java
import javax.enterprise.context.ApplicationScoped;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.cdi.ContextName;
@ApplicationScoped
@ContextName("camel-cdi-context")
public class HTTPRouter extends RouteBuilder {
@Override
public void configure() throws Exception {
from("direct:oneRouter")
.process("${header.typeId}RequestProcessor")
.to("direct:anotherRouter");
}
}
錯誤:
org.apache.camel.FailedToCreateRouteException: Failed to create route route19 at: >>> process[ref:${header.messageId}RequestProcessor] <<< in route: Route(route19)[[From[direct:oneRouter]] -> [process[ref:${he... because of No bean could be found in the registry for: ${header.messageId}RequestProcessor of type: org.apache.camel.Processor
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1298)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:204)
at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:1087)
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3540)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3271)
at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:202)
我試圖與Bean組件還,但結果是一樣的。
任何人都可以在這裏舉手嗎? 如何動態加載處理器?
Type1RequestProcessor.java
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
public class Type1RequestProcessor implements Processor {
public void process(Exchange exchange) throws Exception {
// Do Type1 process implementation
}
}
Type2RequestProcessor.java
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
public class Type2RequestProcessor implements Processor {
public void process(Exchange exchange) throws Exception {
// Do Type2 process implementation
}
}
注:我在路由器本身的工藝方法中的動態加載這些實施B計劃(匿名內部類)。但我仍然在尋找這個,因爲它完全符合我的要求。
- 駱駝版本:2.19.2
- WildFly版本:10.1.0
- 駱駝補丁版本: wildfly-駱駝膜片4.9.0
查看這個FAQ:http://camel.apache.org/how-to-use-a-dynamic-uri-in-to.html –
Thanx克勞斯易卜生,但我正在尋找動態加載處理器。不能動態地調用URI。如果我需要動態調用URI,我也可以使用toD(),因爲我使用的是駱駝2.19。 – namalfernandolk