public void RepublishError(Error error, IQueueOptions options) { using (var connection = RabbitConnection.FromOptions(options)) using (var model = connection.CreateModel()) { try { if (error.Exchange != string.Empty) { model.ExchangeDeclarePassive(error.Exchange); } var properties = model.CreateBasicProperties(); error.BasicProperties.CopyTo(properties); var body = Encoding.UTF8.GetBytes(error.Message); model.BasicPublish(error.Exchange, error.RoutingKey, properties, body); } catch (OperationInterruptedException) { Log.ErrorFormat("The exchange, '{0}', described in the error message does not exist on '{1}', '{2}'", error.Exchange, options.HostName, options.VirtualHost); } } }
public void Should_republish_to_default_exchange() { var error = new Error { Exchange = "", // default exchange RoutingKey = "hosepipe.test", Message = "Hosepipe test message", BasicProperties = new MessageProperties() }; var parameters = new QueueParameters { HostName = "localhost", Username = "******", Password = "******", MessageFilePath = @"C:\temp\MessageOutput" }; errorRetry.RepublishError(error, parameters); }