public static AmqpMessage ToAmqpMessage(this ServiceBusMessage message) { if (message.AmqpMessage.Body.TryGetData(out IEnumerable <ReadOnlyMemory <byte> > dataBody)) { return(AmqpMessage.Create(dataBody.AsAmqpData())); } if (message.AmqpMessage.Body.TryGetValue(out object value)) { if (AmqpMessageConverter.TryGetAmqpObjectFromNetObject(value, MappingType.MessageBody, out object amqpObject)) { return(AmqpMessage.Create(new AmqpValue { Value = amqpObject })); } else { throw new NotSupportedException(Resources.InvalidAmqpMessageValueBody.FormatForUser(amqpObject?.GetType())); } } if (message.AmqpMessage.Body.TryGetSequence(out IEnumerable <IList <object> > sequence)) { return(AmqpMessage.Create(sequence.Select(s => new AmqpSequence((IList)s)).ToList())); } throw new NotSupportedException($"{message.AmqpMessage.Body.GetType()} is not a supported message body type."); }
/// <summary> /// Updates the disposition status of deferred messages. /// </summary> /// /// <param name="lockTokens">Message lock tokens to update disposition status.</param> /// <param name="timeout"></param> /// <param name="dispositionStatus"></param> /// <param name="isSessionReceiver"></param> /// <param name="sessionId"></param> /// <param name="receiveLinkName"></param> /// <param name="propertiesToModify"></param> /// <param name="deadLetterReason"></param> /// <param name="deadLetterDescription"></param> internal override async Task DisposeMessageRequestResponseAsync( Guid[] lockTokens, TimeSpan timeout, DispositionStatus dispositionStatus, bool isSessionReceiver, string sessionId = null, string receiveLinkName = null, IDictionary <string, object> propertiesToModify = null, string deadLetterReason = null, string deadLetterDescription = null) { try { // Create an AmqpRequest Message to update disposition var amqpRequestMessage = AmqpRequestMessage.CreateRequest(ManagementConstants.Operations.UpdateDispositionOperation, timeout, null); if (receiveLinkName != null) { amqpRequestMessage.AmqpMessage.ApplicationProperties.Map[ManagementConstants.Request.AssociatedLinkName] = receiveLinkName; } amqpRequestMessage.Map[ManagementConstants.Properties.LockTokens] = lockTokens; amqpRequestMessage.Map[ManagementConstants.Properties.DispositionStatus] = dispositionStatus.ToString().ToLowerInvariant(); if (deadLetterReason != null) { amqpRequestMessage.Map[ManagementConstants.Properties.DeadLetterReason] = deadLetterReason; } if (deadLetterDescription != null) { amqpRequestMessage.Map[ManagementConstants.Properties.DeadLetterDescription] = deadLetterDescription; } if (propertiesToModify != null) { var amqpPropertiesToModify = new AmqpMap(); foreach (var pair in propertiesToModify) { if (AmqpMessageConverter.TryGetAmqpObjectFromNetObject(pair.Value, MappingType.ApplicationProperty, out var amqpObject)) { amqpPropertiesToModify[new MapKey(pair.Key)] = amqpObject; } else { throw new NotSupportedException( Resources.InvalidAmqpMessageProperty.FormatForUser(pair.Key.GetType())); } } if (amqpPropertiesToModify.Count > 0) { amqpRequestMessage.Map[ManagementConstants.Properties.PropertiesToModify] = amqpPropertiesToModify; } } if (!string.IsNullOrWhiteSpace(sessionId)) { amqpRequestMessage.Map[ManagementConstants.Properties.SessionId] = sessionId; } if (isSessionReceiver) { // TODO - ThrowIfSessionLockLost(); } var amqpResponseMessage = await ExecuteRequestResponseAsync(amqpRequestMessage, timeout).ConfigureAwait(false); if (amqpResponseMessage.StatusCode != AmqpResponseStatusCode.OK) { // throw amqpResponseMessage.ToMessagingContractException(); } } catch (Exception) { // throw AmqpExceptionHelper.GetClientException(exception); throw; } }