Beispiel #1
0
        public void RepublishError(Error error, QueueParameters parameters)
        {
            using (var connection = HosepipeConnection.FromParameters(parameters))
                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 = errorMessageSerializer.Deserialize(error.Message);

                        model.BasicPublish(error.Exchange, error.RoutingKey, true, properties, body);
                    }
                    catch (OperationInterruptedException)
                    {
                        Console.WriteLine("The exchange, '{0}', described in the error message does not exist on '{1}', '{2}'",
                                          error.Exchange, parameters.HostName, parameters.VHost);
                    }
                }
        }
Beispiel #2
0
 public void RepublishError(Error error, QueueParameters parameters)
 {
     using (var connection = HosepipeConnection.FromParameters(parameters))
         using (var model = connection.CreateModel())
         {
             var properties = model.CreateBasicProperties();
             error.BasicProperties.CopyTo(properties);
             var body = errorMessageSerializer.Deserialize(error.Message);
             model.BasicPublish("", error.Queue, true, properties, body);
         }
 }
Beispiel #3
0
        public void PublishMessagesToQueue(IEnumerable <HosepipeMessage> messages, QueueParameters parameters)
        {
            using (var connection = HosepipeConnection.FromParameters(parameters))
                using (var channel = connection.CreateModel())
                {
                    foreach (var message in messages)
                    {
                        var body = errorMessageSerializer.Deserialize(message.Body);

                        var properties = channel.CreateBasicProperties();
                        message.Properties.CopyTo(properties);

                        channel.BasicPublish(message.Info.Exchange, message.Info.RoutingKey, true, properties, body);
                    }
                }
        }
Beispiel #4
0
        public void RetryErrors(IEnumerable <HosepipeMessage> rawErrorMessages, QueueParameters parameters)
        {
            using var connection = HosepipeConnection.FromParameters(parameters);
            using var model      = connection.CreateModel();

            model.ConfirmSelect();

            foreach (var rawErrorMessage in rawErrorMessages)
            {
                var error      = (Error)serializer.BytesToMessage(typeof(Error), errorMessageSerializer.Deserialize(rawErrorMessage.Body));
                var properties = model.CreateBasicProperties();
                error.BasicProperties.CopyTo(properties);
                var body = errorMessageSerializer.Deserialize(error.Message);
                model.BasicPublish("", error.Queue, true, properties, body);
                model.WaitForConfirmsOrDie();
            }
        }
Beispiel #5
0
        public void PublishMessagesToQueue(IEnumerable <HosepipeMessage> messages, QueueParameters parameters)
        {
            using (var connection = HosepipeConnection.FromParameters(parameters))
                using (var channel = connection.CreateModel())
                {
                    foreach (var message in messages)
                    {
                        var body = errorMessageSerializer.Deserialize(message.Body);

                        var properties = channel.CreateBasicProperties();
                        message.Properties.CopyTo(properties);

                        var queueName = string.IsNullOrEmpty(parameters.QueueName)
                        ? message.Info.Queue
                        : parameters.QueueName;
                        channel.BasicPublish("", queueName, true, properties, body);
                    }
                }
        }
Beispiel #6
0
        public void RetryErrors(IEnumerable <HosepipeMessage> rawErrorMessages, QueueParameters parameters)
        {
            using var connection = HosepipeConnection.FromParameters(parameters);
            using var model      = connection.CreateModel();
            model.ConfirmSelect();

            var errors = rawErrorMessages
                         .Select(x => (Error)serializer.BytesToMessage(typeof(Error), errorMessageSerializer.Deserialize(x.Body)))
                         .ToArray();

            var tempExchangeName = DeclareTemporaryExchange(model);

            try
            {
                RouteMessagesToExchange(model, tempExchangeName, errors);
                PublishMessages(model, tempExchangeName, errors);
            }
            finally
            {
                model.ExchangeDelete(tempExchangeName);
            }
        }
Beispiel #7
0
        public IEnumerable <HosepipeMessage> GetMessagesFromQueue(QueueParameters parameters)
        {
            using (var connection = HosepipeConnection.FromParameters(parameters))
                using (var channel = connection.CreateModel())
                {
                    try
                    {
                        channel.QueueDeclarePassive(parameters.QueueName);
                    }
                    catch (OperationInterruptedException exception)
                    {
                        Console.WriteLine(exception.Message);
                        yield break;
                    }

                    var count = 0;
                    while (count++ < parameters.NumberOfMessagesToRetrieve)
                    {
                        var basicGetResult = channel.BasicGet(parameters.QueueName, parameters.Purge);
                        if (basicGetResult == null)
                        {
                            break;                     // no more messages on the queue
                        }
                        var properties = new MessageProperties(basicGetResult.BasicProperties);
                        var info       = new MessageReceivedInfo(
                            "hosepipe",
                            basicGetResult.DeliveryTag,
                            basicGetResult.Redelivered,
                            basicGetResult.Exchange,
                            basicGetResult.RoutingKey,
                            parameters.QueueName
                            );

                        yield return(new HosepipeMessage(errorMessageSerializer.Serialize(basicGetResult.Body.ToArray()), properties, info));
                    }
                }
        }