-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
33 lines (26 loc) · 1.11 KB
/
Program.cs
File metadata and controls
33 lines (26 loc) · 1.11 KB
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
30
31
32
33
using System.Text;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
var factory = new ConnectionFactory
{
// Uri = new Uri("amqps://fkucsvcj:LqAqt0v5ApdauHz4EbhyT-mizaXEKoEI@cow.rmq2.cloudamqp.com/fkucsvcj")
HostName = "localhost"
};
using var connection = factory.CreateConnection();
using var channel = connection.CreateModel();
//publisher projesnde bu kuyruk varsa bu satırı silebilirsin ama subscriberdan önce publisher projesini çalıştırman gerek yoksa hello-queue diye bi kuyruk oluşmadığı için hata verecektir.
// Eğer kuyruk publisher da varsa onu bağlanır yoksa yeni oluşturur.
channel.QueueDeclare(queue: "hello-queue", false, false, false, arguments: null);
channel.BasicQos(0, 10, false);
var consumer = new EventingBasicConsumer(channel);
channel.BasicConsume(queue: "hello-queue", autoAck: false, consumer: consumer);
consumer.Received += (sender, e) =>
{
var body = e.Body.ToArray();
var message = Encoding.UTF8.GetString(body);
Thread.Sleep(1000);
Console.WriteLine($"Gelen Mesaj: {message}");
channel.BasicAck(e.DeliveryTag, false);
};
Console.ReadLine();