Exemple #1
0
        static void Main()
        {
            _factory = RabbitHelper.GetFactory();
            using (_connection = _factory.CreateConnection())
            {
                using (var channel = _connection.CreateModel())
                {
                    channel.ExchangeDeclare(ExchangeName, "direct");

                    channel.QueueDeclare(PurchaseOrderQueueName, true, false, false, null);
                    channel.QueueBind(PurchaseOrderQueueName, ExchangeName, "PurchaseOrder");
                    channel.BasicQos(0, 1, false);

                    var consumer = new QueueingBasicConsumer(channel);
                    channel.BasicConsume(PurchaseOrderQueueName, false, consumer);

                    while (true)
                    {
                        var ea         = consumer.Queue.Dequeue();
                        var message    = (PurchaseOrder)ea.Body.DeSerialize(typeof(PurchaseOrder));
                        var routingKey = ea.RoutingKey;
                        channel.BasicAck(ea.DeliveryTag, false);

                        Console.WriteLine("-- Purchase Order - Routing Key <{0}> : {1}, £{2}, {3}, {4}", routingKey, message.CompanyName, message.AmountToPay, message.PaymentDayTerms, message.PoNumber);
                    }
                }
            }
        }
        public static void Receive()
        {
            var factory = RabbitHelper.GetFactory();

            using (var connection = factory.CreateConnection())
            {
                using (var model = connection.CreateModel())
                {
                    model.QueueDeclare(QueueName, true, false, false, null);
                    model.BasicQos(0, 1, false);

                    var consumer = new QueueingBasicConsumer(model);
                    model.BasicConsume(QueueName, false, consumer);

                    while (true)
                    {
                        var ea      = consumer.Queue.Dequeue();
                        var message = (Payment)ea.Body.DeSerialize(typeof(Payment));
                        model.BasicAck(ea.DeliveryTag, false);

                        Console.WriteLine("----- Payment Processed {0} : {1}", message.CardNumber, message.AmountToPay);
                    }
                }
            }
        }
Exemple #3
0
        private static void CreateConnection()
        {
            _model = _model = RabbitHelper.GetChannel();
            _model.ExchangeDeclare(ExchangeName, "direct");

            _model.QueueDeclare(PurchaseOrderQueueName, true, false, false, null);
            _model.QueueBind(PurchaseOrderQueueName, ExchangeName, "PurchaseOrder");

            _model.QueueDeclare(CardPaymentQueueName, true, false, false, null);
            _model.QueueBind(CardPaymentQueueName, ExchangeName, "CardPayment");
        }
Exemple #4
0
        static void Main()
        {
            _factory = RabbitHelper.GetFactory();
            using (_connection = _factory.CreateConnection())
            {
                using (var channel = _connection.CreateModel())
                {
                    var queueName = DeclareAndBindQueueToExchange(channel);
                    channel.BasicConsume(queueName, true, _consumer);

                    while (true)
                    {
                        var ea      = _consumer.Queue.Dequeue();
                        var message = (Payment)ea.Body.DeSerialize(typeof(Payment));

                        Console.WriteLine("----- Payment Processed {0} : {1}", message.CardNumber, message.AmountToPay);
                    }
                }
            }
        }
 private static void CreateConnection()
 {
     _model = RabbitHelper.GetChannel();
     _model.ExchangeDeclare(ExchangeName, "fanout", false);
 }
 private static void CreateQueue()
 {
     _model = RabbitHelper.GetChannel();
     _model.QueueDeclare(QueueName, true, false, false, null);
 }