如需使用最新稳定版本,请使用 Spring Integration 7.0.4spring-doc.cadn.net.cn

控制总线控制器

从版本 6.4 开始,HTTP 模块提供了一个 @EnableControlBusController 配置类注解,用于在 /control-bus 路径上将 ControlBusController 暴露为 REST 服务。 其下方的 ControlBusControllerConfiguration 启用了 ControlBusCommandRegistry 的预加载初始化,以便为该 REST 服务提供所有可用的控制总线命令。 /control-bus GET 请求将以如下格式返回应用程序的所有控制总线命令: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"
        ]
      }
    ]
  }
]

本质上,这是一个包含 ControlBusController.ControlBusBean 个实例的 JSON 序列化列表。 每个条目都是一个 Bean,其中包含一个控制总线可调用方法的列表(有关更多信息,请参阅 ControlBusMethodFilter),以及这些方法的参数类型和来自 @ManagedOperation@ManagedAttribute 的描述(否则回退到方法名)。spring-doc.cadn.net.cn

POST 方法调用/control-bus/{beanName.methodName}将执行该命令。 请求体可以包含要执行的命令的值的列表及其类型。 例如,对于该类,使用参数intoperation命令: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;
    }

}

可以使用 POST 方法并附带以下 body 内容来调用 /testManagementComponent.operationspring-doc.cadn.net.cn

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

有关更多信息,请参阅 控制总线spring-doc.cadn.net.cn