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); }
static void publishDefault(string exchangeName, string queueName) { var factory = new ConnectionFactory() { HostName = ConfigurationManager.AppSettings["rabbitMq_HostName"], Port = Convert.ToInt32(ConfigurationManager.AppSettings["rabbitMq_Port"]), UserName = ConfigurationManager.AppSettings["rabbitMq_UserName"], Password = ConfigurationManager.AppSettings["rabbitMq_Password"] }; using (IConnection conn = factory.CreateConnection()) { using (var channel = conn.CreateModel()) { channel.ExchangeDeclare(exchange: exchangeName, type: ConfigurationManager.AppSettings["rabbitMq_Type"], durable: true); //指定队列 channel.QueueBind(queue: queueName, exchange: exchangeName, routingKey: ""); try { var beingIMEIINumber = 100000000000000; string imei = ""; //1秒=10000000ticks //1毫秒=10000tikcs //1ticks = 100毫微秒=0.1微秒=0.00001毫秒 #region 循环批量 while (true) { for (int i = 60000; i < 70000; i++) { imei = (beingIMEIINumber + i).ToString(); var log = new UpgradeLog { TerId = 0, RequestRawData = GetUpgradeBytes(imei), StatusCode = 0, LogId = 100001, IMEI = imei, Request = "", CreatedTime = DateTime.Now, LocalEndPoint = "192.168.30.204:20260", FirewareType = 0, HardwareVer = "WK_MT6260D_T808_1V0", SoftwareVer = "9300_2016/10/11,VKEL_T808_20161011", AppVer = "9315" }; var message = Encoding.ASCII.GetBytes(log.ToJson()); channel.BasicPublish(exchange: exchangeName, routingKey: "", basicProperties: null, body: message); } //System.Threading.Thread.Sleep(2000); } #endregion #region 单个测试 //var log = new UpgradeLog //{ // TerId = 0, // RequestRawData = GetUpgradeBytes("868500023849383"), // StatusCode = 0, // LogId = 100001, // IMEI = "868500023849383", // Request = "", // CreatedTime = DateTime.Now, // LocalEndPoint = "192.168.30.204:20260", // FirewareType = 0, // Scheme= "VKEL_MT2503D",//方案号只去下划线前两位 // HardwareVer = "VKEL_MT2503D_S28_1V0", // SoftwareVer = "BP00_2018/07/14,VKEL_S107_20180822", // AppVer = "BP24" //}; //var message = Encoding.ASCII.GetBytes(log.ToJson()); //channel.BasicPublish(exchange: exchangeName, routingKey: "", basicProperties: null, body: message); #endregion } catch (Exception ex) { Console.WriteLine(ex); } } } }