Real-time monitoring of CAT tours ~ encapsulation of Get and post, support for distributed message trees

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.