spring-boot - Zuul Gateway 服务器在本地处理请求
问题描述
如何让 Spring Boot Zuul 代理服务器在本地处理特定请求,而不是将其代理到其他服务器?
假设我想通过 API 对 Zuul 代理服务器本身进行自定义健康检查,该 API 应该返回本地响应,而不是从其他远程服务器返回代理响应。
转发请求需要什么样的路由配置?
解决方案
以下是我想出的,它对我有用:
1)创建本地请求处理程序:
在Zuul代理服务器代码的文件中添加一个带有RequestMapping的常规Controller/RestController
@RestController
public class LocalRequestHandler {
@GetMapping(path = "/status", produces = MediaType.TEXT_PLAIN_VALUE);
private static ResponseEntity<String> getServiceStatus() {
String status = "I am alive";
return ResponseEntity.ok().body(status);
}
}
2)在定义了其他路由的配置文件(application.properties 或视情况而定)中创建本地转发路由。在我的例子中,Spring Boot Zuul 代理服务器在 Jetty 容器上运行,GatewaySvc 作为应用程序上下文。
zuul.routes.gatewaysvc.path=/GatewaySvc/status
zuul.routes.gatewaysvc.url=forward:/GatewaySvc/status
对于我尚未测试过的独立 Spring Boot,您可能必须从上述配置中删除上下文路径。
zuul.routes.gatewaysvc.path=/status
zuul.routes.gatewaysvc.url=forward:/status
参考: 绞杀模式和本地前锋
推荐阅读
- css - 如何水平居中垂直旋转文本?
- vb.net - vb.net 下拉列表中每个项目的工具提示
- c - 两个连续的参数定义对 C 中的函数意味着什么?
- r - 使用 twitteR 的 ROAuth 握手错误 (Twitter API 443)
- docker - 有没有从运行 Docker 容器到 Kubernetes 部署的好方法?
- r - scale_fill_manual 默认中断:如何分配
- jenkins - 如何在声明性 Jenkinsfile 中跨阶段保留非字符串对象?
- plsql - 将函数调用作为参数传递给插入语句 - 可能的问题
- mysql - Magento 2:如何允许更新具有外键约束的列的空值?
- prometheus - 将字符串附加到grafana查询中的变量?