work 2.2 done
This commit is contained in:
parent
060bd2321e
commit
94b8ba783c
@ -5,8 +5,8 @@ var factory = new ConnectionFactory { HostName = "localhost" };
|
||||
using var connection = factory.CreateConnection();
|
||||
using var channel = connection.CreateModel();
|
||||
|
||||
channel.QueueDeclare(queue: "hello",
|
||||
durable: false,
|
||||
channel.QueueDeclare(queue: "task_queue",
|
||||
durable: true,
|
||||
exclusive: false,
|
||||
autoDelete: false,
|
||||
arguments: null);
|
||||
@ -14,9 +14,12 @@ channel.QueueDeclare(queue: "hello",
|
||||
var message = GetMessage(args);
|
||||
var body = Encoding.UTF8.GetBytes(message);
|
||||
|
||||
var properties = channel.CreateBasicProperties();
|
||||
properties.Persistent = true;
|
||||
|
||||
channel.BasicPublish(exchange: string.Empty,
|
||||
routingKey: "hello",
|
||||
basicProperties: null,
|
||||
routingKey: "task_queue",
|
||||
basicProperties: properties,
|
||||
body: body);
|
||||
Console.WriteLine($" [x] Sent {message}");
|
||||
|
||||
|
@ -6,18 +6,20 @@ var factory = new ConnectionFactory { HostName = "localhost" };
|
||||
using var connection = factory.CreateConnection();
|
||||
using var channel = connection.CreateModel();
|
||||
|
||||
channel.QueueDeclare(queue: "hello",
|
||||
durable: false,
|
||||
channel.QueueDeclare(queue: "task_queue",
|
||||
durable: true,
|
||||
exclusive: false,
|
||||
autoDelete: false,
|
||||
arguments: null);
|
||||
|
||||
channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false);
|
||||
|
||||
Console.WriteLine(" [*] Waiting for messages.");
|
||||
|
||||
var consumer = new EventingBasicConsumer(channel);
|
||||
consumer.Received += (model, ea) =>
|
||||
{
|
||||
var body = ea.Body.ToArray();
|
||||
byte[] body = ea.Body.ToArray();
|
||||
var message = Encoding.UTF8.GetString(body);
|
||||
Console.WriteLine($" [x] Received {message}");
|
||||
|
||||
@ -25,9 +27,12 @@ consumer.Received += (model, ea) =>
|
||||
Thread.Sleep(dots * 1000);
|
||||
|
||||
Console.WriteLine(" [x] Done");
|
||||
|
||||
// here channel could also be accessed as ((EventingBasicConsumer)sender).Model
|
||||
channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
|
||||
};
|
||||
channel.BasicConsume(queue: "hello",
|
||||
autoAck: true,
|
||||
channel.BasicConsume(queue: "task_queue",
|
||||
autoAck: false,
|
||||
consumer: consumer);
|
||||
|
||||
Console.WriteLine(" Press [enter] to exit.");
|
||||
|
Loading…
Reference in New Issue
Block a user