简体   繁体   English

找出哪个端点发送了REST调用

[英]Find out which endpoint sent a REST call

I'm trying to create a visualisation of REST calls among several internal and external services/servers. 我正在尝试在多个内部和外部服务/服务器之间创建REST调用的可视化。 I'd like to know which endpoint called which other endpoint. 我想知道哪个端点调用了另一个端点。 I figured that the only way to do this is to do this on the caller side, because the receiver does not have any information about the caller endpoint. 我认为执行此操作的唯一方法是在调用方执行此操作,因为接收方没有有关调用方端点的任何信息。

Here's my thinking: 这是我的想法:

  1. I create an object like RestTemplate and call the method. 我创建一个类似RestTemplate的对象并调用该方法。
  2. I create an Interceptor or something like that, which will extract the information from the RestTemplate. 我创建了一个拦截器或类似的东西,它将从RestTemplate中提取信息。

My problem is that I'm not sure how to find out which REST endpoint called the RestTemplate method. 我的问题是我不确定如何找出哪个REST端点称为RestTemplate方法。 The RestTemplate (or other similar object) call could be called in nested methods, so for example the endpoint could invoke a private method, which then calls the external service itself. 可以在嵌套方法中调用RestTemplate(或其他类似对象)调用,因此,例如,端点可以调用私有方法,然后私有方法将调用外部服务本身。

Is there any way how to get this information? 有什么办法可以获取这些信息吗? Or am I maybe just thinking too hard and there is an easier way to do this? 还是我可能只是想得太刻苦,有更简单的方法可以做到这一点?

Example: 例:

@GetMapping("/hello")
public String hello() {
    methodThatCallsOtherEndpoint("something.com/weather"); // this method inside itself calls an endpoint
    logRestCall("localhost:8000/hello", "something.com/weather"); // how do I do this automatically without having to type it myself?

    return "hello";
}

Thanks for any help. 谢谢你的帮助。

如果这些服务/服务器具有静态IP,则可以用其IP地址标记它们吗?

您可以使用Spring Sleuth来跟踪不同REST调用之间的关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM