/// <summary>
        /// This override sets the receive options for the client.
        /// </summary>
        /// <returns>Returns the client.</returns>
        protected override AzureClientHolder <QueueClient, BrokeredMessage> ClientCreate(ListenerPartitionConfig partition)
        {
            var client = base.ClientCreate(partition);

            client.Type = "Queue Listener";
            client.Name = mPriorityClientNamer(AzureConn.ConnectionName, partition.Priority);

            client.AssignMessageHelpers();

            client.FabricInitialize = () =>
            {
                var queuedesc = AzureConn.QueueFabricInitialize(client.Name, lockDuration: partition.FabricMaxMessageLock);
            };

            client.SupportsQueueLength = true;

            client.QueueLength = () =>
            {
                try
                {
                    var desc = AzureConn.NamespaceManager.GetQueue(client.Name);

                    client.QueueLengthLastPoll = DateTime.UtcNow;

                    if (IsDeadLetterListener)
                    {
                        return(desc.MessageCountDetails.DeadLetterMessageCount);
                    }
                    else
                    {
                        return(desc.MessageCountDetails.ActiveMessageCount);
                    }
                }
                catch (Exception)
                {
                    return(null);
                }
            };

            client.ClientCreate = () =>
            {
                var messagingFactory = MessagingFactory.CreateFromConnectionString(AzureConn.ConnectionString);

                string queueName = IsDeadLetterListener ? QueueClient.FormatDeadLetterPath(client.Name) : client.Name;

                var queue = messagingFactory.CreateQueueClient(queueName);

                return(queue);
            };

            client.MessageReceive = async(c, t) =>
            {
                return(await client.Client.ReceiveBatchAsync(c ?? 10, TimeSpan.FromMilliseconds(t ?? 500)));
            };

            return(client);
        }
Пример #2
0
        /// <summary>
        /// This override sets the transmit options for the client.
        /// </summary>
        /// <returns>Returns the client.</returns>
        protected override AzureClientHolder <QueueClient, BrokeredMessage> ClientCreate(SenderPartitionConfig partition)
        {
            var client = base.ClientCreate(partition);

            client.Type = "Queue Sender";
            client.Name = mPriorityClientNamer(AzureConn.ConnectionName, partition.Priority);

            client.AssignMessageHelpers();

            client.FabricInitialize = () => AzureConn.QueueFabricInitialize(client.Name);

            //Set the method that creates the client.
            client.ClientCreate = () => QueueClient.CreateFromConnectionString(AzureConn.ConnectionString, client.Name);

            //We have to do this due to the stupid inheritance rules for Azure Service Bus.
            client.MessageTransmit = async(b) => await client.Client.SendAsync(b);

            return(client);
        }