Created
February 24, 2021 09:41
-
-
Save davidsarkany/da9adc1f8ad1106efc29d55cb86919cb to your computer and use it in GitHub Desktop.
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
public void receiveMessage() | |
{ | |
var factory = new ConnectionFactory(); | |
factory.HostName = host; | |
factory.UserName = username; | |
factory.Password = password; | |
using (var connection = factory.CreateConnection()) | |
{ | |
using (var channel = connection.CreateModel()) | |
{ | |
channel.QueueDeclare(queue: "hello", false, false, false, null); | |
channel.QueueBind("hello", "hellotest",""); | |
var consumer = new EventingBasicConsumer(channel); | |
consumer.Received += (ch, ea) => | |
{ | |
var body = ea.Body.ToArray(); | |
var message = Encoding.UTF8.GetString(body); | |
System.Diagnostics.Debug.WriteLine(" [x] Received: " + message); | |
}; | |
System.Diagnostics.Debug.WriteLine(channel.BasicConsume(queue: "hello", autoAck: true, consumer: consumer)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment