控制匯流排控制器
從 6.4 版本開始,HTTP 模組提供了 @EnableControlBusController 配置類註解,用於在 /control-bus 路徑下將 ControlBusController 作為 REST 服務公開。底層的 ControlBusControllerConfiguration 啟用了 ControlBusCommandRegistry 的預初始化,以便為上述 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"
}
]
有關更多資訊,請參閱 控制匯流排。