控制总线控制器
从 6.4 版本开始,HTTP 模块提供了一个 @EnableControlBusController
配置类注解,用于将 ControlBusController
作为 REST 服务暴露在 /control-bus
路径下。底层的 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 序列化列表。每个条目都是一个包含控制总线合格方法(有关更多信息,请参阅 ControlBusMethodFilter
)列表的 bean,其中包含这些方法的参数类型和来自 @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;
}
}
可以调用为 /testManagementComponent.operation
,使用 POST 方法并带有以下主体:
[
{
"value": "1",
"parameterType": "int"
}
]
更多信息请参见 控制总线。