actuator–基础–07–自定义Endpoint
代码位置
https://gitee.com/DanShenGuiZu/learnDemo/tree/master/actuator-learn/actuator01
1、怎么自定义Endpoint
1.1、方法1
- 只需要在我们的新建Bean上使用 @Endpoint 注解即可
- Bean 中的方法就可以通过 JMX 或者 HTTP 公开。
1.2、方法2
- 可以使用 @JmxEndpoint 或 @WebEndpoint 编写 EndPoint。
- @JmxEndpoint 仅通过JMX公开
- @WebEndpoint 仅通过HTTP公开
2、类方法的公开
类中的方法是不支持对外公开的,需要添加对应的注解,这里有3个注解
- @ReadOperation:对应HTTP的GET请求
- @WriteOperation:对应HTTP的POST请求
- @DeleteOperation:对应HTTP的DELETE请求
3、案例
3.1、代码
@Component
// 自定义端点,名称为my
@Endpoint(id = "my")
public class EndpointCustom {
// 方法公开
@ReadOperation
public String endpointCustomRead(String content) {
return "ReadOperation-->请求的内容: " + content;
}
// 方法公开
@WriteOperation
public String endpointCustomWrite(String content) {
return "WriteOperation-->写的内容: " + content;
}
// 方法公开
@DeleteOperation
public String endpointCustomDelete(String content) {
return "DeleteOperation-->删除的内容: " + content;
}
}
3.2、测试
# GET请求
http://localhost:8080/actuator/my?content=endpointGet
# POST请求
http://localhost:8080/actuator/my?content=endpointPost
# DELETE请求
http://localhost:8080/actuator/my?content=endpointDELETE