[英]Apache Camel Issue having routingSlip after a filter
我正在實施 Camel 路由,在將消息處理重定向到端點或其他取決於routing slip
標頭之前,我需要在其中放置過濾器。 像下面這樣:
from("direct:a")
.routeId("a")
.choice()
.when(header("foo"))
.filter(body().isNotNull())
.routingSlip(header("my-slip"))
.endChoice()
.otherwise()
.log("header 'foo' was false")
.endChoice()
.end();
嘗試運行應用程序時,出現以下異常:
java.lang.ClassCastException: class org.apache.camel.model.FilterDefinition cannot be cast to class org.apache.camel.model.ChoiceDefinition
任何解釋為什么這不是一個合法的結構以及我應該如何編碼我的路線來實現我想要的。 根據我自己的觀察,這是導致這種情況的choice()
構造。 如果選擇不存在,則在filter
之后添加routingSlip
構造就可以正常工作。
預先感謝您的意見。
嘗試在.routingSlip(header("my-slip"))
.end()
之后添加.end()
以關閉過濾器定義。
from("direct:a")
.routeId("a")
.choice()
.when(header("foo"))
.filter(body().isNotNull())
.routingSlip(header("my-slip"))
.end()
.endChoice()
.otherwise()
.log("header 'foo' was false")
.endChoice()
.end();
只需移除filter
。 將所有條件放在when
分支中。 例如,這里我使用的是 Simple 語言:
from("direct:a")
.routeId("a")
.choice()
.when(simple("${header.foo} !=null and ${body}!=null))
.routingSlip(header("my-slip"))
.endChoice()
.otherwise()
.log("header 'foo' was false")
.endChoice()
.end();
filter
和choice
是相似的。 您可以使用filter
而不是單個if
(或者也可以從列表中過濾項目); 在if .. else
情況下使用choice
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.