Jetty是從某個給定URL接收請求的最簡單方法。
from("jetty:http://localhost:{{port}}/myapp/myservice")
.process() // do something with the Exchange
這是很容易得到運行,但是你最終會得到一些棘手的路由規則來區分的GET,郵政等之間。恕我直言,在駱駝路線執行多條路徑(即分裂,選擇等)可能/將成爲一個陷阱的粗心大意。
Servlets比較棘手,因爲您需要編寫Servlet實現並將其註冊到Servlet容器(例如,通過web.xml),結果是相同的 - 您將得到一個HTTP請求作爲交換。
web.xml
<web-app>
<servlet>
<servlet-name>CamelServlet</servlet-name>
<display-name>Camel Http Transport Servlet</display-name>
<servlet-class>org.apache.camel.component.servlet.CamelHttpTransportServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CamelServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>
RouteBuilder
from("servlet:///hello?matchOnUriPrefix=true").process(new Processor() {
// do stuff
我不認爲這對jetty組件有什麼好處。
Camel Rest DSL是我的選擇。這是一個簡單的DSL,用於描述具有良好REST語義的HTTP端點,它明確了路由規則是什麼,它相對簡潔。這僅2.14起,雖然工程..
rest("/say")
.get("/hello").to("direct:hello")
.get("/bye").consumes("application/json").to("direct:bye")
.post("/bye").to("mock:update");
from("direct:hello")
.transform().constant("Hello World");
from("direct:bye")
.transform().constant("Bye World");
在休息DSL或與此有關的任何非servlet的實現,有什麼建議的方法來保持運行所有的時間駱駝上下文線程? – Milli 2015-02-24 04:05:26
這取決於你如何開始駱駝上下文 - 有一堆選項,比如使用MainSupport類,在spring容器中,osgi,在war文件中以及可能是其他的。 Redhat會說使用Fuse/OSGi,但這會爲一個簡單的應用程序帶來巨大的認知和應用程序開銷。就我個人而言,我認爲與駱駝MainSupport類的一個罐子是要走的路。如果你需要在tomcat上運行它,請看這個http://camel.apache.org/tutorial-on-using-camel-in-a-web-application.html(儘管你想避免使用spring可能不是最好的方式) – stringy05 2015-02-24 04:21:54