控制总线控制器

从版本 6.4 开始,HTTP 模块提供了一个@EnableControlBusControllerconfiguration 类注解来公开ControlBusController作为 REST 服务在/control-bus路径。 这ControlBusControllerConfigurationControlBusCommandRegistry公开上述 REST 服务的所有可用 Control Bus 命令。 这/control-busGET 请求以如下格式返回应用程序的所有控制总线命令:spring-doc.cadn.net.cn

[
  {
    "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(否则回退到方法名称)。spring-doc.cadn.net.cn

POST 方法用于/control-bus/{beanName.methodName}调用命令。 请求正文可能包含一个值及其类型列表,供命令执行。 例如,operationcommand 替换为int类的参数:spring-doc.cadn.net.cn

@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使用带有 body 的 mention POST 方法:spring-doc.cadn.net.cn

[
    {
        "value": "1",
        "parameterType": "int"
    }
]

请参阅 Control Bus 了解更多信息。spring-doc.cadn.net.cn