コード例 #1
0
        static void Main(string[] args)
        {
            var factory = new ConnectionFactory()
            {
                HostName = "localhost"
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    FanoutConfig fanoutConfig = new FanoutConfig();

                    Console.WriteLine(" [*] Waiting for 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.BasicConsume(queue: fanoutConfig.Queue,
                                         autoAck: true,
                                         consumer: consumer);

                    Console.WriteLine(" Press [enter] to exit.");
                    Console.ReadLine();
                }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var factory = new ConnectionFactory()
            {
                HostName = "localhost"
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    FanoutConfig fanoutConfig = new FanoutConfig();

                    var message = "It is a FanOut Message";
                    var body    = Encoding.UTF8.GetBytes(message);
                    channel.BasicPublish(exchange: fanoutConfig.exchangeName,
                                         routingKey: fanoutConfig.routingKey,
                                         basicProperties: null,
                                         body: body);
                    Console.WriteLine(" [x] Sent {0}", message);
                }

            Console.WriteLine(" Press [enter] to exit.");
            Console.ReadLine();
        }