Skip to content

Commit e04c24a

Browse files
committed
Reformatted and cleaned up
1 parent e1d1649 commit e04c24a

File tree

1 file changed

+36
-31
lines changed

1 file changed

+36
-31
lines changed

dotnet/ReceiveLogsTopic.cs

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,48 @@
11
using System;
22
using RabbitMQ.Client;
33
using RabbitMQ.Client.Events;
4+
using System.Text;
45

5-
class ReceiveLogsTopic {
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-
channel.ExchangeDeclare("topic_logs", "topic");
12-
string queue_name = channel.QueueDeclare();
6+
class ReceiveLogsTopic
7+
{
8+
public static void Main(string[] args)
9+
{
10+
var factory = new ConnectionFactory() { HostName = "localhost" };
11+
using (var connection = factory.CreateConnection())
12+
{
13+
using (var channel = connection.CreateModel())
14+
{
15+
channel.ExchangeDeclare("topic_logs", "topic");
16+
var queueName = channel.QueueDeclare();
1317

14-
if (args.Length < 1) {
15-
Console.Error.WriteLine("Usage: {0} [binding_key...]",
16-
Environment.GetCommandLineArgs()[0]);
17-
Environment.ExitCode = 1;
18-
return;
19-
}
20-
21-
foreach (string bindingKey in args) {
22-
channel.QueueBind(queue_name, "topic_logs", bindingKey);
23-
}
18+
if (args.Length < 1)
19+
{
20+
Console.Error.WriteLine("Usage: {0} [binding_key...]",
21+
Environment.GetCommandLineArgs()[0]);
22+
Environment.ExitCode = 1;
23+
return;
24+
}
2425

25-
Console.WriteLine(" [*] Waiting for messages. " +
26-
"To exit press CTRL+C");
26+
foreach (var bindingKey in args)
27+
{
28+
channel.QueueBind(queueName, "topic_logs", bindingKey);
29+
}
2730

28-
QueueingBasicConsumer consumer =
29-
new QueueingBasicConsumer(channel);
30-
channel.BasicConsume(queue_name, true, consumer);
31+
Console.WriteLine(" [*] Waiting for messages. " +
32+
"To exit press CTRL+C");
3133

32-
while(true) {
33-
BasicDeliverEventArgs ea =
34-
(BasicDeliverEventArgs)consumer.Queue.Dequeue();
34+
var consumer = new QueueingBasicConsumer(channel);
35+
channel.BasicConsume(queueName, true, consumer);
3536

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);
37+
while (true)
38+
{
39+
var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
40+
var body = ea.Body;
41+
var message = Encoding.UTF8.GetString(body);
42+
var routingKey = ea.RoutingKey;
43+
Console.WriteLine(" [x] Received '{0}':'{1}'",
44+
routingKey, message);
45+
}
4146
}
4247
}
4348
}

0 commit comments

Comments
 (0)