Example #1
0
        public ConfiguracoesValores ResgataParametro()
        {
            IConfiguration config = new ConfigurationBuilder()
                                    .AddJsonFile("appsettings.json", true, true)
                                    .Build();

            //var settingsSection = config.Get<ConfiguracoesValores>();
            ConfiguracoesValores settings = config.Get <ConfiguracoesValores>();

            return(settings);
        }
Example #2
0
        static void Main(string[] args)
        {
            PSHub                principal = new PSHub();
            Settings             configs   = new Settings();
            ConfiguracoesValores escutas   = configs.ResgataParametro();

            foreach (Escutas escuta in escutas.Parametros.Escuta)
            {
                AdicionaParametroRotina(escuta.EnderecoFila, escuta.Topico, escuta.API);
            }
            foreach (ParametrosRotina topico in topicos.Values)
            {
                Console.WriteLine("iniciando escuta: {0}", topico.topico);
                principal.executar(topico);
            }
        }
Example #3
0
        private void NovaRotina(object parametro)
        {
            ParametrosRotina topico     = (ParametrosRotina)parametro;
            Connection       connection = null;

            try
            {
                Address address = new Address(topico.enderecoAMQ);
                connection = new Connection(address);
                Session              session     = new Session(connection);
                Settings             configs     = new Settings();
                ConfiguracoesValores config      = configs.ResgataParametro();
                string EndpointElasticSearchOK   = config.Parametros.EndpointElasticSearch.DoctoOK;
                string EndpointElasticSearchERRO = config.Parametros.EndpointElasticSearch.DoctoERRO;
                ElasticSearch.ElasticSearch ES   = new ElasticSearch.ElasticSearch();

                ReceiverLink receiver = new ReceiverLink(session, NOME_FILA_CONSUMIDOR_MQ, topico.topico);
                while (true)
                {
                    Message request = receiver.Receive();
                    if (null != request)
                    {
                        string stringData    = request.Body.ToString();
                        string correlationID = request.Properties.CorrelationId;
                        string replyTo       = request.Properties.ReplyTo;

                        dynamic results = JsonConvert.DeserializeObject <dynamic>(stringData);
                        Console.WriteLine("Topico acionado: {0}, Ticket: {1}, Passo: {2}", topico.topico, correlationID, results.passo);
                        using (var client = new HttpClient())
                        {
                            foreach (Rota rota in topico.rota)
                            {
                                var contentData = new StringContent(stringData, System.Text.Encoding.UTF8, MIME_TYPE_JSON);
                                try
                                {
                                    //chama a API
                                    HttpResponseMessage responseHUB = client.PostAsync(rota.endereco, contentData).Result;

                                    if (responseHUB.StatusCode == System.Net.HttpStatusCode.OK)
                                    {
                                        string retorno = responseHUB.Content.ReadAsStringAsync().Result;
                                        //posta elasticsearch
                                        var contentDataES = new StringContent(retorno, System.Text.Encoding.UTF8, MIME_TYPE_JSON);
                                        ES.executa(EndpointElasticSearchOK, contentDataES);
                                    }
                                    else
                                    {
                                        string msgErro = retryMSG(topico.enderecoAMQ, topico.topico, stringData, correlationID, replyTo, responseHUB.StatusCode.ToString());

                                        //posta elasticsearch
                                        var contentDataES = new StringContent(msgErro, System.Text.Encoding.UTF8, MIME_TYPE_JSON);

                                        //                                        Console.WriteLine("Gravando no ElasticSearch: {0}", EndpointElasticSearchERRO + correlationID);
                                        ES.executa(EndpointElasticSearchERRO, contentDataES);
                                    }
                                }
                                catch (Exception erro)
                                {
                                    string msgErro = retryMSG(topico.enderecoAMQ, topico.topico, stringData, correlationID, replyTo, erro.Message.ToString());
                                    //posta elasticsearch
                                    var contentDataES = new StringContent(msgErro, System.Text.Encoding.UTF8, MIME_TYPE_JSON);

                                    //                                    Console.WriteLine("Gravando no ElasticSearch: {0}", EndpointElasticSearchERRO + correlationID);
                                    ES.executa(EndpointElasticSearchERRO, contentDataES);
                                }
                            }
                            receiver.Accept(request);
                        }
                    }
                    else
                    {
                        //   Console.WriteLine(MSG_TIMEOUT);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Exception {0}.", e);
                if (null != connection)
                {
                    connection.Close();
                }
            }
        }