Advertisement
Guest User

Untitled

a guest
Jul 14th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. // Client is a wrapper around the RabbitMQ client
  2. for (var i = 0; i < 1000; ++i)
  3. {
  4. // Publish sequentially numbered messages
  5. client.Publish("routingkey", GetContent(i)));
  6. Thread.Sleep(100);
  7. }
  8.  
  9. public bool Publish(string routingKey, byte[] body)
  10. {
  11. try
  12. {
  13. using (var channel = _connection.CreateModel())
  14. {
  15. var basicProps = new BasicProperties
  16. {
  17. Persistent = true,
  18. };
  19.  
  20. channel.ExchangeDeclare(_exchange, _exchangeType);
  21. channel.BasicPublish(_exchange, routingKey, basicProps, body);
  22.  
  23. return true;
  24. }
  25. }
  26. catch (Exception e)
  27. {
  28. _logger.Log(e);
  29. }
  30.  
  31. return false;
  32. }
  33.  
  34. _connectionFactory = new ConnectionFactory
  35. {
  36. UserName = _userName,
  37. Password = _password,
  38. HostName = _hostName,
  39. Port = _port,
  40. Protocol = Protocols.DefaultProtocol,
  41. VirtualHost = _virtualHost,
  42.  
  43. // Doesn't seem to have any effect on broken connections
  44. RequestedConnectionTimeout = 20,
  45.  
  46. // The behaviour appears to be the same with or without these included
  47. // AutomaticRecoveryEnabled = true,
  48. // NetworkRecoveryInterval = TimeSpan.FromSeconds(10),
  49. };
  50.  
  51. _connection = _connectionFactory.CreateConnection();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement