public TriggeredFunctionData GetTriggerFunctionData() { if (Messages.Length > 0) { Message message = Messages[0]; if (IsSingleDispatch) { Guid?parentId = ServiceBusCausalityHelper.GetOwner(message); return(new TriggeredFunctionData() { ParentId = parentId, TriggerValue = this, TriggerDetails = new Dictionary <string, string>() { { "MessageId", message.MessageId }, { "DeliveryCount", message.SystemProperties.DeliveryCount.ToString() }, { "EnqueuedTimeUtc", message.SystemProperties.EnqueuedTimeUtc.ToString() }, { "LockedUntilUtc", message.SystemProperties.LockedUntilUtc.ToString() }, { "SessionId", message.SessionId } } }); } else { Guid?parentId = ServiceBusCausalityHelper.GetOwner(message); int length = Messages.Length; string[] messageIds = new string[length]; int[] deliveryCounts = new int[length]; DateTime[] enqueuedTimes = new DateTime[length]; DateTime[] lockedUntils = new DateTime[length]; string sessionId = string.Empty; sessionId = Messages[0].SystemProperties.LockedUntilUtc.ToString(); for (int i = 0; i < Messages.Length; i++) { messageIds[i] = Messages[i].MessageId; deliveryCounts[i] = Messages[i].SystemProperties.DeliveryCount; enqueuedTimes[i] = Messages[i].SystemProperties.EnqueuedTimeUtc; lockedUntils[i] = Messages[i].SystemProperties.LockedUntilUtc; } return(new TriggeredFunctionData() { ParentId = parentId, TriggerValue = this, TriggerDetails = new Dictionary <string, string>() { { "MessageIdArray", string.Join(",", messageIds) }, { "DeliveryCountArray", string.Join(",", deliveryCounts) }, { "EnqueuedTimeUtcArray", string.Join(",", enqueuedTimes) }, { "LockedUntilArray", string.Join(",", lockedUntils) }, { "SessionId", sessionId } } }); } } return(null); }
public static async Task SendAndCreateQueueIfNotExistsAsync(this MessageSender sender, BrokeredMessage message, Guid functionInstanceId, NamespaceManager namespaceManager, AccessRights accessRights, CancellationToken cancellationToken) { if (sender == null) { throw new ArgumentNullException("sender"); } else if (namespaceManager == null) { throw new ArgumentNullException("namespaceManager"); } ServiceBusCausalityHelper.EncodePayload(functionInstanceId, message); bool threwMessgingEntityNotFoundException = false; cancellationToken.ThrowIfCancellationRequested(); try { await sender.SendAsync(message); return; } catch (MessagingEntityNotFoundException) { if (accessRights != AccessRights.Manage) { // if we don't have the required rights to create the queue, // rethrow the exception throw; } threwMessgingEntityNotFoundException = true; } Debug.Assert(threwMessgingEntityNotFoundException); cancellationToken.ThrowIfCancellationRequested(); try { await namespaceManager.CreateQueueAsync(sender.Path); } catch (MessagingEntityAlreadyExistsException) { } // Clone the message because it was already consumed before (when trying to send) // otherwise, you get an exception message = message.Clone(); cancellationToken.ThrowIfCancellationRequested(); await sender.SendAsync(message); }
public static async Task SendAndCreateEntityIfNotExists(this ServiceBusSender sender, ServiceBusMessage message, Guid functionInstanceId, CancellationToken cancellationToken) { if (sender == null) { throw new ArgumentNullException(nameof(sender)); } ServiceBusCausalityHelper.EncodePayload(functionInstanceId, message); cancellationToken.ThrowIfCancellationRequested(); await sender.SendMessageAsync(message, cancellationToken).ConfigureAwait(false); }
public static async Task SendAndCreateEntityIfNotExists(this MessageSender sender, Message message, Guid functionInstanceId, EntityType entityType, CancellationToken cancellationToken) { if (sender == null) { throw new ArgumentNullException("sender"); } ServiceBusCausalityHelper.EncodePayload(functionInstanceId, message); cancellationToken.ThrowIfCancellationRequested(); await sender.SendAsync(message); return; }
public TriggeredFunctionData GetTriggerFunctionData() { if (Messages.Length > 0) { ServiceBusReceivedMessage message = Messages[0]; if (IsSingleDispatch) { Guid?parentId = ServiceBusCausalityHelper.GetOwner(message); return(new TriggeredFunctionData() { ParentId = parentId, TriggerValue = this, TriggerDetails = new Dictionary <string, string>() { { "MessageId", message.MessageId }, { "SequenceNumber", message.SequenceNumber.ToString(CultureInfo.InvariantCulture) }, { "DeliveryCount", message.DeliveryCount.ToString(CultureInfo.InvariantCulture) }, { "EnqueuedTimeUtc", message.EnqueuedTime.ToUniversalTime().ToString("o") }, { "LockedUntilUtc", message.LockedUntil.ToUniversalTime().ToString("o") }, { "SessionId", message.SessionId } } }); } else { Guid?parentId = ServiceBusCausalityHelper.GetOwner(message); int length = Messages.Length; string[] messageIds = new string[length]; int[] deliveryCounts = new int[length]; long[] sequenceNumbers = new long[length]; string[] enqueuedTimes = new string[length]; string[] lockedUntils = new string[length]; string sessionId = Messages[0].SessionId; for (int i = 0; i < Messages.Length; i++) { messageIds[i] = Messages[i].MessageId; sequenceNumbers[i] = Messages[i].SequenceNumber; deliveryCounts[i] = Messages[i].DeliveryCount; enqueuedTimes[i] = Messages[i].EnqueuedTime.ToUniversalTime().ToString("o"); lockedUntils[i] = Messages[i].LockedUntil.ToUniversalTime().ToString("o"); } return(new TriggeredFunctionData() { ParentId = parentId, TriggerValue = this, TriggerDetails = new Dictionary <string, string>() { { "MessageIdArray", string.Join(",", messageIds) }, { "SequenceNumberArray", string.Join(",", sequenceNumbers) }, { "DeliveryCountArray", string.Join(",", deliveryCounts) }, { "EnqueuedTimeUtcArray", string.Join(",", enqueuedTimes) }, { "LockedUntilArray", string.Join(",", lockedUntils) }, { "SessionId", sessionId } } }); } } return(null); }