Skip to content

Instantly share code, notes, and snippets.

@davidsarkany
Created February 24, 2021 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidsarkany/da9adc1f8ad1106efc29d55cb86919cb to your computer and use it in GitHub Desktop.
Save davidsarkany/da9adc1f8ad1106efc29d55cb86919cb to your computer and use it in GitHub Desktop.
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