控制匯流排控制器
從 6.4 版本開始,HTTP 模組提供了一個 @EnableControlBusController
配置類註解,用於將 ControlBusController
在 /control-bus
路徑上作為 REST 服務暴露。底層的 ControlBusControllerConfiguration
為 ControlBusCommandRegistry
啟用了預初始化(eager initialization),以暴露所有可用的控制匯流排命令供所述 REST 服務使用。/control-bus
GET 請求將返回應用程式的所有控制匯流排命令,格式如下:
[
{
"beanName": "errorChannel",
"commands": [
{
"command": "errorChannel.setShouldTrack",
"description": "setShouldTrack",
"parameterTypes": [
"boolean"
]
},
{
"command": "errorChannel.setLoggingEnabled",
"description": "Use to disable debug logging during normal message flow",
"parameterTypes": [
"boolean"
]
},
{
"command": "errorChannel.isLoggingEnabled",
"description": "isLoggingEnabled",
"parameterTypes": []
}
]
},
{
"beanName": "testManagementComponent",
"commands": [
{
"command": "testManagementComponent.operation2",
"description": "operation2",
"parameterTypes": []
},
{
"command": "testManagementComponent.operation",
"description": "operation",
"parameterTypes": []
},
{
"command": "testManagementComponent.operation",
"description": "operation",
"parameterTypes": [
"int",
"java.lang.String"
]
},
{
"command": "testManagementComponent.operation",
"description": "operation",
"parameterTypes": [
"int"
]
}
]
}
]
本質上是 ControlBusController.ControlBusBean
例項的 JSON 序列化列表。每個條目都是一個 bean,其中包含一系列符合控制匯流排條件的方法(詳見 ControlBusMethodFilter
),並附帶其引數型別以及從 @ManagedOperation
或 @ManagedAttribute
獲取的描述(如果沒有則回退到方法名)。
對 /control-bus/{beanName.methodName}
發起 POST 請求將呼叫該命令。請求體可以包含用於執行命令的一系列值及其型別。例如,對於帶有 int
引數的 operation
命令,針對某個類
@ManagedResource
class TestManagementComponent {
@ManagedOperation
public void operation() {
}
@ManagedOperation(description = "The overloaded operation with int argument")
public void operation(int input) {
}
@ManagedOperation(description = "The overloaded operation with two arguments")
public void operation(int input1, String input2) {
}
@ManagedOperation
public int operation2() {
return 123;
}
}
可以使用前述 POST 方法呼叫,例如 /testManagementComponent.operation
,請求體為
[
{
"value": "1",
"parameterType": "int"
}
]
有關更多資訊,請參閱控制匯流排。