コード例 #1
0
        private string retryMSG(string enderecoAMQ, string topico, string stringData, string correlationID, string replyTo, string erro)
        {
            AMQ.AMQ gravaMensagem = new AMQ.AMQ();
            dynamic results       = JsonConvert.DeserializeObject <dynamic>(stringData);

            if (results.Retries == null)
            {
                results.Retries = 0;
            }
            results.Retries     = results.Retries + 1;
            results.erroChamada = erro;
            if (results.Retries <= TENTATIVAS_RETRY)
            {
                stringData = JsonConvert.SerializeObject(results);
                gravaMensagem.executa(enderecoAMQ, topico, stringData, correlationID);
            }
            else
            {
                results.numeroTentativasExcedidas = SIM;
                results.passo        = "ERRO";
                results.dataExecucao = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                stringData           = JsonConvert.SerializeObject(results);
                gravaMensagem.executa(enderecoAMQ, topico + SUFIXO_MQ_ERRO, stringData, correlationID);
            }
            return(stringData);
        }
コード例 #2
0
        public string Post([FromBody] object entrada)
        {
            Random random     = new System.Random();
            int    valueSleep = random.Next(1, 10); //returns integer of 0-100

            Thread.Sleep(valueSleep * 1000);
            //            Console.WriteLine("Sleep: {0}", valueSleep);
            AMQ.AMQ mensagem   = new AMQ.AMQ();
            string  stringData = JsonConvert.SerializeObject(entrada);
            dynamic results    = JsonConvert.DeserializeObject <dynamic>(stringData);

            string passo  = "AuthorizeCard";
            string topico = "TXN_4";

            if (valueSleep % 2 == 0)
            {
                passo  = "RejectCard";
                topico = "TXN_40";
            }
            results.passo        = passo;
            results.dataExecucao = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
            stringData           = JsonConvert.SerializeObject(results);
            string fila         = results.fila;
            string codigoTicket = results.codigoTicket;

            mensagem.executa(fila, topico, stringData, codigoTicket);

            return(stringData);
        }
コード例 #3
0
        public string Post([FromBody] object entrada)
        {
            Random random     = new System.Random();
            int    valueSleep = random.Next(1, 10) * 1000; //returns integer of 0-100

            Thread.Sleep(valueSleep);
//            Console.WriteLine("Sleep: {0}", valueSleep);

            AMQ.AMQ mensagem   = new AMQ.AMQ();
            string  stringData = JsonConvert.SerializeObject(entrada);
            dynamic results    = JsonConvert.DeserializeObject <dynamic>(stringData);

            results.passo        = "VerifyConsumer";
            results.dataExecucao = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
            stringData           = JsonConvert.SerializeObject(results);
            string fila         = results.fila;
            string codigoTicket = results.codigoTicket;

            mensagem.executa(fila, "TXN_2", stringData, codigoTicket);

            return(stringData);
        }
コード例 #4
0
        public string Post([FromBody] object entrada)
        {
            Random random     = new System.Random();
            int    valueSleep = random.Next(1, 10) * 1000;

            Thread.Sleep(valueSleep);
            AMQ.AMQ mensagem   = new AMQ.AMQ();
            string  stringData = JsonConvert.SerializeObject(entrada);
            dynamic results    = JsonConvert.DeserializeObject <dynamic>(stringData);
            Guid    guid       = Guid.NewGuid();
            string  codigo     = guid.ToString();

            results.codigoTicket = codigo;
            results.fila         = enderecoFila;
            results.passo        = "InicioProcesso";
            results.dataExecucao = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
            stringData           = JsonConvert.SerializeObject(results);
            string fila = results.fila;

            mensagem.executa(fila, topico, stringData, codigo);
            return(stringData);
        }
コード例 #5
0
        public void monitorar()
        {
            Console.WriteLine("INICIO DA OPERACAO");
            Connection connection = null;

            try
            {
                Settings             configs   = new Settings();
                ConfiguracoesValores config    = configs.ResgataParametro();
                string EndpointElasticSearchOK = config.Parametros.EndpointElasticSearch.DoctoOK;
                string enderecoFila            = config.Parametros.EnderecoFila;
                string topicoEntrada           = config.Parametros.Inicio.TopicoEntrada;
                string topicoSaida             = config.Parametros.Inicio.TopicoSaida;

                Address address = new Address(enderecoFila);
                connection = new Connection(address);
                Session      session           = new Session(connection);
                ReceiverLink receiver          = new ReceiverLink(session, NOME_FILA_CONSUMIDOR_MQ, topicoEntrada);
                ElasticSearch.ElasticSearch ES = new ElasticSearch.ElasticSearch();

                while (true)
                {
                    Message request       = receiver.Receive(new TimeSpan(0, 30, 0));
                    string  replyTo       = request.Properties.ReplyTo;
                    string  correlationID = request.Properties.CorrelationId;

                    if (null != request)
                    {
                        //                        Console.WriteLine(request.Body);
                        string stringData = request.Body.ToString();

                        dynamic results = JsonConvert.DeserializeObject <dynamic>(stringData);

                        results.fila         = enderecoFila;
                        results.passo        = "InicioProcesso";
                        results.dataExecucao = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                        string codigoTicket = results.codigoTicket;

                        stringData = JsonConvert.SerializeObject(results);

                        var contentDataES = new StringContent(stringData, System.Text.Encoding.UTF8, MIME_TYPE_JSON);

                        //                        Console.WriteLine("Gravando no ElasticSearch: {0}", EndpointElasticSearchOK + codigoTicket);
                        ES.executa(EndpointElasticSearchOK, contentDataES);


                        AMQ.AMQ gravaMensagem = new AMQ.AMQ();

                        //                        Console.WriteLine("Enviando, Topico: {0}, CRID: {1}", topicoSaida, correlationID);

                        gravaMensagem.executa(enderecoFila, topicoSaida, stringData, correlationID);
                        receiver.Accept(request);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Exception {0}.", e);
                if (null != connection)
                {
                    connection.Close();
                }
            }
        }