|
2 | 2 | using RabbitMQ.Client; |
3 | 3 | using RabbitMQ.Client.Events; |
4 | 4 |
|
5 | | -class ReceiveLogsDirect { |
6 | | - public static void Main(string[] args) { |
7 | | - ConnectionFactory factory = new ConnectionFactory(); |
8 | | - factory.HostName = "localhost"; |
9 | | - using (IConnection connection = factory.CreateConnection()) |
10 | | - using (IModel channel = connection.CreateModel()) { |
11 | | - |
12 | | - channel.ExchangeDeclare("direct_logs", "direct"); |
13 | | - string queue_name = channel.QueueDeclare(); |
14 | | - |
15 | | - if (args.Length < 1) { |
16 | | - Console.Error.WriteLine("Usage: {0} [info] [warning] [error]", |
17 | | - Environment.GetCommandLineArgs()[0]); |
18 | | - Environment.ExitCode = 1; |
19 | | - return; |
20 | | - } |
21 | | - |
22 | | - foreach (string severity in args) { |
23 | | - channel.QueueBind(queue_name, "direct_logs", severity); |
24 | | - } |
25 | | - |
26 | | - Console.WriteLine(" [*] Waiting for messages. " + |
27 | | - "To exit press CTRL+C"); |
28 | | - |
29 | | - QueueingBasicConsumer consumer = new QueueingBasicConsumer(channel); |
30 | | - channel.BasicConsume(queue_name, true, consumer); |
31 | | - |
32 | | - while(true) { |
33 | | - BasicDeliverEventArgs ea = |
34 | | - (BasicDeliverEventArgs)consumer.Queue.Dequeue(); |
35 | | - |
36 | | - byte[] body = ea.Body; |
37 | | - string message = System.Text.Encoding.UTF8.GetString(body); |
38 | | - string routingKey = ea.RoutingKey; |
39 | | - Console.WriteLine(" [x] Received '{0}':'{1}'", |
40 | | - routingKey, message); |
| 5 | +class ReceiveLogsDirect |
| 6 | +{ |
| 7 | + public static void Main(string[] args) |
| 8 | + { |
| 9 | + var factory = new ConnectionFactory() { HostName = "localhost" }; |
| 10 | + using (var connection = factory.CreateConnection()) |
| 11 | + { |
| 12 | + using (var channel = connection.CreateModel()) |
| 13 | + { |
| 14 | + channel.ExchangeDeclare("direct_logs", "direct"); |
| 15 | + var queue_name = channel.QueueDeclare(); |
| 16 | + |
| 17 | + if (args.Length < 1) |
| 18 | + { |
| 19 | + Console.Error.WriteLine("Usage: {0} [info] [warning] [error]", |
| 20 | + Environment.GetCommandLineArgs()[0]); |
| 21 | + Environment.ExitCode = 1; |
| 22 | + return; |
| 23 | + } |
| 24 | + |
| 25 | + foreach (string severity in args) |
| 26 | + { |
| 27 | + channel.QueueBind(queue_name, "direct_logs", severity); |
| 28 | + } |
| 29 | + |
| 30 | + Console.WriteLine(" [*] Waiting for messages. " + |
| 31 | + "To exit press CTRL+C"); |
| 32 | + |
| 33 | + var consumer = new QueueingBasicConsumer(channel); |
| 34 | + channel.BasicConsume(queue_name, true, consumer); |
| 35 | + |
| 36 | + while (true) |
| 37 | + { |
| 38 | + var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue(); |
| 39 | + |
| 40 | + var body = ea.Body; |
| 41 | + var message = System.Text.Encoding.UTF8.GetString(body); |
| 42 | + var routingKey = ea.RoutingKey; |
| 43 | + Console.WriteLine(" [x] Received '{0}':'{1}'", |
| 44 | + routingKey, message); |
| 45 | + } |
41 | 46 | } |
42 | 47 | } |
43 | 48 | } |
|
0 commit comments