示例#1
0
        internal async Task <AmqpIoTOutcome> SendMessageAsync(Message message, TimeSpan timeout)
        {
            if (Logging.IsEnabled)
            {
                Logging.Enter(this, message, $"{nameof(SendMessageAsync)}");
            }

            AmqpMessage amqpMessage = AmqpIoTMessageConverter.MessageToAmqpMessage(message);
            Outcome     outcome     = await SendAmqpMessageAsync(amqpMessage, timeout).ConfigureAwait(false);

            if (Logging.IsEnabled)
            {
                Logging.Exit(this, message, $"{nameof(SendMessageAsync)}");
            }

            return(new AmqpIoTOutcome(outcome));
        }
示例#2
0
        internal async Task <AmqpIoTOutcome> SendMessagesAsync(IEnumerable <Message> messages, TimeSpan timeout)
        {
            if (Logging.IsEnabled)
            {
                Logging.Enter(this, $"{nameof(SendMessagesAsync)}");
            }

            // List to hold messages in Amqp friendly format
            var messageList = new List <Data>();

            foreach (Message message in messages)
            {
                using (AmqpMessage amqpMessage = AmqpIoTMessageConverter.MessageToAmqpMessage(message))
                {
                    var data = new Data()
                    {
                        Value = AmqpIoTMessageConverter.ReadStream(amqpMessage.ToStream())
                    };
                    messageList.Add(data);
                }
            }

            Outcome outcome;

            using (AmqpMessage amqpMessage = AmqpMessage.Create(messageList))
            {
                amqpMessage.MessageFormat = AmqpConstants.AmqpBatchedMessageFormat;
                outcome = await SendAmqpMessageAsync(amqpMessage, timeout).ConfigureAwait(false);
            }

            AmqpIoTOutcome amqpIoTOutcome = new AmqpIoTOutcome(outcome);

            if (amqpIoTOutcome != null)
            {
                amqpIoTOutcome.ThrowIfNotAccepted();
            }

            if (Logging.IsEnabled)
            {
                Logging.Exit(this, $"{nameof(SendMessagesAsync)}");
            }

            return(amqpIoTOutcome);
        }
示例#3
0
        internal async Task <AmqpIoTOutcome> SendMessageAsync(Message message, TimeSpan timeout)
        {
            if (Logging.IsEnabled)
            {
                Logging.Enter(this, message, $"{nameof(SendMessageAsync)}");
            }

            // After this message is sent, we will return the outcome that has no references to the message
            // So it can safely be disposed.
            using AmqpMessage amqpMessage = AmqpIoTMessageConverter.MessageToAmqpMessage(message);
            Outcome outcome = await SendAmqpMessageAsync(amqpMessage, timeout).ConfigureAwait(false);

            if (Logging.IsEnabled)
            {
                Logging.Exit(this, message, $"{nameof(SendMessageAsync)}");
            }

            return(new AmqpIoTOutcome(outcome));
        }