控制总线控制器

从 6.4 版本开始,HTTP 模块提供了 @EnableControlBusController 配置类注解,用于在 /control-bus 路径下将 ControlBusController 作为 REST 服务公开。底层的 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(否则回退到方法名)的描述。

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

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

© . This site is unofficial and not affiliated with VMware.