Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. try {
  2. var factory = new ConnectionFactory() { HostName = "xxx" , UserName ="xxx", Password="xxx"};
  3. using(var connection = factory.CreateConnection())
  4. using(var channel = connection.CreateModel())
  5. {
  6. channel.ExchangeDeclare(exchange: "call_notify", type: "fanout");
  7.  
  8. var queueName = channel.QueueDeclare().QueueName;
  9. channel.QueueBind(queue: queueName,
  10. exchange: "call_notify",
  11. routingKey: "");
  12.  
  13. var consumer = new EventingBasicConsumer(channel);
  14. consumer.Received += (model, ea) =>
  15. {
  16. var body = ea.Body;
  17. var message = Encoding.UTF8.GetString(body);
  18. Console.WriteLine(message);
  19. };
  20. channel.BasicConsume(queue: queueName,
  21. autoAck: true,
  22. consumer: consumer);
  23.  
  24. Console.WriteLine(" Press [enter] to exit.");
  25. Console.ReadLine(); // Program does'nt wait here in windows form based application
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement