我想跟踪单个操作的开始和结束。当接收方接收到100要求/秒时,我无法达到要求。请帮助
在第一个进程结束时,第二个进程进入并更改UUID值。
所以我无法跟踪单个消息/请求的开始和结束。
这不是Web应用程序,因此不能对Trace类使用“ reqest”作用域,我的应用程序是pub-sub模型。这是一个示例应用程序。
public class MainClass {
@Bean
@Autowired
public Receiver getEventHubReceiver(Trace trace, SomeOtherClass classex) {
return new Receiver(trace, classex);
}
}
@Component
class Trace{
String traceid;
public void setTraceid(String traceid) {
this.traceid = traceid;
}
public void trace(String msg){
System.out.println(traceid+" : Tracing : "+msg);
}
}
class Receiver{
private final SomeOtherClass classex;
private final Trace trace;
Receiver(Trace trace, SomeOtherClass classex){
this.trace= trace;
this.classex = classex;
}
//This is a callback method invoked by server internally.
public void receiver(){
trace.setTraceid(UUID.randomUUID().toString());
trace.trace("reached Receiver..started");
classex.invoke(); //==> I don't want to pass the Trace object here, same object should be used by multiple classes.
trace.trace("reached Receiver..completed");
}
}
class SomeOtherClass{
@Autowired
private Trace trace; // ==> ISSUE -- Behaving as a single ton.
public void invoke(){
trace.trace("Reached SomeOtherClass - started");
someLongRunProcess(); // it take almost 3-5 seconds to complete this.
trace.trace("Reached SomeOtherClass - completed");
}
private void someLongRunProcess() {
//DB invoke option
}
}
答案 0 :(得分:0)
您是否尝试过prototype
组件的Trace
范围?原型作用域应允许您为处理的每个请求创建一个新bean。有关更多信息,请参见this answer on prototype scope instantiation。