Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("msgID,Description")] GTMS.Models.Message message)
        {
            if (id != message.msgID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(message);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MessageExists(message.msgID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(message));
        }
Пример #2
0
        public void SendQueueMessages(GTMS.Models.Message message)
        {
            // definir nombre del queue, en caso de no existir activemq lo crea
            // definir el uri del endpoint de aw - aws acepta ssl no tcp asi que el string cambia en el protocolo
            // al ser ssl hay que enviar las credenciales
            // apache.nms connectionfactory provee manejo de comunicacion con el queue
            // definir el "producer" en caso de la clase que envia de mensaje
            // definir el "receiver" en caso de ser el servicio consumiendo el queue

            string queueName = "dev_queue";

            Console.WriteLine($"Adding message to queue topic: {queueName}");

            string brokerUri = $"activemq:tcp://localhost:61616";  // dev broker
            //string brokerUri = $"activemq:ssl://b-57e8bf3e-69c9-4bec-b528-de407901bd09-1.mq.us-east-2.amazonaws.com:61617";

            NMSConnectionFactory factory = new NMSConnectionFactory(brokerUri);

            using (IConnection connection = factory.CreateConnection("admin", "adminactivemq"))
            {
                connection.Start();

                using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
                    using (IDestination dest = session.GetQueue(queueName))
                        using (IMessageProducer producer = session.CreateProducer(dest))
                        {
                            producer.DeliveryMode = MsgDeliveryMode.NonPersistent;
                            producer.Send(message);
                            Console.WriteLine($"Sent {message} messages");
                        }
            }
        }
Пример #3
0
        public async Task <IActionResult> Create([Bind("msgID,Description")] GTMS.Models.Message message)
        {
            SendQueueMessages(message);

            if (ModelState.IsValid)
            {
                _context.Add(message);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(message));
        }