protected override async Task OnSendEventAsync(IEnumerable <Message> messages) { // List to hold messages in Amqp friendly format var messageList = new List <Data>(); foreach (var message in messages) { using (AmqpMessage amqpMessage = message.ToAmqpMessage()) { var data = new Data() { Value = MessageConverter.ReadStream(amqpMessage.ToStream()) }; messageList.Add(data); } } Outcome outcome; using (var amqpMessage = AmqpMessage.Create(messageList)) { amqpMessage.MessageFormat = AmqpConstants.AmqpBatchedMessageFormat; outcome = await this.SendAmqpMessageAsync(amqpMessage); } if (outcome.DescriptorCode != Accepted.Code) { throw AmqpErrorMapper.GetExceptionFromOutcome(outcome); } }
protected async override Task OnSendEventAsync(Message message) { Outcome outcome; using (AmqpMessage amqpMessage = message.ToAmqpMessage()) { outcome = await this.SendAmqpMessageAsync(amqpMessage); } if (outcome.DescriptorCode != Accepted.Code) { throw AmqpErrorMapper.GetExceptionFromOutcome(outcome); } }
async Task DisposeMessageAsync(string lockToken, Outcome outcome) { var deliveryTag = IotHubConnection.ConvertToDeliveryTag(lockToken); Outcome disposeOutcome; try { ReceivingAmqpLink deviceBoundReceivingLink = await this.GetDeviceBoundReceivingLinkAsync(); disposeOutcome = await deviceBoundReceivingLink.DisposeMessageAsync(deliveryTag, outcome, batchable : true, timeout : this.OperationTimeout); } catch (Exception exception) { if (exception.IsFatal()) { throw; } throw AmqpClientHelper.ToIotHubClientContract(exception); } if (disposeOutcome.DescriptorCode != Accepted.Code) { if (disposeOutcome.DescriptorCode == Rejected.Code) { var rejected = (Rejected)disposeOutcome; // Special treatment for NotFound amqp rejected error code in case of DisposeMessage if (rejected.Error != null && rejected.Error.Condition.Equals(AmqpErrorCode.NotFound)) { throw new DeviceMessageLockLostException(rejected.Error.Description); } } throw AmqpErrorMapper.GetExceptionFromOutcome(disposeOutcome); } }