/// <summary> /// 定时触发 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { var list = DANQueue <User> .TryTakeAll(); if (list.Count > 0) { RabbitProvider.Publish(ExchangeStr, QueueStr, TypeUserName, list); } }
/// <summary> /// 只推送一次 /// </summary> public void RunOncePush() { //批量测试聚合通知。 stopwatch.Restart(); for (var i = 0; i <= 100000; i++) { var user = new User() { CompanyId = 13232, Mobile = "11111" + i }; repository.Update(user); } RabbitProvider.Publish(ExchangeStr, QueueStr, TypeUserName, DANQueue <User> .TryTakeAll()); stopwatch.Stop(); Console.WriteLine($"UpdateDelayPush-Time:" + stopwatch.ElapsedMilliseconds); }
/// <summary> /// 每次都推送 /// </summary> public void RunEachPush() { stopwatch.Restart(); //批量测试循环实时通知 for (var i = 0; i <= 5000; i++) { var user = new User() { CompanyId = 13232, Mobile = "11111" + i }; repository.Update(user); RabbitProvider.Publish(ExchangeStr, QueueStr, TypeUserName, DANQueue <User> .TryTake()); } stopwatch.Stop(); Console.WriteLine($"UpdateWithPush-Time:" + stopwatch.ElapsedMilliseconds); }