예제 #1
0
        public void Receive(EventHandler <T> handler, string cola = "default", string ruta = "default", bool duradero = false, bool exclusivo = false, bool autoBorrado = false, IDictionary <string, object> argumentos = null)
        {
            IConnectionFactory cf = new ConnectionFactory();

            cf.Uri = new Uri(_URI_CONEXION);
            using (IConnection cn = cf.CreateConnection())
            {
                using (IModel ch = cn.CreateModel())
                {
                    ch.QueueDeclare(queue: cola,
                                    durable: duradero,
                                    exclusive: exclusivo,
                                    autoDelete: autoBorrado,
                                    arguments: argumentos);
                    var consumidor = new EventingBasicConsumer(ch);
                    consumidor.Received += (model, ea) =>
                    {
                        byte[]            datos = ea.Body.ToArray();
                        JsonSerialize <T> js    = new JsonSerialize <T>();
                        T valor;
                        valor = js.GetObjectByt(datos);
                        handler(this, valor);
                    };
                }
            }
        }