Beispiel #1
0
        static void publishUpgradeStatus(RabbitMqService rabbitMqProxy)
        {
            var beingIMEIINumber = 500000000000000;
            int loop             = 2;

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            string exchangeName             = "upgradestatus.exchange";
            string queueName = "upgradestatus_queue";

            try
            {
                sw.Start();
                Console.WriteLine("*****************消息发布开始******************");
                //升级任务详情ID;升级状态;IMEI;固件ID
                rabbitMqProxy.Publish(exchangeName, queueName, "", $"4377892;2;500000000000000;3612;0;VKEL_MT2503D_T100_1V0;FE00_2017/11/29;FE13");
                rabbitMqProxy.Publish(exchangeName, queueName, "", $"4377880;2;867282032269330;3612;0;VKEL_MT2503D_T100_1V0;FE00_2017/11/29;FE13");
                //rabbitMqProxy.Publish(exchangeName, queueName, "", $"3567095;2;500000000000000");
                System.Threading.Thread.Sleep(100);
                sw.Stop();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.WriteLine("总耗时:" + sw.Elapsed.Milliseconds);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var rabbitMqProxy = new RabbitMqService(new MqConfig
            {
                AutomaticRecoveryEnabled = true,
                HeartBeat = 60,
                NetworkRecoveryInterval = new TimeSpan(60),
                Host     = "localhost",
                UserName = "******",
                Password = "******"
            });

            var input = Input();

            while (input != "exit")
            {
                var log = new MessageModel
                {
                    CreateDateTime = DateTime.Now,
                    Msg            = input
                };
                rabbitMqProxy.Publish(log);

                input = Input();
            }

            rabbitMqProxy.Dispose();
        }
Beispiel #3
0
        public static void PublishTest()
        {
            var rabbitMqProxy = new RabbitMqService(new MqConfig
            {
                AutomaticRecoveryEnabled = true,
                HeartBeat = 60,
                NetworkRecoveryInterval = new TimeSpan(60),
                Host        = "192.168.2.8",
                UserName    = "******",
                Password    = "******",
                VirtualHost = "PaymentVHost"
            });

            while (true)
            {
                Thread.Sleep(1000);
                var input = Guid.NewGuid().ToString();
                rabbitMqProxy.Publish(new MessageModel
                {
                    Msg            = input,
                    CreateDateTime = DateTime.Now
                });
            }
            Console.ReadLine();
        }
Beispiel #4
0
        static void publishSendReply(RabbitMqService rabbitMqProxy)
        {
            var beingIMEIINumber = 500000000000000;
            int loop             = 100;

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            string exchangeName             = "terreply.exchange";
            string queueName = "terreply_queue";

            try
            {
                sw.Start();
                Console.WriteLine("*****************消息发布开始******************");
                string imei  = string.Empty;
                int    logId = 0;
                for (int i = 0; i < loop; i++)
                {
                    for (int k = 0; k < 2; k++)
                    {
                        logId++;
                        //rabbitMqProxy.Publish(exchangeName, queueName,"",GetSendReplyStr((beingIMEIINumber+i).ToString(), logId));
                        rabbitMqProxy.Publish(exchangeName, queueName, "", GetSendReplyStr((beingIMEIINumber + i).ToString(), logId));
                    }
                }

                System.Threading.Thread.Sleep(100);
                sw.Stop();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.WriteLine("总耗时:" + sw.Elapsed.Milliseconds);
        }
Beispiel #5
0
 /// <summary>
 /// 发布消息到RabbitMQ
 /// </summary>
 /// <param name="msg"></param>
 public static void PublishMessage(MessageModel msg)
 {
     var ts = Task.Factory.StartNew(() =>
     {
         string MQHost    = new DataItemDetailBLL().GetItemValue("host", "MQConfig");    // MQ主机地址
         string MQUser    = new DataItemDetailBLL().GetItemValue("user", "MQConfig");    // MQ用户
         string MQPwd     = new DataItemDetailBLL().GetItemValue("pwd", "MQConfig");     // MQ密码
         string isPush    = new DataItemDetailBLL().GetItemValue("ispush", "MQConfig");  //是否推送
         string MQVirHost = new DataItemDetailBLL().GetItemValue("virhost", "MQConfig"); //MQ虚拟主机名称
         string port      = new DataItemDetailBLL().GetItemValue("port", "MQConfig");    //端口号
         port             = string.IsNullOrWhiteSpace(port) ? "5672" : port;
         if (isPush == "1")
         {
             if (!string.IsNullOrWhiteSpace(MQHost))
             {
                 var rabbitMqProxy = new RabbitMqService(new MqConfig
                 {
                     AutomaticRecoveryEnabled = true,
                     HeartBeat = 60,
                     NetworkRecoveryInterval = new TimeSpan(60),
                     Host        = MQHost,
                     UserName    = MQUser,
                     Password    = MQPwd,
                     VirtualHost = MQVirHost,
                     Port        = int.Parse(port)
                 });
                 rabbitMqProxy.Publish(msg);
             }
         }
     });
 }
Beispiel #6
0
        public void TestRabbitMq()
        {
            RabbitMqConfig rabbitMqConfig = new RabbitMqConfig
            {
                Host     = "10.10.10.110",
                UserName = "******",
                Password = "******",
            };
            RabbitMqService rabbitMqService = new RabbitMqService(rabbitMqConfig);

            Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    rabbitMqService.Publish("test-exchange", "test-queue", "test-exchange", "{\"Data\":\"啊实打实大苏打实打实打算大苏打\"}");
                    System.Threading.Thread.Sleep(1000);
                }
            });

            Task.Factory.StartNew(() =>
            {
                rabbitMqService.Subscribe <object>("test-queue", false, t =>
                {
                    var msg = JsonConvert.SerializeObject(t);
                    Debug.WriteLine($"时间:{DateTime.Now},当前消息内容:{msg}");
                    System.Threading.Thread.Sleep(1000);
                }, false);
            });
            while (true)
            {
            }
        }
Beispiel #7
0
        public JsonResult TestSendMsg(string Msg)
        {
            var rabbitMqProxy = new RabbitMqService(new MqConfig
            {
                AutomaticRecoveryEnabled = true,
                HeartBeat = TimeSpan.FromTicks(60),
                NetworkRecoveryInterval = new TimeSpan(60),
                Host     = "127.0.0.1",
                UserName = "******",
                Password = "******"
            });
            var log = new MessageModel
            {
                CreateDateTime = DateTime.Now,
                Msg            = Msg
            };

            rabbitMqProxy.Publish(log);
            //rabbitMqProxy.Dispose();
            return(Result(true));
        }
Beispiel #8
0
 /// <summary>
 /// 发布消息到RabbitMQ
 /// </summary>
 /// <param name="msg"></param>
 public static void PublicMessage(MessageEntity msg)
 {
     var ts = Task.Factory.StartNew(() => {
         string MQHost    = new DataItemDetailBLL().GetItemValue("host", "MQConfig");    // MQ主机地址
         string MQUser    = new DataItemDetailBLL().GetItemValue("user", "MQConfig");    // MQ用户
         string MQPwd     = new DataItemDetailBLL().GetItemValue("pwd", "MQConfig");     // MQ密码
         string isPush    = new DataItemDetailBLL().GetItemValue("ispush", "MQConfig");  //是否推送
         string MQVirHost = new DataItemDetailBLL().GetItemValue("virhost", "MQConfig"); //MQ虚拟主机名称
         string port      = new DataItemDetailBLL().GetItemValue("port", "MQConfig");    //端口号
         port             = string.IsNullOrWhiteSpace(port) ? "5672" : port;
         if (isPush == "1")
         {
             if (!string.IsNullOrWhiteSpace(MQHost))
             {
                 var rabbitMqProxy = new RabbitMqService(new MqConfig
                 {
                     AutomaticRecoveryEnabled = true,
                     HeartBeat = 60,
                     NetworkRecoveryInterval = new TimeSpan(60),
                     Host        = MQHost,
                     UserName    = MQUser,
                     Password    = MQPwd,
                     VirtualHost = MQVirHost,
                     Port        = int.Parse(port)
                 });
                 var data = new MessageModel
                 {
                     Content     = msg.Content,
                     Category    = msg.Category,
                     ReciverUser = msg.UserId,
                     SendTime    = DateTime.Now,
                     Title       = msg.Title,
                     SendUser    = msg.SendUserName,
                     Remark      = msg.Remark
                 };
                 rabbitMqProxy.Publish(data);
             }
         }
     });
 }
Beispiel #9
0
        /// <summary>
        /// 发布消息到队列
        /// </summary>
        /// <param name="obj">消息对象</param>
        /// <param name="mode">对象类型:0>部门,1>用户</param>
        public static void PushMessage(object obj, int mode, string queuePrefix = "")
        {
            string name = "";

            if (string.IsNullOrWhiteSpace(queuePrefix))
            {
                queuePrefix = "xldms";
            }
            if (mode == 0)
            {
                name = string.Format("{0}.dept", queuePrefix);
            }
            if (mode == 1)
            {
                name = string.Format("{0}.user", queuePrefix);
            }
            string MQHost    = new DataItemDetailBLL().GetItemValue("host", "MQConfig");    // MQ主机地址
            string MQUser    = new DataItemDetailBLL().GetItemValue("user", "MQConfig");    // MQ用户
            string MQPwd     = new DataItemDetailBLL().GetItemValue("pwd", "MQConfig");     // MQ密码
            string isPush    = new DataItemDetailBLL().GetItemValue("ispush", "MQConfig");  //是否推送
            string MQVirHost = new DataItemDetailBLL().GetItemValue("virhost", "MQConfig"); //MQ虚拟主机名称
            string port      = new DataItemDetailBLL().GetItemValue("port", "MQConfig");    //端口号

            port = string.IsNullOrWhiteSpace(port) ? "5672" : port;
            if (!string.IsNullOrWhiteSpace(MQHost))
            {
                var rabbitMqProxy = new RabbitMqService(new MqConfig
                {
                    AutomaticRecoveryEnabled = true,
                    HeartBeat = 60,
                    NetworkRecoveryInterval = new TimeSpan(60),
                    Host        = MQHost,
                    UserName    = MQUser,
                    Password    = MQPwd,
                    VirtualHost = MQVirHost,
                    Port        = int.Parse(port)
                });
                rabbitMqProxy.Publish(name, name, name, Newtonsoft.Json.JsonConvert.SerializeObject(obj), true);
            }
        }
Beispiel #10
0
        static void publishUpgradeLog(string exchangeName, string queueName)
        {
            var rabbitMqProxyLog = new RabbitMqService(new MqConfig
            {
                AutomaticRecoveryEnabled = true,
                HeartBeat = 60,
                NetworkRecoveryInterval = new TimeSpan(60),
                Host     = "localhost",
                UserName = "******",
                Password = "******"
            });
            var beingIMEIINumber = 100000000000000;

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            try
            {
                sw.Start();
                Console.WriteLine($"*****************{queueName}消息发布开始******************");
                string imei  = string.Empty;
                int    terId = 0;

                try
                {
                    while (true)
                    {
                        for (int i = 0; i < 50000; i++)
                        {
                            imei = (beingIMEIINumber + i).ToString();

                            var log = new UpgradeLog
                            {
                                TerId          = 0,
                                RequestRawData = GetUpgradeBytes(imei),
                                StatusCode     = 0,
                                LogId          = 100001,
                                IMEI           = imei,
                                Request        = "",
                                ComHost        = "",
                                LocalEndPoint  = "192.168.0.38:8886",
                                CreatedTime    = DateTime.Now,
                                FirewareType   = 0,
                                HardwareVer    = "WK_MT6260D_T808_1V0",
                                SoftwareVer    = "9300_2016/10/11,VKEL_T808_20161011",
                                AppVer         = "9315"
                            };
                            rabbitMqProxyLog.Publish(exchangeName, queueName, "", log.ToJson());
                            //rabbitMqProxyLog.Publish(log);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw;
                }

                sw.Stop();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.WriteLine("总耗时:" + sw.Elapsed.Milliseconds);
        }