コード例 #1
0
        public object Clone()
        {
            var copy = new MessageProperties();

            if (contentTypePresent)
            {
                copy.ContentType = ContentType;
            }
            if (contentEncodingPresent)
            {
                copy.ContentEncoding = ContentEncoding;
            }
            if (deliveryModePresent)
            {
                copy.DeliveryMode = DeliveryMode;
            }
            if (priorityPresent)
            {
                copy.Priority = Priority;
            }
            if (correlationIdPresent)
            {
                copy.CorrelationId = CorrelationId;
            }
            if (replyToPresent)
            {
                copy.ReplyTo = ReplyTo;
            }
            if (expirationPresent)
            {
                copy.Expiration = Expiration;
            }
            if (messageIdPresent)
            {
                copy.MessageId = MessageId;
            }
            if (timestampPresent)
            {
                copy.Timestamp = Timestamp;
            }
            if (typePresent)
            {
                copy.Type = Type;
            }
            if (userIdPresent)
            {
                copy.UserId = UserId;
            }
            if (appIdPresent)
            {
                copy.AppId = AppId;
            }
            if (clusterIdPresent)
            {
                copy.ClusterId = ClusterId;
            }

            if (headersPresent)
            {
                copy.Headers = new Dictionary <string, object>(Headers);
            }

            return(copy);
        }
コード例 #2
0
        public virtual async Task PublishAsync(
            IExchange exchange,
            string routingKey,
            bool mandatory,
            MessageProperties messageProperties,
            byte[] body)
        {
            Preconditions.CheckNotNull(exchange, "exchange");
            Preconditions.CheckShortString(routingKey, "routingKey");
            Preconditions.CheckNotNull(messageProperties, "messageProperties");
            Preconditions.CheckNotNull(body, "body");

            // Fix me: It's very hard now to move publish logic to separate abstraction, just leave it here.
            var rawMessage = produceConsumeInterceptor.OnProduce(new RawMessage(messageProperties, body));

            if (connectionConfiguration.PublisherConfirms)
            {
                var timeBudget = new TimeBudget(TimeSpan.FromSeconds(connectionConfiguration.Timeout)).Start();
                while (!timeBudget.IsExpired())
                {
                    var confirmsWaiter = await clientCommandDispatcher.InvokeAsync(model =>
                    {
                        var properties = model.CreateBasicProperties();
                        rawMessage.Properties.CopyTo(properties);
                        var waiter = confirmationListener.GetWaiter(model);

                        try
                        {
                            model.BasicPublish(exchange.Name, routingKey, mandatory, properties, rawMessage.Body);
                        }
                        catch (Exception)
                        {
                            waiter.Cancel();
                            throw;
                        }

                        return(waiter);
                    }).ConfigureAwait(false);

                    try
                    {
                        await confirmsWaiter.WaitAsync(timeBudget.GetRemainingTime()).ConfigureAwait(false);

                        break;
                    }
                    catch (PublishInterruptedException)
                    {
                    }
                }
            }
            else
            {
                await clientCommandDispatcher.InvokeAsync(model =>
                {
                    var properties = model.CreateBasicProperties();
                    rawMessage.Properties.CopyTo(properties);
                    model.BasicPublish(exchange.Name, routingKey, mandatory, properties, rawMessage.Body);
                }).ConfigureAwait(false);
            }
            eventBus.Publish(new PublishedMessageEvent(exchange.Name, routingKey, rawMessage.Properties, rawMessage.Body));
            logger.DebugWrite("Published to exchange: '{0}', routing key: '{1}', correlationId: '{2}'", exchange.Name, routingKey, messageProperties.CorrelationId);
        }
コード例 #3
0
 public void SetProperties(MessageProperties properties)
 {
     Preconditions.CheckNotNull(properties, "properties");
     Properties = properties;
 }