/// <summary> /// 测试队列化调用 /// </summary> static void TestInvokeQueue() { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); ESBProxy esbProxy = ESBProxy.GetInstance(); stopWatch.Stop(); Console.WriteLine("ESBProxy Init 耗时:{0}ms。", stopWatch.ElapsedMilliseconds);; Console.ReadKey(); stopWatch.Restart(); //esbProxy.InvokeQueue("ESB_Queue", "HelloWorld", "Tony", 0, new Core.Rpc.QueueParam() //{ // QueueName = "ERP.Order" //}); esbProxy.InvokeQueue("ESB_QUEUE_20", "HelloWorld", "Queue"); stopWatch.Stop(); Console.WriteLine("第1次调用 耗时:{0}ms。", stopWatch.ElapsedMilliseconds); Console.ReadKey(); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.ContentEncoding = Encoding.UTF8; if (context.Request["ServiceName"] == null || context.Request["MethodName"] == null) { context.Response.ContentType = "text/html"; context.Response.ContentEncoding = Encoding.UTF8; context.Response.Write(@"<head runat=""server""><title>ESB调用中心</title></head>"); context.Response.Write("<h1>错误:请传入正确的参数信息!</h1>"); context.Response.Write(@"<h2>示例:<a target=""_blank"" href=""ESB_InvokeService.ashx?ServiceName=ESB_ASHX&MethodName=HelloWorld&Message=Demo"">ESB_InvokeService.ashx?ServiceName=ESB_ASHX&MethodName=HelloWorld&Message=Demo</a></h2>"); } else { String serviceName = context.Request["ServiceName"].Trim(); String methodName = context.Request["MethodName"].Trim(); String isQueue = context.Request["IsQueue"]; String noCache = context.Request["NoCache"]; Int32 version = String.IsNullOrEmpty(context.Request["Version"]) ? 0 : Int32.Parse(context.Request["Version"]); String callback = context.Request["callback"]; String message = GetMessageFromRequest(context.Request); String consumerIP = context.Request.UserHostAddress; AdvanceInvokeParam aiParam = new AdvanceInvokeParam(); aiParam.ConsumerIP = consumerIP; //--判断是否需要强制弃用缓存 Int32 cache = 0; if (String.IsNullOrEmpty(noCache) || !Int32.TryParse(noCache, out cache) || cache < 1) { aiParam.NoCache = 0; } else { aiParam.NoCache = 1; } //--判断是否为队列调用 Int32 queue = 0; if (String.IsNullOrEmpty(isQueue) || !Int32.TryParse(isQueue, out queue) || queue < 1) { String response; try { response = esbProxy.Invoke(serviceName, methodName, message, version, aiParam); } catch (Exception ex) { response = String.Format("MBSOA-CallCenter-Error:{0}", ex.Message); } //--判断是否为JSONP调用 if (!String.IsNullOrEmpty(callback)) { response = String.Format(@"{0}({{message:""{1}""}})", callback, JsonEncoding(response)); } context.Response.Write(response); } else { String response; try { esbProxy.InvokeQueue(serviceName, methodName, message, version, aiParam); response = "OK"; } catch (Exception ex) { response = String.Format("MBSOA-CallCenter-Error:{0}", ex.Message); } //--判断是否为JSONP调用 if (!String.IsNullOrEmpty(callback)) { response = String.Format(@"{0}({{message:""{1}""}})", callback, JsonEncoding(response)); } context.Response.Write(response); } } }