private static void HandleErrorConfig(SubscriptionConfiguration subscriptionConfig, IModel channel)
        {
            if (
                subscriptionConfig.ErrorHandling == null
                ||
                !subscriptionConfig.ErrorHandling.EnableErrorQueue
                ||
                string.IsNullOrEmpty(subscriptionConfig.ErrorHandling.ErrorQueueName)) return;

            channel.QueueDeclare(subscriptionConfig.ErrorHandling.ErrorQueueName, true, false,
                                                       false, null);
        }
Exemple #2
0
        protected void HandleReceivedMessage(IModel channel, SubscriptionConfiguration subscription, BasicGetResult result)
        {
            var messageProperties = BuildMessageProperties(channel, subscription, result.BasicProperties);

            ReceivedMessage message = null;
            try
            {
                OnMessageReceived(result.Body, result.Exchange, result.RoutingKey, messageProperties, out message);
            }
            catch (Exception e)
            {
                Logger.Log("Exception occureed while receiving message");
                Logger.Log("Message: " + e.Message);
                Logger.Log("Stacktrace: " + e.StackTrace);
                ErrorHandler.HandleError(message, EndpointName);
                if (ErrorHandler.ShouldRethrowExceptions(EndpointName)) throw;
            }
            finally
            {
                AckMessage(channel, result.DeliveryTag, subscription.NoAck, message);
            }
        }
Exemple #3
0
        private MessageProperties BuildMessageProperties(IModel channel, SubscriptionConfiguration subscription, IBasicProperties properties)
        {
            var messageProperties = new MessageProperties
            {
                MessageId = properties.MessageId,
                CorrelationId = properties.CorrelationId,
                ContentType = properties.ContentType,
                ContentEncoding = properties.ContentEncoding
            };
            if (properties.Headers != null && properties.Headers.Keys.Count > 0)
            {
                foreach (var key in properties.Headers.Keys)
                {
                    try
                    {
                        var val = GetStringFromByteArray(properties.Headers[key], properties.ContentEncoding) ?? string.Empty;
                        messageProperties.Headers.Add(key.ToString(), val);
                    }
                    catch { }

                }
            }
            return messageProperties;
        }