コード例 #1
0
        /// <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);
            });
        }
コード例 #2
0
ファイル: ESBProxy.cs プロジェクト: rebider/soa
        /// <summary>
        /// 请求响应调用-队列化
        /// </summary>
        /// <param name="serviceName">服务名称</param>
        /// <param name="methodName">方法名称</param>
        /// <param name="message">消息内容</param>
        /// <param name="version">服务版本:0代表调用默认版本</param>
        /// <returns></returns>
        public void InvokeQueue(String serviceName, String methodName, String message, Int32 version = 0, AdvanceInvokeParam invokeParam = null)
        {
            //--从ESBConfig中获取到服务版本信息
            ServiceItem si = GetServiceItem(serviceName, version);

            //--从ESBConfig中获取到服务配置信息
            EsbView_ServiceConfig sc = this.ESBConfig.GetServiceConfig(serviceName, GetMethodName(methodName));

            if (String.IsNullOrWhiteSpace(sc.QueueCenterUri))
            {
                throw new Exception("服务需要在管理中心配置队列服务地址才能通过队列调用!");
            }

            QueueMessage qm = new QueueMessage();

            qm.ConsumerAppName = m_ConsumerConfig.ApplicationName;

            if (invokeParam != null && !String.IsNullOrEmpty(invokeParam.ConsumerIP))
            {
                qm.ConsumerIP = invokeParam.ConsumerIP;
            }
            else
            {
                qm.ConsumerIP = m_ConfigurationManager.LocalIP;
            }

            qm.ServiceName = serviceName;
            qm.MethodName  = methodName;
            qm.Message     = message;
            qm.Version     = version;


            m_MessageQueueClient.SendToInvokeQueue(qm);
        }
コード例 #3
0
ファイル: ESBProxy.cs プロジェクト: rebider/soa
        /// <summary>
        /// 请求响应调用
        /// </summary>
        /// <param name="serviceName">服务名称</param>
        /// <param name="methodName">方法名称</param>
        /// <param name="message">消息内容</param>
        /// <param name="version">服务版本:0代表调用默认版本</param>
        /// <returns></returns>
        public String Invoke(String serviceName, String methodName, String message, Int32 version = 0, AdvanceInvokeParam invokeParam = null)
        {
            DateTime reqStartTime = DateTime.Now;

            String hostName = m_ConsumerConfig.ApplicationName;

            if (invokeParam != null && !String.IsNullOrWhiteSpace(invokeParam.ConsumerAppName))
            {
                hostName = invokeParam.ConsumerAppName;
            }

            ESB.Core.Schema.务请求 req = new ESB.Core.Schema.务请求();
            req.务名称  = serviceName;
            req.方法名称 = methodName;
            req.请求时间 = reqStartTime;
            req.主机名称 = hostName;
            req.消息内容 = message;
            req.消息编码 = "";
            req.密码   = "";

            //--从ESBConfig中获取到服务版本信息
            ServiceItem si = GetServiceItem(serviceName, version);

            //--从ESBConfig中获取到服务版本信息
            EsbView_ServiceConfig sc = this.ESBConfig.GetServiceConfig(serviceName, GetMethodName(methodName));
            String msg = EsbClient.DynamicalCallWebService(true, req, si.Binding, si.Version, sc, invokeParam).消息内容;

            return(msg);
        }
コード例 #4
0
ファイル: ESB_InvokeService.ashx.cs プロジェクト: rebider/soa
        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);
                }
            }
        }