protected override async Task ExecuteAsync(CancellationToken stoppingToken) { peiuPublishWorker = new PeiuPublishWorker(stoppingToken); peiuPublishWorker.Initialize(); while (!stoppingToken.IsCancellationRequested) { _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now); DaegunPacket pacekt = await packetQueue.DequeueAsync(stoppingToken); await Task.Delay(100, stoppingToken); } }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { PeiuPublishWorker = new PeiuPublishWorker(stoppingToken); PeiuPublishWorker.Initialize(); while (true) { stoppingToken.ThrowIfCancellationRequested(); if (stoppingToken.IsCancellationRequested) { break; } DaegunPacket packet = await queue.DequeueAsync(stoppingToken); await PublishAsync(packet); } }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { _logger.LogInformation("execute worker"); string target_ip = Environment.GetEnvironmentVariable("UDP_TARGET_IP"); string target_port = Environment.GetEnvironmentVariable("UDP_TARGET_PORT"); _logger.LogInformation("Target UDP Server: {0} : {1}", target_ip, target_port); int portNum = 11000; int.TryParse(target_port, out portNum); while (!stoppingToken.IsCancellationRequested) { try { //_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now); JObject jObj = await packetQueue.DequeueAsync(stoppingToken); int groupId = jObj["groupid"].Value <int>(); int siteId = jObj["siteId"].Value <int>(); string deviceId = jObj["normalizedeviceid"].Value <string>(); //if (groupId == 4 && siteId == 6) //{ // PvPacket packet = ConvertPacket(jObj); // int packSize = packet.GetSize(); // var pack = packet.ToByteArray(); // int packLength = pack.Length; // int sendpackets = udpClient.Send(pack, packLength, target_ip, portNum); // _logger.LogInformation("SENDING PACKET ({0} bytes)", sendpackets); //} string redisKey = CreateRedisKey(siteId, groupId, deviceId); HashEntry[] hashValues = CreateHashEntry(jObj); await db.HashSetAsync(redisKey, hashValues); await Task.Delay(100, stoppingToken); } catch (Exception ex) { _logger.LogError(ex, ex.Message); } } }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { PeiuPublishWorker = new PeiuPublishWorker(stoppingToken); PeiuPublishWorker.Initialize(); while (true) { try { stoppingToken.ThrowIfCancellationRequested(); if (stoppingToken.IsCancellationRequested) { break; } //if(PeiuPublishWorker.) DaegunPacket packet = await queue.DequeueAsync(stoppingToken); await PublishAsync(packet, stoppingToken); } catch (Exception ex) { logger.LogError(ex, ex.Message); } } }