Advertisement
Guest User

Untitled

a guest
May 7th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. using RabbitMQ.Client;
  2. using RabbitMQ.Client.Events;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace konsument {
  10. class MyConsumer: DefaultBasicConsumer {
  11. public MyConsumer(IModel model) : base(model) {
  12.  
  13. }
  14. public override void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, IBasicProperties properties, byte[] body) {
  15. var message = Encoding.UTF8.GetString(body);
  16. Console.WriteLine(message);
  17. }
  18.  
  19. }
  20. class Program {
  21. static void Main(string[] args) {
  22. var factory = new ConnectionFactory() {
  23. UserName = "qrabuqlb",
  24. Password = "1ewwXuKpWcRJHaVinKjbrz5pTJveGBAr",
  25. HostName = "bear-01.rmq.cloudamqp.com",
  26. VirtualHost = "qrabuqlb"
  27. };
  28. using (var connection = factory.CreateConnection())
  29. using (var channel = connection.CreateModel()) {
  30. var consumer = new MyConsumer(channel);
  31.  
  32. // headers start
  33. var queueName = channel.QueueDeclare().QueueName;
  34. var headers = new Dictionary<string, object>
  35. {
  36. { "x-match", "all" },
  37. {"part", "first"},
  38. {"number", 42 }
  39. };
  40. channel.QueueBind(queueName, "head_rout", "", headers);
  41. // headers end
  42.  
  43. // topics start
  44. //channel.ExchangeDeclare("top_rout", "topic");
  45. //var queueName = channel.QueueDeclare().QueueName;
  46. //channel.QueueBind(queueName, "top_rout", "lazy.pink.rabbit");
  47. //topics end
  48.  
  49. channel.BasicConsume("s160236_queue1", true, consumer);
  50. Console.ReadKey();
  51. }
  52. }
  53.  
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement