Scala Futures-当threadId不相关时跟踪请求上下文 [英] scala futures - keeping track of request context when threadId is irrelevant
问题描述
在Web服务器(目前仍为Jetty/synchronous ::)中使用Scala Promise/futures进行第一步,正如预期的那样,threadId不再对跟踪单个HTTP请求处理期间发生的情况有用.
making first steps using Scala promises/futures in a web server (still Jetty/synchronous for now :( ), as expected the threadId is no longer useful for tracking what happened during a single HTTP request processing.
我想记录请求令牌将解决问题-这是推荐的方法吗?如果可以的话,您可以让我参考已经做过的一些代码吗?
I guess logging a request token will do the trick - is this the recommended approach? if so can you refer me to some code already doing that?
推荐答案
在这种情况下,我的方法是让一个案例类保存上下文数据(例如请求ID),并将其作为
My approach in such situation is to have a case class that holds contextual data (such as request id) and pass it throught all layers of your application as implicit
parameter.
这篇关于Scala Futures-当threadId不相关时跟踪请求上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!