Guest User

Untitled

a guest
Jan 28th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. using RabbitMQ.Client;
  2. using System;
  3. using System.Text;
  4.  
  5. namespace HelloWorld_RabbitMQ
  6. {
  7. class Producer
  8. {
  9. private const string exchangeName = "HelloWorld_RabbitMQ";
  10. private const string queueName = "HelloQueue";
  11. public static void Main(string[] args)
  12. {
  13. ConnectionFactory factory = new ConnectionFactory { HostName = "localhost", UserName = "guest", Password = "guest", Port = 5672 };
  14.  
  15. using (IConnection connection = factory.CreateConnection())
  16. {
  17. using (IModel channel = connection.CreateModel())
  18. {
  19. channel.ExchangeDeclare(exchangeName, ExchangeType.Fanout);
  20. channel.QueueDeclare(queue: queueName,
  21. durable: false,
  22. exclusive: false,
  23. autoDelete: false,
  24. arguments: null);
  25.  
  26. string message = "Hello World. This is my first RabbitMQ Message";
  27. var body = Encoding.UTF8.GetBytes(message);
  28. channel.QueueBind(queueName, exchangeName, string.Empty);
  29.  
  30. channel.BasicPublish(exchange:exchangeName,
  31. routingKey: string.Empty,
  32. basicProperties: null,
  33. body: body);
  34. Console.WriteLine("Message Sent Successfully - {0}", message);
  35.  
  36. }
  37. }
  38. Console.ReadLine();
  39. }
  40. }
  41. }
Add Comment
Please, Sign In to add comment