控制总线控制器

从版本 6.4 开始,HTTP 模块提供了一个配置类 Comments,以在 path 上将 作为 REST 服务公开。 下面的 启用预先初始化,以公开上述 REST 服务的所有可用控制总线命令。 GET 请求以如下格式返回应用程序的所有控制总线命令:@EnableControlBusControllerControlBusController/control-busControlBusControllerConfigurationControlBusCommandRegistry/control-busspring-doc.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 序列化的实例列表。 每个条目都是一个 bean,其中包含一个符合控制总线条件的方法列表(有关更多信息,请参见),以及它们的参数类型和 or 描述(否则回退到方法名称)。ControlBusController.ControlBusBeanControlBusMethodFilter@ManagedOperation@ManagedAttributespring-doc.cn

用于调用命令的 POST 方法。 请求正文可能包含一个值及其类型列表,供命令执行。 例如,带有类的参数的命令:/control-bus/{beanName.methodName}operationintspring-doc.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;
    }

}

可以像使用 mention POST 方法和 body 一样调用:/testManagementComponent.operationspring-doc.cn

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

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