Guest User

Untitled

a guest
Apr 15th, 2019
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 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 Consumer1
  10. {
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. var factory = new ConnectionFactory()
  16. {
  17. UserName = "amivnqqc",
  18. VirtualHost = "amivnqqc",
  19. HostName = "bulldog.rmq.cloudamqp.com",
  20. Password = "WyPz_1Vl1KoR3lUvzgZfm7IhWXWYdnlE"
  21. };
  22.  
  23. using (var connection = factory.CreateConnection())
  24. using (var channel = connection.CreateModel())
  25. {
  26. channel.QueueDeclare("ksr_queue", false, false, false, null);
  27.  
  28. var consumer = new EventingBasicConsumer(channel);
  29. consumer.Received += (model, ea) =>
  30. {
  31. var body = ea.Body;
  32. var message = Encoding.UTF8.GetString(body);
  33. Console.WriteLine("Message: '{0}'", message);
  34.  
  35. var responseBytes = Encoding.UTF8.GetBytes(DateTime.Now.ToLongTimeString());
  36. var replyProps = channel.CreateBasicProperties();
  37. replyProps.CorrelationId = ea.BasicProperties.CorrelationId;
  38.  
  39. channel.BasicPublish("", ea.BasicProperties.ReplyTo, replyProps, responseBytes);
  40.  
  41. channel.BasicAck(ea.DeliveryTag, false);
  42. };
  43. channel.BasicConsume("ksr_queue", false, consumer);
  44.  
  45. Console.ReadKey();
  46. }
  47. }
  48. }
  49. }
Add Comment
Please, Sign In to add comment