Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spring-boot内嵌tomcat场景下,SpringMVC restcontroller接口内调用cse接口如何传递header(上下文)信息 #4632

Open
Castile opened this issue Dec 4, 2024 · 2 comments

Comments

@Castile
Copy link

Castile commented Dec 4, 2024

场景

集成spring-boot-actuator组件,业务通过curl命令调用actuator/health接口检测服务状态,业务自定义AbstractHealthIndicator里面调用cse的health接口,代码如下:

@Component
public class HealthChecker extends AbstractHealthIndicator {

    @Override
    protected void doHealthCheck(Health.Builder builder) throws Exception {
        RestTemplate restTemplate = RestTemplateBuilder.create();
        String result = restTemplate.getForObject("cse://provider/test/health", String.class);
        if ("UP".equals(result)) {
            builder.up().withDetail("cseState", "UP");
        } else {
            builder.down().withDetail("cseState", "DOWN");
        }
    }
}
image

curl命令:携带x-cse-context header信息

curl  -ki -H 'x-cse-context: {"x-biz-tenantId": "1002"}' http://localhost:9093/provider/actuator/health

期望

在provider/test/health 这个cse接口内可以通过handler在invocationcontext中获取到'x-cse-context: {"x-biz-tenantId": "1002"}' 信息。

现状

由于actuator组件的endpoint接口是由Spring MVC的DispatchServlet处理的,而cse接口是由RestServlet处理的,这个header信息无法带过来,但是是处于同一条调用链中。
其实,任何restcontroller接口调用cse接口都无法传递header信息, 我们希望在前台设置header上下文,调用rest接口的时候,将这个上下文传递到cse接口中

@RestController("/")
public class HelloController {

    @GetMapping("/hello")
    public String hello(){
        RestTemplate restTemplate = RestTemplateBuilder.create();
        return  restTemplate.getForObject("cse://provider/test/health", String.class);
    }
}
image

请问有什么方案?

@liubao68
Copy link
Contributor

liubao68 commented Dec 5, 2024

前后端走的spring boot mvc, 你可以看下它提供什么机制了,收到后,在调用请求前设置一下到java chasiss 的InvocationContext.

最好是actuator能够通过java chassis的RestServlet暴露端点,可以研究下是否具备可行性。

@Castile
Copy link
Author

Castile commented Dec 5, 2024

前后端走的spring boot mvc, 你可以看下它提供什么机制了,收到后,在调用请求前设置一下到java chasiss 的InvocationContext.

最好是actuator能够通过java chassis的RestServlet暴露端点,可以研究下是否具备可行性。

actuator能够通过java chassis的RestServlet暴露端点这个我没有啥好办法,如果可以的话actuator组件也可用在standalone模式下了,现在standalone模式下缺乏这种像spring-boot-actuator应用监控组件,希望后续能支持下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants