forked from v.moiseev/distributed-computing
28 lines
765 B
C#
28 lines
765 B
C#
using System.Text;
|
|
using RabbitMQ.Client;
|
|
|
|
var factory = new ConnectionFactory { HostName = "localhost" };
|
|
using var connection = factory.CreateConnection();
|
|
using var channel = connection.CreateModel();
|
|
|
|
channel.QueueDeclare(queue: "hello",
|
|
durable: false,
|
|
exclusive: false,
|
|
autoDelete: false,
|
|
arguments: null);
|
|
|
|
foreach (var item in Enumerable.Range(0, 100))
|
|
{
|
|
string message = "Hello World!";
|
|
var body = Encoding.UTF8.GetBytes(message + item);
|
|
channel.BasicPublish(exchange: string.Empty,
|
|
routingKey: "hello",
|
|
basicProperties: null,
|
|
body: body);
|
|
Console.WriteLine($" [x] Sent {message} iteration {item}");
|
|
await Task.Delay(1000);
|
|
}
|
|
|
|
|
|
Console.WriteLine(" Press [enter] to exit.");
|
|
Console.ReadLine(); |