forked from rabbitmq/rabbitmq-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReceive.cs
29 lines (24 loc) · 1.02 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
28
29
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
namespace Receive {
class Program {
static void Main(string[] args) {
ConnectionFactory factory = new ConnectionFactory();
factory.HostName = "localhost";
IConnection connection = factory.CreateConnection();
IModel channel = connection.CreateModel();
channel.QueueDeclare("hello");
QueueingBasicConsumer consumer = new QueueingBasicConsumer(channel);
channel.BasicConsume("hello", true, null, 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);
}
}
}
}