forked from rabbitmq/rabbitmq-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReceive.cs
27 lines (23 loc) · 1.01 KB
/
Receive.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
class Receive {
public static void Main() {
ConnectionFactory factory = new ConnectionFactory();
factory.HostName = "localhost";
using (IConnection connection = factory.CreateConnection())
using (IModel channel = connection.CreateModel()) {
channel.QueueDeclare("hello", false, false, false, null);
QueueingBasicConsumer consumer = new QueueingBasicConsumer(channel);
channel.BasicConsume("hello", true, consumer);
System.Console.WriteLine(" [*] Waiting for messages." +
"To exit press CTRL+C");
while(true) {
BasicDeliverEventArgs ea =
(BasicDeliverEventArgs)consumer.Queue.Dequeue();
byte[] body = ea.Body;
string message = System.Text.Encoding.UTF8.GetString(body);
System.Console.WriteLine(" [x] Received {0}", message);
}
}
}
}