Skip to content

Instantly share code, notes, and snippets.

@lucascebertin
Created April 25, 2018 18:06
Show Gist options
  • Select an option

  • Save lucascebertin/31c748ff9ecca389b00a01220f118a4a to your computer and use it in GitHub Desktop.

Select an option

Save lucascebertin/31c748ff9ecca389b00a01220f118a4a to your computer and use it in GitHub Desktop.
RabbitMQ Producer - C#
public static void Main(string[] args)
{
var factory = new ConnectionFactory() { HostName = "localhost" };
using (var connection = factory.CreateConnection())
using (var channel = connection.CreateModel())
{
channel.QueueDeclare("hello", true, false, false, null);
var message = new TestMessage(1, "test", $"{args.FirstOrDefault()} Hello World!");
var json = JsonConvert.SerializeObject(message);
var body = Encoding.UTF8.GetBytes(json);
channel.BasicPublish("", "hello", null, body);
Console.WriteLine(" [x] Sent {0}", message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment