Calls to third-party interfaces We need to monitor the get and post to see if some of the execution of the request is successful, such as a call to B,b call C,c D, this series of things we need to use cat to record, after recording, we can easily find the request response time and error, Here is my encapsulation of these two types of requests.
/// <summary> ///httpclient used in Cat/// </summary> Public classcathttpclient {/// <summary> ///returns the current cat context/// </summary> /// <returns></returns> StaticCatcontext Getcurrentcontext (stringmessage) { stringCurrenturl =System.Web.HttpContext.Current.Request.Url.AbsoluteUri; varContext =PureCat.CatClient.GetCatContextFromServer (); if(Context = =NULL) {Context= PureCat.CatClient.DoTransaction ("Xuexiba", Currenturl, () ={PureCat.CatClient.LogEvent ("Xuexiba", Message,"0", Currenturl); }); } Else{Context= PureCat.CatClient.DoTransaction ("Xuexiba", Currenturl, () ={PureCat.CatClient.LogRemoteCallServer (context); PureCat.CatClient.LogEvent ("Xuexiba", Message,"0", Currenturl); }); } returncontext; } /// <summary> ///Post Data/// </summary> /// <param name= "RequestUri" ></param> /// <param name= "content" ></param> /// <returns></returns> Public StaticHttpresponsemessage Post (stringRequestUri, httpcontent content) { varHandler =NewHttpclienthandler () {}; using(varHTTP =NewHttpClient (handler)) {PureCat.CatClient.SetCatContextToServer (HTTP, Getcurrentcontext ("Post Request Sent ...")); varResponse =http. Postasync (RequestUri, content). Result; returnresponse; } } /// <summary> ///Get Data/// </summary> /// <param name= "RequestUri" ></param> /// <returns></returns> Public StaticHttpresponsemessage Get (stringRequestUri) { varHandler =NewHttpclienthandler () {}; using(varHTTP =NewHttpClient (handler)) {PureCat.CatClient.SetCatContextToServer (HTTP, Getcurrentcontext ("Get Request Sent ..."));//set the header of the interface API, send varResponse =http. Getasync (RequestUri). Result; returnresponse; } } }
It is very convenient to use in the program, the following code, a glance to know
[allowanonymous] Public voidStep1 () {Lind.DDD.CatClientPur.CatHttpClient.Get ("HTTP://LOCALHOST:4829/ADMINCOMMON/STEP2"); } [AllowAnonymous] Public voidStep2 () {Lind.DDD.CatClientPur.CatHttpClient.Get ("HTTP://LOCALHOST:4829/ADMINCOMMON/STEP3"); } [AllowAnonymous] Public voidStep3 () {Lind.DDD.CatClientPur.CatHttpClient.Get ("HTTP://LOCALHOST:4829/ADMINCOMMON/STEP4"); } [AllowAnonymous] Public voidStep4 () {Lind.DDD.CatClientPur.CatHttpClient.Get ("Http://localhost:4829/AdminCommon/Error"); }
And the message tree it produces is what we want to see, from Step1 to Step4 Records,
Next we will read how to monitor a request from the beginning to the end of the cat, so please look forward to it!
Real-time monitoring of CAT tours ~ encapsulation of Get and post, support for distributed message trees