控制总线控制器

从 6.4 版本开始,HTTP 模块提供了一个 @EnableControlBusController 配置类注解,用于将 ControlBusController/control-bus 路径上作为 REST 服务暴露。底层的 ControlBusControllerConfigurationControlBusCommandRegistry 启用了预初始化(eager initialization),以暴露所有可用的控制总线命令供所述 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 获取的描述(如果没有则回退到方法名)。

/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"
    }
]

有关更多信息,请参阅控制总线