Created
November 28, 2021 11:45
-
-
Save irfan-yusanif/b5342af1a5af2d9804aa0b3eca63b979 to your computer and use it in GitHub Desktop.
Receive message
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 RabbitMQ.Client; | |
using RabbitMQ.Client.Events; | |
using System; | |
using System.Text; | |
class Receive | |
{ | |
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); | |
Console.WriteLine(" [*] Waiting for messages."); | |
var consumer = new EventingBasicConsumer(channel); | |
consumer.Received += (model, ea) => | |
{ | |
var body = ea.Body.ToArray(); | |
var message = Encoding.UTF8.GetString(body); | |
Console.WriteLine(" [x] Received {0}", message); | |
}; | |
channel.BasicConsume(queue: "hello", autoAck: true, consumer: consumer); | |
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