Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Client is a wrapper around the RabbitMQ client
- for (var i = 0; i < 1000; ++i)
- {
- // Publish sequentially numbered messages
- client.Publish("routingkey", GetContent(i)));
- Thread.Sleep(100);
- }
- public bool Publish(string routingKey, byte[] body)
- {
- try
- {
- using (var channel = _connection.CreateModel())
- {
- var basicProps = new BasicProperties
- {
- Persistent = true,
- };
- channel.ExchangeDeclare(_exchange, _exchangeType);
- channel.BasicPublish(_exchange, routingKey, basicProps, body);
- return true;
- }
- }
- catch (Exception e)
- {
- _logger.Log(e);
- }
- return false;
- }
- _connectionFactory = new ConnectionFactory
- {
- UserName = _userName,
- Password = _password,
- HostName = _hostName,
- Port = _port,
- Protocol = Protocols.DefaultProtocol,
- VirtualHost = _virtualHost,
- // Doesn't seem to have any effect on broken connections
- RequestedConnectionTimeout = 20,
- // The behaviour appears to be the same with or without these included
- // AutomaticRecoveryEnabled = true,
- // NetworkRecoveryInterval = TimeSpan.FromSeconds(10),
- };
- _connection = _connectionFactory.CreateConnection();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement