rabbitmq-tutorials/dotnet/Send/Send.cs
Luke Bakken a4adce94c9
Update dotnet tutorials to use 7.0.0
* Specify unix line endings so that `christian-bromann/docusaurus-theme-github-codeblock` formats code blocks correctly
* Fix RPC examples
2024-11-06 08:44:10 -08:00

19 lines
637 B
C#

using RabbitMQ.Client;
using System.Text;
var factory = new ConnectionFactory { HostName = "localhost" };
using var connection = await factory.CreateConnectionAsync();
using var channel = await connection.CreateChannelAsync();
await channel.QueueDeclareAsync(queue: "hello", durable: false, exclusive: false, autoDelete: false,
arguments: null);
const string message = "Hello World!";
var body = Encoding.UTF8.GetBytes(message);
await channel.BasicPublishAsync(exchange: string.Empty, routingKey: "hello", body: body);
Console.WriteLine($" [x] Sent {message}");
Console.WriteLine(" Press [enter] to exit.");
Console.ReadLine();