コード例 #1
0
        private static bool frMo_ReceiveMessage(RabbitMQHelper mq, string message)
        {
            throw new NotImplementedException();
            //MOSMS mo = null;
            //try
            //{
            //    mo = JsonSerialize.Instance.Deserialize<MOSMS>(message);

            //    if (string.IsNullOrWhiteSpace(mo.SPNumber))
            //    {
            //        //如果spNumber 是空,那么从最近给该用户发短信的记录里找
            //        var rl = CacheStatisticsReport.Instance.GetStatistics(DateTime.Now.AddDays(-3), DateTime.Now.AddDays(1));
            //        var n = rl.FirstOrDefault(r => r.Telephones.Contains(mo.UserNumber));
            //        if (n != null)
            //        {
            //            mo.SPNumber = n.SPNumber;
            //        }
            //    }

            //    DeliverMODB.Add(mo);
            //    CacheMOSMS.Instance.Set(mo);
            //}
            //catch (Exception ex)
            //{
            //    LogClient.LogHelper.LogError("StatusReport", "StatusReportHost.frMo_ReceiveMessage", ex.ToString());
            //}
            return(true);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Console.Title = "状态报告服务";
            ShieldingCloseButton();

            Console.WriteLine(DateTime.Now.ToString() + " Starting the server!");

            Console.WriteLine(DateTime.Now.ToString() + " Initialize the server ...");
            RemotingConfiguration.Configure("StatusReportHost.exe.config", false);

            frReport = new RabbitMQHelper(AppConfig.MQHost, AppConfig.MQVHost, AppConfig.MQUserName, AppConfig.MQPassword);
            frReport.OnSubsribeMessageRecieve += frReport_ReceiveMessage;
            frReport.SubsribeMessage("Report");

            frMo = new RabbitMQHelper(AppConfig.MQHost, AppConfig.MQVHost, AppConfig.MQUserName, AppConfig.MQPassword);
            frMo.OnSubsribeMessageRecieve += frMo_ReceiveMessage;
            frMo.SubsribeMessage("MOSend");

            frMo = new RabbitMQHelper(AppConfig.MQHost, AppConfig.MQVHost, AppConfig.MQUserName, AppConfig.MQPassword);
            frSMSOriginal.OnSubsribeMessageRecieve += frSMSOriginal_ReceiveMessage;
            frMo.SubsribeMessage("SMSOriginal");

            Console.WriteLine(DateTime.Now.ToString() + " Initialize the server ok.");
            Console.WriteLine(DateTime.Now.ToString() + " Started the server ok.");
            Console.WriteLine();
            Console.WriteLine("Press input 'quit' to stop it!");

            do
            {
            } while (Console.ReadLine() != "quit");

            Console.WriteLine("The server was stopped,press any key to exit!");
            Console.ReadKey();
            Environment.Exit(0);
        }
コード例 #3
0
        static bool frReport_ReceiveMessage(RabbitMQHelper mq, string message)
        {
            StatusReport sr = null;

            try
            {
                sr = JsonSerialize.Instance.Deserialize <StatusReport>(message);
            }
            catch (Exception ex)
            {
                LogClient.LogHelper.LogError("StatusReport", "StatusReportHost.frReport_ReceiveMessage", ex.ToString());
            }
            int status = sr.StatusCode - (sr.StatusCode / 1000) * 1000;

            if (status < 100)
            {
                GatewaySend(sr);
            }
            else if (status < 200)
            {
                GatewayResponse(sr);
            }

            return(true);
        }
コード例 #4
0
ファイル: Global.asax.cs プロジェクト: a8175610/RabbitMqTest
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            //启用监听
            RabbitMQHelper.Listening <Student>("testExchange", "testQueue", student =>
            {
                var resultData = "选课成功...";
                try
                {
                    //模拟耗时操作...
                    Thread.Sleep(50);

                    //存储结果,如果已有对应的key,则覆盖
                    StoreHelper.AddOrUpdate(student.StudentId, resultData);
                    return(true);
                }
                catch (Exception e)
                {
                    //存储结果,如果已有对应的key,则覆盖
                    StoreHelper.AddOrUpdate(student.StudentId, resultData);
                    return(false);
                }
            });
        }
コード例 #5
0
ファイル: MOMQHelper.cs プロジェクト: aspdotnetmvc/mvc
        private bool OnMessageRecieve(RabbitMQHelper mq, string message)
        {
            var mo = JsonConvert.DeserializeObject <List <MOSMS> >(message);

            Gateway.MORecieved(mo);
            return(true);
        }
コード例 #6
0
 private static bool accountBlacklist_ReceiveMessage(RabbitMQHelper mq, string message)
 {
     try
     {
         string[] blData = message.Split((char)2);
         if (blData[0] == "Add")
         {
             //添加黑名单
             List <string> list = new List <string>();
             for (int i = 1; i < blData.Length; i++)
             {
                 list.Add(blData[i]);
             }
             BlacklistManager.Instance.Add(list);
         }
         if (blData[0] == "Dec")
         {
             //删除黑名单
             List <string> list = new List <string>();
             for (int i = 1; i < blData.Length; i++)
             {
                 list.Add(blData[i]);
             }
             BlacklistManager.Instance.Del(list);
         }
     }
     catch (Exception ex)
     {
         LogHelper.LogError("SendQueue", "SendQueueHost.accountBlacklist_ReceiveMessage", ex.ToString());
     }
     return(true);
 }
コード例 #7
0
        public void SendMessage(Payment message)
        {
            IModel model = RabbitMQHelper.CreateRabbitMqModel();

            model.BasicPublish("", QueueName, false, null, message.Serialize());
            Debug.WriteLine($"Payment Message Sent: {message.CardNumber}, {message.AmountToPay}");
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: aspdotnetmvc/mvc
        static void Main(string[] args)
        {
            Console.Title = "LogHost";
            ShieldingCloseButton();

            Console.WriteLine(DateTime.Now.ToString() + " Start the server!");
            RemotingConfiguration.Configure("LogHost.exe.config", false);
            Console.WriteLine();
            Console.WriteLine("Press input 'quit' to stop it!");
            RabbitMQHelper fr = new RabbitMQHelper(ConfigurationManager.AppSettings["MQHost"],
                                                   ConfigurationManager.AppSettings["MQHost"],
                                                   ConfigurationManager.AppSettings["MQUserName"],
                                                   ConfigurationManager.AppSettings["MQPassword"]);

            fr.OnSubsribeMessageRecieve += fr_ReceiveMessage;
            fr.SubsribeMessage(ConfigurationManager.AppSettings["Channel"]);
            Thread thread = new Thread(new ThreadStart(CreateSubmeter));

            thread.Start();

            do
            {
            } while (Console.ReadLine() != "quit");
            Console.WriteLine("The server was stopped,press any key to exit!");
            Console.ReadKey();
            Environment.Exit(0);
        }
コード例 #9
0
        public ActionResult SelectCheckEnabled(string keyValue, bool status)
        {
            var data = earlywarningmanagebll.GetEntity(keyValue);

            if (data != null)
            {
                if (status)
                {
                    data.Isenable = 1;
                }
                else
                {
                    data.Isenable = 0;
                }
                earlywarningmanagebll.SaveForm(keyValue, data);

                //将信息同步到后台计算服务中
                RabbitMQHelper rh = RabbitMQHelper.CreateInstance();
                SendData       sd = new SendData();
                sd.DataName     = "UpdateEarlywarningmanageEntity";
                sd.EntityString = JsonConvert.SerializeObject(data);
                rh.SendMessage(JsonConvert.SerializeObject(sd));
            }
            return(Success("操作成功。"));
        }
コード例 #10
0
        public static void CreateTaskQueue()
        {
            IModel channel = RabbitMQHelper.CreateRabbitMqModel();

            channel.QueueDeclare(QueueName, true, false, false, null);
            var consumer = new EventingBasicConsumer(channel);

            //Fair dispatch
            //You might have noticed that the dispatching still doesn't work exactly as we want.
            //For example in a situation with two workers, when all odd messages are heavy and even messages are light,
            //one worker will be constantly busy and the other one will do hardly any work. Well,
            //RabbitMQ doesn't know anything about that and will still dispatch messages evenly.
            //this happens because RabbitMQ just dispatches a message when the message enters the queue.
            //It doesn't look at the number of unacknowledged messages for a consumer.
            //It just blindly dispatches every n-th message to the n-th consumer.
            //In order to change this behavior we can use the ***BasicQos*** method with the ***prefetchCount = 1*** setting.
            //This tells RabbitMQ not to give more than one message to a worker at a time. Or, in other words,
            //don't dispatch a new message to a worker until it has processed and acknowledged the previous one.
            //Instead, it will dispatch it to the next worker that is not still busy.
            channel.BasicQos(0, 1, false);
            uint total = channel.MessageCount(QueueName);

            consumer.Received += (ch, ea) =>
            {
                channel.BasicAck(ea.DeliveryTag, false);
            };

            channel.BasicConsume(QueueName, false, consumer);
        }
コード例 #11
0
ファイル: MOHelper.cs プロジェクト: aspdotnetmvc/mvc
 public void StartMOService()
 {
     frMo = new RabbitMQHelper(AppConfig.MQHost, AppConfig.MQVHost, AppConfig.MQUserName, AppConfig.MQPassword);
     frMo.OnSubsribeMessageRecieve += frMo_ReceiveMessage;
     frMo.SubsribeMessage("MOSend");
     MOCache.Instance.LoadMOCache();
 }
コード例 #12
0
        public static IMQHelper Create(MQConnect connect)
        {
            // 根据配置切换MQ
            RabbitMQHelper Helper = new RabbitMQHelper(connect);

            return(Helper);
        }
コード例 #13
0
ファイル: Program.cs プロジェクト: aspdotnetmvc/mvc
        static void Main(string[] args)
        {
            Console.Title = "SendQueueHost";
            ShieldingCloseButton();

            Console.WriteLine(DateTime.Now.ToString() + " Starting the server ...");
            Console.WriteLine(DateTime.Now.ToString() + " Loading the config ...");

            Console.WriteLine(DateTime.Now.ToString() + " Loading the config ok.");
            Console.WriteLine(DateTime.Now.ToString() + " Loading the cache ...");
            Console.WriteLine(DateTime.Now.ToString() + " Loading the cache ok.");
            Console.WriteLine(DateTime.Now.ToString() + " Initialize the server ...");
            accountBlacklist = new RabbitMQHelper(AppConfig.MQHost, AppConfig.MQVHost, AppConfig.MQUserName, AppConfig.MQPassword);
            accountBlacklist.OnSubsribeMessageRecieve += accountBlacklist_ReceiveMessage;
            accountBlacklist.SubsribeMessage("Blacklist", AppConfig.MaxPriority);

            SMSMQHelper = new RabbitMQHelper(AppConfig.MQHost, AppConfig.MQVHost, AppConfig.MQUserName, AppConfig.MQPassword);
            accountBlacklist.OnSubsribeMessageRecieve += SMSMQHelper_RecieveMessage;
            accountBlacklist.SubsribeMessage("SendQueue", AppConfig.MaxPriority);

            Console.WriteLine(DateTime.Now.ToString() + " Initialize the server ok.");
            Console.WriteLine(DateTime.Now.ToString() + " Started the server ok.");
            Console.WriteLine();
            Console.WriteLine("Press input 'quit' to stop it!");

            do
            {
            } while (Console.ReadLine() != "quit");
            SMSMQHelper.Close();
            accountBlacklist.Close();
            Console.WriteLine("The server was stopped!");

            Console.ReadKey();
            Environment.Exit(0);
        }
コード例 #14
0
ファイル: MOHelper.cs プロジェクト: aspdotnetmvc/mvc
 private bool frMo_ReceiveMessage(RabbitMQHelper mq, string message)
 {
     try
     {
         var mo = JsonConvert.DeserializeObject <MOSMS>(message);
         //找到给发短信的记录
         var sms = StatusReportDB.GetSMSForMO(mo.Gateway, mo.ReceiveTime, mo.UserNumber);
         if (sms != null)
         {
             if (string.IsNullOrWhiteSpace(mo.SPNumber))
             {
                 mo.SPNumber = sms.SPNumber;
             }
             mo.AccountID = sms.AccountID;
         }
         DeliverMODB.Add(mo);
         MOCache.Instance.AddMOCache(mo);
         return(true);
     }
     catch (Exception ex)
     {
         LogClient.LogHelper.LogError("SendQueue", "frMo_ReceiveMessage", ex.ToString());
         return(true);
     }
 }
コード例 #15
0
        public OkResult Notification()
        {
            RabbitMQHelper.init();
            RabbitMQHelper.publisher("competitionEndpointQueue", "*** Testantando API *****");

            return(Ok());
        }
コード例 #16
0
        public async Task <ActionResult> Edit(string taskId, [Bind("taskId,TaskName,TaskDesc,CronExpressionString,CronRemark,IsDce,TaskUrl,IsActive")] TaskModel task)
        {
            TaskModel taskModel = await DbContext.Task.FindAsync(Guid.Parse(taskId));

            if (taskModel == null)
            {
                return(APIReturn.BuildFail("记录不存在"));
            }
            taskModel.TaskName             = task.TaskName;
            taskModel.TaskDesc             = task.TaskDesc;
            taskModel.CronExpressionString = task.CronExpressionString;
            taskModel.CronRemark           = task.CronRemark;
            taskModel.IsDce    = task.IsDce;
            taskModel.TaskUrl  = task.TaskUrl;
            taskModel.IsActive = task.IsActive;
            DbContext.Task.Update(taskModel);
            await DbContext.SaveChangesAsync();

            ICache.SetList <TaskModel>("task_list", delegate()
            {
                return(DbContext.Task.ToArray());
            });
            RabbitMQHelper.PublishMessage(ConnectionFactory, GlobalVariable.EXCHANGE, taskModel.TaskKey, taskModel.TaskID.ToString());
            return(APIReturn.BuildSuccess("修改成功"));
        }
コード例 #17
0
        private bool OnMessageRecieve(RabbitMQHelper mq, string message)
        {
            var sr = JsonConvert.DeserializeObject <List <StatusResult> >(message);

            Gateway.StatusReportRecieved(sr);
            return(true);
        }
コード例 #18
0
ファイル: Program.cs プロジェクト: aspdotnetmvc/mvc
        static void Main(string[] args)
        {
            Console.Title = "SMSPlatformHost";
            ShieldingCloseButton();

            Console.WriteLine(DateTime.Now.ToString() + " Starting the server!");
            Console.WriteLine(DateTime.Now.ToString() + " Loading the cache ...");
            AccountServer.Instance.LoadAccountCache();
            Console.WriteLine(DateTime.Now.ToString() + " Loading the cache ok.");
            Console.WriteLine(DateTime.Now.ToString() + " Initialize the server ...");
            RemotingConfiguration.Configure("SMSPlatformHost.exe.config", false);
            Console.WriteLine(DateTime.Now.ToString() + " Initialize the server ok.");
            Console.WriteLine(DateTime.Now.ToString() + " Started the server ok.");


            RabbitMQHelper fr = new RabbitMQHelper(AppConfig.MQHost, AppConfig.MQVHost, AppConfig.MQUserName, AppConfig.MQPassword);

            fr.OnSubsribeMessageRecieve += fr_ReceiveMessage;
            fr.SubsribeMessage(AppConfig.MQChannel);

            Console.WriteLine();
            Console.WriteLine("Press input 'quit' to stop it!");
            do
            {
            } while (Console.ReadLine() != "quit");
            Console.WriteLine("The server was stopped!");
            Console.ReadKey();
            Environment.Exit(0);
        }
コード例 #19
0
 public KeywordLoad(string gateway)
 {
     _gateway = gateway;
     fr       = new RabbitMQHelper(AppConfig.MQHost, AppConfig.MQVHost, AppConfig.MQUserName, AppConfig.MQPassword);
     fr.OnSubsribeMessageRecieve += fr_ReceiveMessage;
     fr.SubsribeMessage("Keyword_" + gateway);
 }
コード例 #20
0
 public void StartStatusService()
 {
     frReport = new RabbitMQHelper(AppConfig.MQHost, AppConfig.MQVHost, AppConfig.MQUserName, AppConfig.MQPassword);
     frReport.OnSubsribeMessageRecieve += frReport_ReceiveMessage;
     frReport.SubsribeMessage("Report");
     StatusReportCache.Instance.LoadStatusReportCache();
 }
コード例 #21
0
ファイル: Program.cs プロジェクト: aspdotnetmvc/mvc
 static bool fr_ReceiveMessage(RabbitMQHelper mq, string message)
 {
     string[] msgs = message.Split((char)0x1d);
     Log.Write(msgs[0].ToString(), msgs[1].ToString(), msgs[2].ToString(), msgs[3].ToString(), msgs[4].ToString(), msgs[5].ToString(), DateTime.Now.ToString());
     Console.WriteLine(DateTime.Now.ToString() + " : Message --> " + msgs[0] + " , " + msgs[1] + " , " + msgs[2] + " , " + msgs[3] + " , " + msgs[4] + " , " + msgs[5]);
     Console.WriteLine();
     return(true);
 }
コード例 #22
0
 public AccountController(IAccountService accountService, IHostingEnvironment environment, IMapper mapper, ICacheHelper cacheHelper, RabbitMQHelper rabbitMQHelper) : base(0)
 {
     this._accountService = accountService;
     this._environment    = environment;
     this._mapper         = mapper;
     this._cacheHelper    = cacheHelper;
     this._rabbitMQHelper = rabbitMQHelper;
 }
コード例 #23
0
 public ActionResult QueueUp(Student stu)
 {
     //先清空一次存储
     StoreHelper.Remove(stu.StudentId);
     //消息入队...
     RabbitMQHelper.Enqueue("testExchange", "testQueue", stu);
     return(Json(new { success = true, msg = "排队等待中..." }));
 }
コード例 #24
0
        /// <summary>
        /// 启动监听
        /// </summary>
        public void Start(HttpPushGateway gateway)
        {
            Gateway = gateway;

            StatusReportMQ = new RabbitMQHelper(AppConfig.MQHost, AppConfig.MQVHost, AppConfig.MQUserName, AppConfig.MQPassword);
            StatusReportMQ.OnSubsribeMessageRecieve += OnMessageRecieve;
            StatusReportMQ.SubsribeMessage(Gateway.Gateway.Config.GatewayName + "_SR");
        }
コード例 #25
0
        public JsonResult Edit(string id, Models.LableModel model)
        {
            var user = OperatorProvider.Provider.Current();

            model.LabelId = model.LabelId.PadLeft(6, '0');
            if (lablemanagebll.GetIsBind(model.LabelId))
            {
                return(Json(new AjaxResult {
                    type = ResultType.error, message = "标签已经绑定!"
                }));
            }
            if (!string.IsNullOrEmpty(model.UserId) && lablemanagebll.GetUserLable(model.UserId) != null)
            {
                return(Json(new AjaxResult {
                    type = ResultType.error, message = model.Name + "已经绑定!"
                }));
            }
            var entity = new LablemanageEntity()
            {
                ID                 = Guid.NewGuid().ToString(),
                DeptId             = model.DeptId,
                DeptCode           = model.DeptCode,
                DeptName           = model.DeptName,
                BindTime           = model.BindTime,
                CreateDate         = DateTime.Now,
                CreateUserDeptCode = user.DeptCode,
                CreateUserId       = user.UserId,
                ModifyDate         = DateTime.Now,
                ModifyUserId       = user.DeptId,
                CreateUserOrgCode  = user.OrganizeCode,
                IdCardOrDriver     = model.IdCardOrDriver,
                IsBind             = 1,
                LableId            = model.LabelId,
                LableTypeName      = model.LableTypeName,
                LableTypeId        = model.LableTypeId,
                Name               = model.Name,
                OperUserId         = user.UserName,
                Phone              = model.Phone,
                Power              = "100%",
                Type               = 0,
                State              = "离线",
                UserId             = model.UserId
            };

            lablemanagebll.SaveForm(id, entity);
            if (string.IsNullOrEmpty(id))
            {
                //将标签信息同步到后台计算服务中
                RabbitMQHelper rh = RabbitMQHelper.CreateInstance();
                SendData       sd = new SendData();
                sd.DataName     = "LableEntity";
                sd.EntityString = JsonConvert.SerializeObject(entity);
                rh.SendMessage(JsonConvert.SerializeObject(sd));
            }
            return(Json(new AjaxResult {
                type = ResultType.success, message = "保存成功!"
            }));
        }
コード例 #26
0
ファイル: MQ.cs プロジェクト: aspdotnetmvc/mvc
        public MQ(string gateway)
        {
            GatewayName  = gateway;
            statusreport = new RabbitMQHelper(MQHost, MQVHost, MQUserName, MQPassword);
            statusreport.BindQueue(GatewayName + "_SR", MaxPriority, GatewayName + "_SR");

            mo = new RabbitMQHelper(MQHost, MQVHost, MQUserName, MQPassword);
            mo.BindQueue(GatewayName + "_MO", MaxPriority, GatewayName + "_MO");
        }
コード例 #27
0
ファイル: Program.cs プロジェクト: aspdotnetmvc/mvc
        static bool fr_ReceiveMessage(RabbitMQHelper mq, string message)
        {
            //处理上行短信

            PlatformService.ProcessMOSMS(message);


            return(true);
        }
コード例 #28
0
        public RabbitMQManager(IOptions<RabbitMQConfig> config)
        {
            if (config.Value == null || string.IsNullOrEmpty(config.Value.URL))
            {
                throw new ArgumentException("RabbitMQ configuration missing!");
            }

            helper = new RabbitMQHelper(config.Value.URL);
        }
コード例 #29
0
        public static bool StartWorkflowMessage(string message)
        {
            WriteInfoLog("发起流程的消息,message-->" + message);
            StartWorkflowParameter parameter = JsonConvert.DeserializeObject <StartWorkflowParameter>(message);

            Dictionary <string, object> dicPara = JsonConvert.DeserializeObject <Dictionary <string, object> >(JsonConvert.SerializeObject(parameter.ParamValues));

            dicPara.Add("id", parameter.id);

            NameValueCollection nvBody = new NameValueCollection();

            nvBody.Add("USER_CODE", parameter.UserCode);
            nvBody.Add("WORKFLOW_CODE", parameter.WorkflowCode);
            nvBody.Add("FINISH_START", parameter.FinishStart ? "1" : "0");
            nvBody.Add("INSTANCE_ID", "");
            nvBody.Add("PARAM_VALUES", JsonConvert.SerializeObject(dicPara));

            var ret = postFormData(url_startworkflow, new NameValueCollection(), nvBody);

            try
            {
                RestfulResult startworkflowResult = JsonConvert.DeserializeObject <RestfulResult>(ret);
                var           msg = new object();
                if (startworkflowResult.STATUS == "2")
                {
                    msg = new
                    {
                        id      = parameter.id,
                        type    = "startworkflow",
                        code    = "1",
                        data    = startworkflowResult.INSTANCE_ID,
                        message = startworkflowResult.MESSAGE
                    };
                }
                else
                {
                    msg = new
                    {
                        id      = parameter.id,
                        type    = "startworkflow",
                        code    = "-1",
                        data    = startworkflowResult.INSTANCE_ID,
                        message = startworkflowResult.MESSAGE
                    };
                }
                RabbitMQHelper rabbitMQHelper = new RabbitMQHelper(host, user, password);
                WriteInfoLog("写入h3_to_wxapp_response队列的消息:{0}", JsonConvert.SerializeObject(msg));
                rabbitMQHelper.SendMsg(JsonConvert.SerializeObject(msg), queue_h3_to_wxapp_response);
                WriteInfoLog("【完成】写入h3_to_wxapp_response队列的消息:{0}", JsonConvert.SerializeObject(msg));
            }
            catch (Exception ex)
            {
                return(false);
            }
            WriteInfoLog("监听中...");
            return(true);
        }
コード例 #30
0
        public void RabbitMQ_PushIntoQueue()
        {
            string exchangeName = "test_exchange";

            var helper  = new RabbitMQHelper(connection, exchangeName);
            var message = Encoding.UTF8.GetBytes("bob");

            helper.PushMessageIntoQueue(message, "Test123");
            server.Exchanges[exchangeName].Messages.Should().HaveCount(1);
        }