Apache Camel使用之集成SpingBoot Actuator2.0

在完成Apache Camel組件之Control Bus
之後, 筆者突然想起來之前在 Apache Camel源碼研究之集成到SpingBoot 中探究過Camel對於SpringBoot Actuator特性的支持,而這不正是我們所需要的嗎?

1. 概述

在上一篇 Apache Camel源碼研究之集成到SpingBoot 中,我們是基於SpringBoot1.x來研究的Actuator特性,隨着SpringBoot升級到2.x,其Actuator特性的實現變化也是頗大,Apache Camel的實現相應發生了改變,如果要對其進行源碼層次的討論勢必要牽扯到SpringBoot2.x相關變更,因此本文接下來的部分只要針對是應用方面,關於SpringBoot2.x Actuator特性的變更就留待後續發展吧。

2. 集成

SpringBoot以配置簡單聞名,這裏也不例外。

2.1 引入依賴包

Apache Camel對於SpringBoot Actuator特性的支持是直接包含在camel-spring-boot-x.yy.z.jar中的。因此只需要在pom.xml進行一次引用即可。

<!-- 針對 2.x 版本 -->
<dependency>
	<groupId>org.apache.camel</groupId>
	<artifactId>camel-spring-boot-starter</artifactId>
	<version>${camel.version}</version>
</dependency>
<!-- 針對 3.x 版本 -->
<dependency>
    <groupId>org.apache.camel.springboot</groupId>
    <artifactId>camel-spring-boot-starter</artifactId>
    <version>${camel.version}</version>
</dependency>

2.2 必要配置文件項

SpringBoot2.x之後,出於安全性考慮,Actuator特性需要顯式聲明,如下所示,在配置文件application.properties中進行如下設置:

# 只開放camel相關的Actuator特性. 另外可以通過設置爲 * 來開啓所有的接口.
# camelroutes  /  * 
management.endpoints.web.exposure.include=camelroutes,camelroutecontroller
# 允許對route進行start, stop等操作
management.endpoint.camelroutes.readOnly=false

3. 操作清單

本文靈魂所在,以下列舉Camel提供的所有Actuator功能(相關源碼爲CamelRoutesEndpoint類等)。

URL 用途 HTTP Method 參數說明
http://ip:port/context/actuator/camelroutes 獲取CamelContext中定義的所有Route GET
http://ip:port/context/actuator/camelroutes/{id} 獲取某個Route的定義信息,XML格式的 POST {id} 爲相應Route的Id
http://ip:port/context/actuator/camelroutes/{id}/{action} 操作指定Route GET 1. {id} 爲相應Route的Id
2. action可選項:
detail,
info,
stop,
start,
reset,
suspend,
resume
http://ip:port/context/actuator/camelroutecontroller 默認返回的是空集合 GET

4. Links

  1. Apache Camel組件之Control Bus
  2. Apache Camel源碼研究之集成到SpingBoot
  3. Office Site - Camel And Spring
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章