欢迎访问 生活随笔!

尊龙游戏旗舰厅官网

当前位置: 尊龙游戏旗舰厅官网 > 编程资源 > 编程问答 >内容正文

编程问答

实时监控cat之旅~对get和post进行封装,支持分布式消息树 -尊龙游戏旗舰厅官网

发布时间:2025/1/21 编程问答 8 豆豆
尊龙游戏旗舰厅官网 收集整理的这篇文章主要介绍了 实时监控cat之旅~对get和post进行封装,支持分布式消息树 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

对第三方接口的调用我们需要对get和post进行监控,看一些请求的执行是否成功,如a调用b,b调用c,c调用d,这一连串的东西需要我们使用cat进行记录,进行记录之后,我们可以很容易的发现请求响应的时间及是否出错,下面是我对这两种请求的封装。

/// /// cat中使用的httpclient/// public class cathttpclient{/// /// 返回当前cat上下文/// /// static catcontext getcurrentcontext(string message){string currenturl = system.web.httpcontext.current.request.url.absoluteuri;var context = 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);});}return context;}/// /// post数据/// /// /// /// public static httpresponsemessage post(string requesturi, httpcontent content){var handler = new httpclienthandler() { };using (var http = new httpclient(handler)){purecat.catclient.setcatcontexttoserver(http, getcurrentcontext("post request sent..."));var response = http.postasync(requesturi, content).result;return response;}}/// /// get数据/// /// /// public static httpresponsemessage get(string requesturi){var handler = new httpclienthandler() { };using (var http = new httpclient(handler)){purecat.catclient.setcatcontexttoserver(http, getcurrentcontext("get request sent..."));//设置接口api的头,发送var response = http.getasync(requesturi).result;return response;}}}

在程序中使用非常方便,如下代码,一看便知

[allowanonymous]public void step1(){lind.ddd.catclientpur.cathttpclient.get("http://localhost:4829/admincommon/step2");}[allowanonymous]public void step2(){lind.ddd.catclientpur.cathttpclient.get("http://localhost:4829/admincommon/step3");}[allowanonymous]public void step3(){lind.ddd.catclientpur.cathttpclient.get("http://localhost:4829/admincommon/step4");}[allowanonymous]public void step4(){lind.ddd.catclientpur.cathttpclient.get("http://localhost:4829/admincommon/error");}

而它产生的消息树也是我们希望看到的,即从step1到step4的记录,如图

下一讲我们将读一下,如何对一个请求从开始到结束进行cat的监控,敬请期待!

转载于:https://www.cnblogs.com/lori/p/5316343.html

总结

以上是尊龙游戏旗舰厅官网为你收集整理的实时监控cat之旅~对get和post进行封装,支持分布式消息树的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得尊龙游戏旗舰厅官网网站内容还不错,欢迎将尊龙游戏旗舰厅官网推荐给好友。

网站地图