Esempio n. 1
0
 public Delivery(string consumerTag, Envelope envelope, RC.IBasicProperties properties, byte[] body, string queue)
 {
     ConsumerTag = consumerTag;
     Envelope    = envelope;
     Properties  = properties;
     Body        = body;
     Queue       = queue;
 }
Esempio n. 2
0
        public virtual void FromMessageHeaders(IMessageHeaders headers, RC.IBasicProperties target, Encoding charset)
        {
            var source = headers;

            target.Headers = ConvertHeadersIfNecessary(headers);
            if (source.Timestamp.HasValue)
            {
                target.Timestamp = new RC.AmqpTimestamp(source.Timestamp.Value);
            }

            if (source.Id != null)
            {
                target.MessageId = source.Id;
            }

            if (source.UserId() != null)
            {
                target.UserId = source.UserId();
            }

            if (source.AppId() != null)
            {
                target.AppId = source.AppId();
            }

            if (source.ClusterId() != null)
            {
                target.ClusterId = source.ClusterId();
            }

            if (source.Type() != null)
            {
                target.Type = source.Type();
            }

            if (source.DeliveryMode().HasValue)
            {
                target.DeliveryMode = (byte)source.DeliveryMode().Value;
            }
            else
            {
                target.DeliveryMode = (byte)RabbitHeaderAccessor.DEFAULT_DELIVERY_MODE;
            }

            if (source.Expiration() != null)
            {
                target.Expiration = source.Expiration();
            }

            if (source.Priority().HasValue)
            {
                target.Priority = (byte)source.Priority().Value;
            }

            if (source.ContentType() != null)
            {
                target.ContentType = source.ContentType();
            }

            if (source.ContentEncoding() != null)
            {
                target.ContentEncoding = source.ContentEncoding();
            }

            var correlationId = source.CorrelationId();

            if (!string.IsNullOrEmpty(correlationId))
            {
                target.CorrelationId = correlationId;
            }

            var replyTo = source.ReplyTo();

            if (replyTo != null)
            {
                target.ReplyTo = replyTo;
            }
        }
Esempio n. 3
0
        public virtual IMessageHeaders ToMessageHeaders(RC.IBasicProperties source, Envelope envelope, Encoding charset)
        {
            var target  = new RabbitHeaderAccessor();
            var headers = source.Headers;

            if (headers?.Count > 0)
            {
                foreach (var entry in headers)
                {
                    var key = entry.Key;
                    if (RabbitMessageHeaders.X_DELAY.Equals(key))
                    {
                        var value = entry.Value;
                        if (value is int intVal)
                        {
                            target.ReceivedDelay = intVal;
                        }
                    }
                    else
                    {
                        target.SetHeader(key, ConvertLongStringIfNecessary(entry.Value, charset));
                    }
                }
            }

            target.Timestamp      = source.Timestamp.UnixTime;
            target.MessageId      = source.MessageId;
            target.ReceivedUserId = source.UserId;
            target.AppId          = source.AppId;
            target.ClusterId      = source.ClusterId;
            target.Type           = source.Type;
            var deliveryMode = (int)source.DeliveryMode;

            target.ReceivedDeliveryMode = (MessageDeliveryMode)Enum.ToObject(typeof(MessageDeliveryMode), deliveryMode);
            target.DeliveryMode         = null;
            target.Expiration           = source.Expiration;
            target.Priority             = source.Priority;

            target.ContentType = source.ContentType;

            target.ContentEncoding = source.ContentEncoding;
            var correlationId = source.CorrelationId;

            if (!string.IsNullOrEmpty(correlationId))
            {
                target.CorrelationId = correlationId;
            }

            var replyTo = source.ReplyTo;

            if (replyTo != null)
            {
                target.ReplyTo = replyTo;
            }

            if (envelope != null)
            {
                target.ReceivedExchange   = envelope.Exchange;
                target.ReceivedRoutingKey = envelope.RoutingKey;
                target.Redelivered        = envelope.Redeliver;
                target.DeliveryTag        = envelope.DeliveryTag;
            }

            target.LeaveMutable = true;
            return(target.MessageHeaders);
        }
            public override void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, RC.IBasicProperties properties, byte[] body)
            {
                Logger?.LogDebug("Storing delivery for consumer tag: {tag} with deliveryTag: {deliveryTag} for consumer: {consumer}", ConsumerTag, deliveryTag, ToString());
                try
                {
                    var delivery = new Delivery(consumerTag, new Envelope(deliveryTag, redelivered, exchange, routingKey), properties, body, QueueName);
                    if (Consumer.AbortStarted > 0)
                    {
                        if (!Consumer.Queue.TryAdd(delivery, Consumer.ShutdownTimeout))
                        {
                            RabbitUtils.SetPhysicalCloseRequired(Model, true);
                            _ = Consumer.Queue.TakeWhile((d) => Consumer.Queue.Count > 0);
                            if (!Canceled)
                            {
                                RabbitUtils.Cancel(Model, consumerTag);
                            }

                            try
                            {
                                Model.Close();
                            }
                            catch (Exception)
                            {
                                // Noop
                            }
                        }
                    }
                    else
                    {
                        Consumer.Queue.TryAdd(delivery);
                    }
                }
                catch (Exception e)
                {
                    Logger?.LogWarning(e, "Unexpected exception during delivery");
                }
            }
 public void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, R.IBasicProperties properties, byte[] body)
 {
     Delegate.HandleBasicDeliver(consumerTag, deliveryTag, redelivered, exchange, routingKey, properties, body);
 }
Esempio n. 6
0
            public override void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, R.IBasicProperties properties, byte[] body)
            {
                var envelope          = new Envelope(deliveryTag, redelivered, exchange, routingKey);
                var messageProperties = _container.MessagePropertiesConverter.ToMessageProperties(properties, envelope, EncodingUtils.Utf8);

                messageProperties.ConsumerTag   = consumerTag;
                messageProperties.ConsumerQueue = Queue;
                var message = new Message(body, messageProperties);

                _logger?.LogDebug(this + " received " + message);
                _container.UpdateLastReceive();

                if (TransactionManager != null)
                {
                    try
                    {
                        ExecuteListenerInTransaction(message, deliveryTag);
                    }

                    // catch (WrappedTransactionException e)
                    // {
                    //    if (e.InnerException instanceof Error) {
                    //        throw (Error)e.getCause();
                    //    }
                    // }
                    catch (Exception)
                    {
                        // empty
                    }
                    finally
                    {
                        if (IsRabbitTxManager)
                        {
                            ConsumerChannelRegistry.UnRegisterConsumerChannel();
                        }
                    }
                }
                else
                {
                    try
                    {
                        CallExecuteListener(message, deliveryTag);
                    }
                    catch (Exception e)
                    {
                        // NOSONAR
                    }
                }
            }