- Apache Camel 教程
- Apache Camel - 首頁
- Apache Camel - 簡介
- Apache Camel - 概述
- Apache Camel - 特性
- Apache Camel - 架構
- Apache Camel - CamelContext
- Apache Camel - 端點
- Apache Camel - 元件
- Apache Camel - 訊息佇列
- Apache Camel - 專案
- 使用 Spring 與 Camel
- Apache Camel 有用資源
- Apache Camel - 快速指南
- Apache Camel - 有用資源
- Apache Camel - 討論
Apache Camel - 端點
我們已經瞭解了整合程式碼中端點的外觀。我們迄今為止使用的表示式,例如file:/order、jms:orderQueue、direct:distributeOrderDSL,都是端點。如您所見,它們遵循 URI 規範格式。在評估此 URI 時,CamelContext 會建立Endpoint例項;您無需擔心在 DSL 中例項化Endpoint實現。
以我們之前的示例為例,您可以在 Java DSL 中指定端點,如下所示:
from ("file:/order").to("jms:orderQueue");
在 Spring 中,如下所示:
<route> <from uri = "file:/order"/> <to uri = "jms:orderQueue"/> </route>
在這兩種情況下,端點都是一個常量字串。在某些情況下,您可能希望在執行時構建此字串。您可以使用 Java 的String格式化程式方法來做到這一點。Camel 提供了另一種更簡單的方法來在執行時建立這些 URI 字串。為此,Camel 提供了fromF和toF方法,這些方法接受使用者指定引數的引數。以下語句說明了toF方法的使用:
from("direct:distributeOrderDSL”).toF("file://%s?fileName=%s", path, name);
由於這些方法的存在,因此無需使用 Java 內建的String格式化程式方法。
Camel 預設使用Simple語言來計算端點表示式。Simple語言主要用於評估表示式和謂詞,而無需過多考慮XPath的複雜性。為了評估謂詞,您可以將另一種語言(例如xpath)與預設的Simple語言結合使用。這可以透過使用加號分隔其他語言來完成。此處的程式碼片段展示瞭如何將xpath字串連線到用Simple編寫的表示式。
from("direct:start")
.toD("jms:${orderQueue}+language:xpath:/order/@id");
在Spring中,您可以像這裡一樣實現相同的功能:
<route>
<from uri = "direct:start"/>
<toD uri = "jms:${orderQueue}+language:xpath:/order/@id"/>
</route>
您可以根據需要連線任意數量的語言,每個語言都用加號與前一個語言分隔。支援的語言列表可以在此處找到。
廣告