protected override string DoEsbAction(string esbAction, string request) { esbProxy.Invoke("ESB_COMPOSIT", "CompositAction", "Hello Composit!"); esbProxy.Invoke("ESB_WS", "WebServiceAction", "Hello Composit!"); return(String.Format("收到参数:{0}={1}。", esbAction, request)); }
protected override string DoEsbAction(string esbAction, string request) { String message1 = esbProxy.Invoke("ESB_WCF", "WCF_ACTION", "HelloWCF"); String message2 = esbProxy.Invoke("ESB_ASHX", "ASHX_ACTION", "HelloWCF"); return(String.Format("收到参数:{0}={1}。", esbAction, request)); }
/// <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"); esbProxy.Invoke("ESB_ASHX", "HelloAction", "Hello World"); stopWatch.Stop(); Console.WriteLine("第1次调用 耗时:{0}ms。", stopWatch.ElapsedMilliseconds); Console.ReadKey(); }
static void TestEsbProxy(String serviceName, String methodName = "HelloAction", String message = null, int callNum = 10, Int32 version = 0) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); ESBProxy esbProxy = ESBProxy.GetInstance(); stopWatch.Stop(); Console.WriteLine("ESBProxy Init 耗时:{0}ms。", stopWatch.ElapsedMilliseconds);; Console.ReadKey(); stopWatch.Restart(); String msgBody = (message == null) ? new String('A', 1024 * 10) : message; try { String response = esbProxy.Invoke(serviceName, methodName, msgBody, version); } catch (Exception ex) { Console.WriteLine("调用总线发生异常:" + ex.Message); } stopWatch.Stop(); Console.WriteLine("第1次调用 耗时:{0}ms。", stopWatch.ElapsedMilliseconds); Console.ReadKey(); Int64 elapsedMS = 0; for (int i = 0; i < callNum; i++) { stopWatch.Restart(); String ret = esbProxy.Invoke(serviceName, methodName, msgBody, version); stopWatch.Stop(); elapsedMS += stopWatch.ElapsedMilliseconds; Console.WriteLine("第{0}次调用 耗时:{1}ms。", i + 2, stopWatch.ElapsedMilliseconds); } Console.WriteLine("排除第一次后 {0} 平均耗时:{1}ms。", callNum, elapsedMS / callNum); Console.ReadKey(); }
public HelloResponse Any(Hello request) { String response = esbProxy.Invoke("ESB_COM_WS", "HelloAction", "Hello From ServiceStack!"); return(new HelloResponse { Result = "Hello, {0}!".Fmt(request.Name) }); }
/// <summary> /// 处理队列调用消息 /// </summary> public void ProcessInvokeQueueMessage() { //--#代表ESB专用队列 m_RabbitMQ.ListenInvokeQueue(m_ServiceName, x => { AdvanceInvokeParam invokeParam = new AdvanceInvokeParam(); invokeParam.ConsumerAppName = x.ConsumerAppName; invokeParam.ConsumerIP = x.ConsumerIP; invokeParam.IsQueue = 1; m_ESBProxy.Invoke(x.ServiceName, x.MethodName, x.Message, x.Version, invokeParam); }); }
static void Main(string[] args) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); ESBProxy esbProxy = ESBProxy.GetInstance(); stopWatch.Stop(); Console.WriteLine("ESBProxy Init 耗时:{0}ms。", stopWatch.ElapsedMilliseconds); Console.ReadKey(); stopWatch.Restart(); String message = esbProxy.Invoke("WXSC_WeiXinServiceForApp", "GET:XML:CollocationDetailFilter", "collocationId=11"); 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); } } }