Exemplo n.º 1
0
        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);
        }
Exemplo n.º 3
0
        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;
        }