Example #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting Worker2...");

            using (var connection = RabbitConnectionFactory.GetConnection())
            {
                using (var channel = connection.CreateModel())
                {
                    var queueName = channel.QueueDeclare().QueueName;
                    channel.QueueBind(queueName, "logs", "");

                    var consumer = new EventingBasicConsumer(channel);
                    consumer.Received += (model, ea) =>
                    {
                        var body    = ea.Body;
                        var message = Encoding.UTF8.GetString(body);
                        Console.WriteLine(" [x] {0}", message);

                        channel.BasicAck(ea.DeliveryTag, false);
                    };

                    channel.BasicConsume(queue: queueName,
                                         autoAck: false,
                                         consumer: consumer);

                    Console.ReadLine();
                }
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            var sender = new DirectMessageSender(RabbitConnectionFactory.GetConnection());

            while (true)
            {
                var message = Console.ReadLine();

                sender.Send(message);
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting publisher...");

            using (var connection = RabbitConnectionFactory.GetConnection())
            {
                using (var channel = connection.CreateModel())
                {
                    channel.ExchangeDeclare("logs", ExchangeType.Fanout);

                    while (true)
                    {
                        var message = Console.ReadLine();

                        var body = Encoding.UTF8.GetBytes(message);
                        channel.BasicPublish(exchange: "logs",
                                             routingKey: "",
                                             basicProperties: null,
                                             body: body);
                    }
                }
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Escutando...");

            new DirectMessageReceiver(RabbitConnectionFactory.GetConnection()).Consume();
        }