控制总线控制器
从版本 6.4 开始,HTTP 模块提供了一个 @EnableControlBusController 配置类注解,用于在 /control-bus 路径上将 ControlBusController 公开为 REST 服务。底层的 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"
]
}
]
}
]
本质上,这是一个JSON序列化的ControlBusController.ControlBusBean实例列表。每个条目都是一个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"
}
]
更多信息请参见控制总线。