private void despacharEventos(object sender, HttpNegocioEventArgs args) { try { string mensagem = null; EventoHttpNegocio httpNEG = args.Evento; if (dctSessions.ContainsKey(httpNEG.instrumento)) { mensagem = JsonConvert.SerializeObject(httpNEG); mensagem = MDSUtils.montaMensagemHttp(ConstantesMDS.TIPO_REQUISICAO_NEGOCIOS, httpNEG.instrumento, null, mensagem); logger.Debug("INCR Negocio[" + httpNEG.instrumento + "]: " + mensagem); if (!String.IsNullOrEmpty(mensagem)) { queueToStreamer.Enqueue(mensagem); } } } catch (Exception ex) { logger.Error("despacharEventos(): " + ex.Message, ex); } }
private void procHttpQueueNEG() { long lstEvent = 0; logger.Info("Inicializando thread do processamento da fila de eventos de Negocios Streamer"); while (bKeepRunning) { try { EventoHttpNegocio e; if (queueHttpNEG.TryDequeue(out e)) { if (OnEventoHttpNegocios != null) { HttpNegocioEventArgs args = new HttpNegocioEventArgs(); args.Evento = e; OnEventoHttpNegocios(this, args); } if (MDSUtils.shouldLog(lstEvent)) { lstEvent = DateTime.UtcNow.Ticks; logger.Info("Fila queueHttpNEG: " + queueHttpNEG.Count + " eventos."); } continue; } lock (syncQueueHttpNEG) { Monitor.Wait(syncQueueHttpNEG, QUEUE_WAIT_TIMEOUT); } } catch (Exception ex) { logger.Error("procHttpQueueNEG: " + ex.Message, ex); } } }