控制总线控制器
从 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 序列化列表。
每个条目都是一个 bean,其中包含一个控制总线合格方法列表(有关更多信息,请参阅 ControlBusMethodFilter
),以及它们的参数类型和来自 @ManagedOperation
或 @ManagedAttribute
的描述(否则默认为方法名)。
POST 方法到 /control-bus/{beanName.methodName}
调用该命令。
请求正文可能包含要执行的命令的值列表及其类型。
例如,对于以下类,带有 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"
}
]
有关更多信息,请参阅 控制总线。