protected override Task ExecuteAsync(CancellationToken stoppingToken)
        {
            //token campurador de evento
            stoppingToken.ThrowIfCancellationRequested();
            try
            {
                channel.QueueDeclare(queue: _queueName, durable: false, exclusive: false, autoDelete: false, arguments: null);

                Prueba_AndreaniContext _context = new Prueba_AndreaniContext(); //contexto de bd
                var consumer = new EventingBasicConsumer(channel);              //consumidor
                consumer.Received += async(mod, ea) =>
                {
                    var    body       = ea.Body.ToArray();
                    var    response   = Encoding.UTF8.GetString(body);
                    Pedido localizado = JsonConvert.DeserializeObject <Pedido>(response);
                    _context.Entry(localizado).State = EntityState.Modified;
                    try
                    {
                        await _context.SaveChangesAsync();//guardo cambios
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        throw;
                    }
                    channel.BasicAck(ea.DeliveryTag, false);
                };
                channel.BasicConsume(_queueName, false, consumer);
            }
            catch (Exception)
            {
                throw;
            }
            return(Task.CompletedTask);
        }
Exemplo n.º 2
0
        public async Task <ActionResult <Pedido> > PostGeolocalizar(Pedido pedido)
        {
            _context = new Prueba_AndreaniContext();
            try
            {
                _context.Pedido.Add(pedido);
                await _context.SaveChangesAsync();

                if (pedido.Id != 0)
                {
                    //establesco valores para la cola
                    var factory = new ConnectionFactory()
                    {
                        HostName = "rabbitmq", UserName = "******", Password = "******"
                    };
                    using (var connection = factory.CreateConnection())
                    {
                        using (var channel = connection.CreateModel())
                        {
                            channel.QueueDeclare(queue: "Cola_Andreani2", durable: false, exclusive: false, autoDelete: false, arguments: null);
                            var json = JsonConvert.SerializeObject(pedido);
                            var body = Encoding.UTF8.GetBytes(json);
                            channel.BasicPublish(exchange: "", routingKey: "Cola_Andreani2", basicProperties: null, body: body);
                        }
                    }
                }
                return(Accepted("GetPedido", new { id = pedido.Id }));
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
Exemplo n.º 3
0
        public async Task <ActionResult <Pedido> > GetPedido(int id)
        {
            _context = new Prueba_AndreaniContext();

            var pedido = await _context.Pedido.FindAsync(id);

            if (pedido == null)
            {
                return(NotFound());
            }

            return(pedido);
        }
Exemplo n.º 4
0
 public async Task <ActionResult <IEnumerable <Pedido> > > GetPedido()
 {
     _context = new Prueba_AndreaniContext();
     return(await _context.Pedido.ToListAsync());
 }
Exemplo n.º 5
0
 public geocodificarController(Prueba_AndreaniContext context)
 {
     _context = context;
 }