public ActionResult Geolocalizar(GeolocalizacionDTO body) { try { if (body == null) { return(BadRequest("Datos incorrectos.")); } var id = _service.SaveGeoRequest(body); PeticionGeolocalizacion request = new PeticionGeolocalizacion() { Id = id, Calle = body.Calle, Numero = body.Numero, Ciudad = body.Ciudad, Codigo_postal = body.Codigo_postal, Provincia = body.Provincia, Pais = body.Pais }; _amqp.PublishGeolocalizacion(request); return(Ok(request.Id)); } catch (Exception ex) { return(StatusCode(500, "Falló la petición de Geolocalización. Error: " + ex.Message)); } }
public void PublishGeolocalizacion(PeticionGeolocalizacion request) { using (var conn = connectionFactory.CreateConnection()) { using (var channel = conn.CreateModel()) { channel.QueueDeclare( queue: QueueRequest, durable: false, exclusive: false, autoDelete: false, arguments: null ); var jsonPayload = JsonConvert.SerializeObject(request); var body = Encoding.UTF8.GetBytes(jsonPayload); channel.BasicPublish(exchange: "", routingKey: QueueRequest, basicProperties: null, body: body ); } } }