Created
November 28, 2021 11:40
-
-
Save irfan-yusanif/cadc1f46be749de8e5d3e0e11400d2db to your computer and use it in GitHub Desktop.
Send message to Queue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using RabbitMQ.Client; | |
using System.Text; | |
class Send | |
{ | |
public static void Main() | |
{ | |
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); | |
string message = "Hello World!"; | |
var body = Encoding.UTF8.GetBytes(message); | |
channel.BasicPublish(exchange: "", routingKey: "hello", basicProperties: null, body: body); | |
Console.WriteLine(" [x] Sent {0}", message); | |
} | |
Console.WriteLine(" Press [enter] to exit."); | |
Console.ReadLine(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment