Esempio n. 1
0
        public bool SendPositionMsg(List <DbModel.LocationHistory.Data.Position> Info)
        {
            if (isBusy)
            {
                return(false);
            }
            if (personList == null)
            {
                personList = bll.Personnels.ToList();
            }
            if (areaList == null)
            {
                areaList = bll.Areas.ToList();
            }
            foreach (DbModel.LocationHistory.Data.Position item in Info)
            {
                try
                {
                    position SendInfo = new position();
                    if (item.Code == "" || item.AreaId == null)
                    {
                        continue;
                    }
                    SetSendInfo(item, SendInfo);
                    if (item.PersonnelID != null)
                    {
                        var ps = personList.FirstOrDefault(p => p.Id == item.PersonnelID);
                        if (ps != null)
                        {
                            SendInfo.staffCode = Convert.ToString(ps.WorkNumber);
                        }
                    }
                    var ae = areaList.FirstOrDefault(p => p.Id == item.AreaId);
                    if (ae != null)
                    {
                        SendInfo.zoneKksCode = ae.KKS;
                    }

                    string strJson = JsonConvert.SerializeObject(SendInfo);
                    isBusy = true;
                    string result = producer.Publish("position", strJson);//这里可能会卡住
                    isBusy = false;
                    if (result == null)
                    {
                        return(false);
                    }
                    //producer.Publish("http://127.0.0.1:4151/pub?topic=position", strJson);
                }
                catch (Exception ex)
                {
                    Log.Error("SendPositionMsg", ex);
                }
            }
            return(true);
        }
Esempio n. 2
0
        private void BenchmarkHttp(int parallel)
        {
            string topicName = "test_benchmark_" + DateTime.Now.UnixNano();

            try
            {
                const int benchmarkNum = 30000;

                byte[] body = new byte[512];

                var startCh = new Chan <bool>();
                var wg      = new WaitGroup();

                for (int j = 0; j < parallel; j++)
                {
                    wg.Add(1);
                    GoFunc.Run(() =>
                    {
                        startCh.Receive();
                        for (int i = 0; i < benchmarkNum / parallel; i++)
                        {
                            _nsqdHttpClient.Publish(topicName, body);
                        }
                        wg.Done();
                    }, "ProducerBenchmarkHttpTest: sendLoop");
                }

                var stopwatch = Stopwatch.StartNew();
                startCh.Close();
                wg.Wait();
                stopwatch.Stop();

                Console.WriteLine(string.Format("{0:#,0} sent in {1:mm\\:ss\\.fff}; Avg: {2:#,0} msgs/s; Threads: {3}",
                                                benchmarkNum, stopwatch.Elapsed, benchmarkNum / stopwatch.Elapsed.TotalSeconds, parallel));
            }
            finally
            {
                _nsqdHttpClient.DeleteTopic(topicName);
                _nsqLookupdHttpClient.DeleteTopic(topicName);
            }
        }
        public void SendPositionMsg(List <DbModel.LocationHistory.Data.Position> Info)
        {
            string strSendInfo = "";

            foreach (DbModel.LocationHistory.Data.Position item in Info)
            {
                position SendInfo = new position();

                if (item.Code == "" || item.AreaId == null)
                {
                    continue;
                }

                SendInfo.deviceCode = item.Code;
                SendInfo.t          = item.DateTimeStamp;
                SendInfo.x          = item.X;
                SendInfo.y          = item.Z;
                SendInfo.z          = item.Y;
                SendInfo.staffCode  = null;

                if (item.PersonnelID != null)
                {
                    DbModel.Location.Person.Personnel ps = bll.Personnels.DbSet.Where(p => p.Id == item.PersonnelID).FirstOrDefault();
                    SendInfo.staffCode = Convert.ToString(ps.WorkNumber);
                }

                DbModel.Location.AreaAndDev.Area ae = bll.Areas.DbSet.Where(p => p.Id == item.AreaId).FirstOrDefault();
                SendInfo.zoneKksCode = ae.KKS;


                string strJson = JsonConvert.SerializeObject(SendInfo);
                producer.Publish("position", strJson);
                //producer.Publish("http://127.0.0.1:4151/pub?topic=position", strJson);
                strSendInfo = "";
            }
            return;
        }
Esempio n. 4
0
 /// <summary>Publishes a <paramref name="message"/> on the specified <paramref name="topic"/>.</summary>
 /// <param name="topic">The topic.</param>
 /// <param name="message">The message.</param>
 public void Publish(string topic, byte[] message)
 {
     _nsqdHttpClient.Publish(topic, message);
 }