Beispiel #1
0
        static void Main(string[] args)
        {
            var connectionFactory = ConnectionFactoryProvider.Get();
            var connection        = connectionFactory.CreateConnection();
            var channel           = connection.CreateModel();

            var payments = new SampleDataCreator().CreatePayments(20);

            CreateQueue(channel);

            Console.WriteLine("-----------------------------------------------------------------------------");
            Console.WriteLine(string.Format("|{0,22}|{1,15}|{2,15}|{3,20}|", "Description", "Card Number", "Amount", "Name"));
            Console.WriteLine("-----------------------------------------------------------------------------");

            foreach (var payment in payments)
            {
                SendMessage(payment, channel);
            }

            Console.WriteLine();
            Console.WriteLine("---------------------------------------------------------------------------------");
            Console.WriteLine(string.Format("|{0,26}|{1,15}|{2,15}|{3,20}|", "Description", "Card Number", "Amount", "Name"));
            Console.WriteLine("---------------------------------------------------------------------------------");

            ReceiveMessages(channel);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var connectionFactory = ConnectionFactoryProvider.Get();
            var connection        = connectionFactory.CreateConnection();
            var channel           = connection.CreateModel();
            var consumer          = new QueueingBasicConsumer(channel);

            var queueName = channel.QueueDeclare().QueueName;

            DeclareAndBindQueueToExchange(channel, queueName);

            channel.BasicConsume(queueName, true, consumer);

            Console.WriteLine();
            Console.WriteLine("---------------------------------------------------------------------------------");
            Console.WriteLine(string.Format("|{0,26}|{1,15}|{2,15}|{3,20}|", "Description", "Card Number", "Amount", "Name"));
            Console.WriteLine("---------------------------------------------------------------------------------");

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

                Console.WriteLine("Payment message received : " + string.Format("|{0,15}|{1,15}|{2,20}|", message.CardNumber, message.Amount, message.Name));
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            var connectionFactory = ConnectionFactoryProvider.Get();
            var connection        = connectionFactory.CreateConnection();
            var channel           = connection.CreateModel();
            var consumer          = new QueueingBasicConsumer(channel);

            DeclareAndBindQueueToExchange(channel);

            channel.BasicConsume(CardPaymentQueueName, false, consumer);

            Console.WriteLine("---------------------------------------------------------------------------------------------------------------");
            Console.WriteLine(string.Format("|{0,25}|{1,20}|{2,20}|{3,20}|{4,20}|", "Description", "Routing Key", "Company Name", "Amount", "Card Number"));
            Console.WriteLine("---------------------------------------------------------------------------------------------------------------");

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

                Console.WriteLine(string.Format("|{0,25}|{1,20}|{2,20}|{3,20}|{4,20}|", "Payment received", routingKey, message.Name, message.Amount, message.CardNumber));
            }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            var connectionFactory = ConnectionFactoryProvider.Get();
            var connection        = connectionFactory.CreateConnection();
            var channel           = connection.CreateModel();
            var consumer          = new QueueingBasicConsumer(channel);

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

            channel.BasicConsume(PurchaseOrderQueueName, false, consumer);

            Console.WriteLine("------------------------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine(string.Format("|{0,25}|{1,20}|{2,20}|{3,20}|{4,20}|{5,20}|", "Description", "Routing Key", "Company Name", "Amount", "Day Terms", "Order Number"));
            Console.WriteLine("------------------------------------------------------------------------------------------------------------------------------------");

            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(string.Format("|{0,25}|{1,20}|{2,20}|{3,20}|{4,20}|{5,20}|", "Purchase Order received", routingKey, message.CompanyName, message.Amount, message.PaymentDayTerms, message.PurchaseOrderNumber));
            }
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            var connectionFactory = ConnectionFactoryProvider.Get();
            var connection        = connectionFactory.CreateConnection();
            var channel           = connection.CreateModel();

            CreateQueue(channel);

            Console.WriteLine();
            Console.WriteLine("---------------------------------------------------------------------------------");
            Console.WriteLine(string.Format("|{0,26}|{1,15}|{2,15}|{3,20}|", "Description", "Card Number", "Amount", "Name"));
            Console.WriteLine("---------------------------------------------------------------------------------");

            ReceiveMessages(channel);
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            var connectionFactory = ConnectionFactoryProvider.Get();
            var connection        = connectionFactory.CreateConnection();
            var channel           = connection.CreateModel();

            var dataCreator    = new SampleDataCreator();
            var payments       = dataCreator.CreatePayments(100);
            var purchaseOrders = dataCreator.CreatePurchaseOrder(100);

            CreateConnection(channel);

            var paymentsQueue       = new Queue <Payment>(payments);
            var purchaseOrdersQueue = new Queue <PurchaseOrder>(purchaseOrders);

            var onOff = true;

            var count = payments.Count() + purchaseOrders.Count();

            Console.WriteLine("---------------------------------------------------------------------------------------------------------------");
            Console.WriteLine(string.Format("|{0,25}|{1,20}|{2,20}|{3,20}|{4,20}|", "Description", "Name", "Amount", "Number", "Other"));
            Console.WriteLine("---------------------------------------------------------------------------------------------------------------");

            for (int i = 0; i < count; i++)
            {
                if (onOff)
                {
                    var payment = paymentsQueue.Dequeue();
                    SendMessage(payment.Serialize(), "CardPayment", channel);
                    Console.WriteLine(string.Format("|{0,25}|{1,20}|{2,20}|{3,20}|", "Payment message sent: ", payment.Name, payment.Amount, payment.CardNumber));
                    onOff = false;
                }
                else
                {
                    var purchaseOrder = purchaseOrdersQueue.Dequeue();
                    SendMessage(purchaseOrder.Serialize(), "PurchaseOrder", channel);
                    Console.WriteLine(string.Format("|{0,25}|{1,20}|{2,20}|{3,20}|{4,20}|", "Purchase order sent: ", purchaseOrder.CompanyName, purchaseOrder.Amount, purchaseOrder.PurchaseOrderNumber, purchaseOrder.PaymentDayTerms));
                    Console.WriteLine("---------------------------------------------------------------------------------------------------------------");
                    onOff = true;
                }
            }
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            var connectionFactory = ConnectionFactoryProvider.Get();
            var connection        = connectionFactory.CreateConnection();
            var channel           = connection.CreateModel();

            channel.ExchangeDeclare(ExchangeName, "fanout", false);

            var payments = CreatePayments(1000);

            Console.WriteLine("-----------------------------------------------------------------------------");
            Console.WriteLine(string.Format("|{0,22}|{1,15}|{2,15}|{3,20}|", "Description", "Card Number", "Amount", "Name"));
            Console.WriteLine("-----------------------------------------------------------------------------");

            foreach (var payment in payments)
            {
                Thread.Sleep(500);
                SendMessage(payment, channel);
            }
        }