SpringCloud 綁定可視化和控制

2023-11-27 11:33 更新

從2.0版開始,Spring Cloud Stream支持通過Actuator端點(diǎn)進(jìn)行綁定的可視化和控制。

從2.0版執(zhí)行器開始,并且web是可選的,您必須首先添加web依賴項(xiàng)之一,然后手動添加執(zhí)行器依賴項(xiàng)。以下示例說明如何為Web框架添加依賴項(xiàng):

<dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-web</artifactId>
</dependency>

以下示例顯示如何為WebFlux框架添加依賴項(xiàng):

<dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-webflux</artifactId>
</dependency>

您可以添加執(zhí)行器依賴項(xiàng),如下所示:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

 要在Cloud Foundry中運(yùn)行Spring Cloud Stream 2.0應(yīng)用程序,必須將spring-boot-starter-webspring-boot-starter-actuator添加到類路徑中。否則,由于運(yùn)行狀況檢查失敗,該應(yīng)用程序?qū)o法啟動。

您還必須通過設(shè)置以下屬性來啟用bindings執(zhí)行器端點(diǎn):--management.endpoints.web.exposure.include=bindings。

一旦滿足這些先決條件。應(yīng)用程序啟動時(shí),您應(yīng)該在日志中看到以下內(nèi)容:

: Mapped "{[/actuator/bindings/{name}],methods=[POST]. . .
: Mapped "{[/actuator/bindings],methods=[GET]. . .
: Mapped "{[/actuator/bindings/{name}],methods=[GET]. . .

要顯示當(dāng)前綁定,請?jiān)L問以下URL:http://<host>:<port>/actuator/bindings

或者,要查看單個(gè)綁定,請?jiān)L問類似于以下內(nèi)容的URL之一:http://<host>:<port>/actuator/bindings/myBindingName

您還可以通過發(fā)布到相同的URL來停止,開始,暫停和恢復(fù)單個(gè)綁定,同時(shí)提供一個(gè)state作為JSON的參數(shù),如以下示例所示:

curl -d'{“ state”:“ STOPPED”}'-H“內(nèi)容類型:應(yīng)用程序/ json” -X POST http:// <主機(jī)>:<port> / actuator / bindings / myBindingName curl -d'{ “ state”:“ STARTED”}'-H“內(nèi)容類型:application / json” -X POST http:// <host>:<port> / actuator / bindings / myBindingName curl -d'{“ state”:“ PAUSED“}'-H”內(nèi)容類型:application / json“ -X POST http:// <host>:<port> / actuator / bindings / myBindingName curl -d'{” state“:” RESUMED“}'- H“內(nèi)容類型:應(yīng)用程序/ json” -X POST http:// <主機(jī)>:<端口> / actuator / bindings / myBindingName

 PAUSEDRESUMED僅在相應(yīng)的活頁夾及其基礎(chǔ)技術(shù)支持時(shí)起作用。否則,您會在日志中看到警告消息。當(dāng)前,只有Kafka活頁夾支持PAUSEDRESUMED狀態(tài)。


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號