如何在不将其添加到所有方法调用的情况下通过各个类中的相关性ID传递?
我正在使用Java Spring Boot,并且我的代码有一个六边形 /端口和适配器结构。
我试图在我的记录中设置相关ID。我的理解是,我的API网关应为每个请求生成一个唯一的ID,然后在API调用中传递该ID。然后,我需要确保所有后续的内部API调用也将此相关ID传递到周围,并将其包含在所有记录中。
但是,由于端口和适配器在代码中分配,我如何将此ID从端口侧传递到适配器侧,而无需更改所有临时业务逻辑以在所有方法调用中包含此ID?
I’m using Java Spring Boot and I have a hexagonal / ports and adaptors structure to my code.
Im trying to set up correlation IDs in my logging. My understanding is that my API gateway should generate a unique ID for each request then pass that in the API call. I need to then make sure all subsequent internal API calls also pass this correlation ID around and include it in all logging.
But since the port and adapters are split in the code, how can I pass this ID from the port side to the adaptor side without changing all the interim business logic to include this ID in all method calls?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以使用Spring-Cloud-Starter-Sleuth,可以从开箱即用,只需添加此依赖项,然后您将在所有服务,网关和Spanid中都具有TraceID-Common-uniquer-keraliation-唯一相关性是每个微服务。您可以在主题分布式跟踪中阅读有关它的更多信息。
Spring-cloud-starter-sleuth is available which supports this out of the box,just add this dependency and then you would have traceId-common across all services and gateway and spanId - unique correlation is per microservice. You can read more about it in topic distributed tracing.