Advertisement
Guest User

Untitled

a guest
Apr 15th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 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 RabbitLab
  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. string replyQueueName = channel.QueueDeclare().QueueName;
  28.  
  29. string message = "Wiadomość testowa";
  30. var body = Encoding.UTF8.GetBytes(message);
  31.  
  32. IBasicProperties props = channel.CreateBasicProperties();
  33. props.ReplyTo = replyQueueName;
  34.  
  35. var corrId = Guid.NewGuid().ToString();
  36. props.CorrelationId = corrId;
  37.  
  38. var replyConsumer = new EventingBasicConsumer(channel);
  39. replyConsumer.Received += (mode, ea) =>
  40. {
  41. if (ea.BasicProperties.CorrelationId == corrId)
  42. {
  43. Console.WriteLine("[{0}][{1}] Przyjęto zadanie", corrId, Encoding.UTF8.GetString(ea.Body));
  44. }
  45. };
  46.  
  47. channel.BasicConsume(replyQueueName, true, replyConsumer);
  48. channel.BasicPublish("", "ksr_queue", props, body);
  49.  
  50. Console.ReadKey();
  51. }
  52. }
  53.  
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement