Esempio n. 1
0
        protected override AzureClientHolder <TopicClient, BrokeredMessage> ClientCreate(SenderPartitionConfig partition)
        {
            var client = base.ClientCreate(partition);

            client.Type = "Topic Sender";

            client.Name = mPriorityClientNamer(AzureConn.ConnectionName, partition.Priority);

            client.AssignMessageHelpers();

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

            client.ClientCreate = () => TopicClient.CreateFromConnectionString(AzureConn.ConnectionString, client.Name);

            client.MessageTransmit = async(b) => await client.Client.SendAsync(b);

            return(client);
        }
        /// <summary>
        /// This method creates the specific client.
        /// </summary>
        /// <returns>Returns the client.</returns>
        protected override AzureClientHolder <SubscriptionClient, BrokeredMessage> ClientCreate(ListenerPartitionConfig partition)
        {
            var client = base.ClientCreate(partition);

            client.Filters = GetFilters().Select((f) => f.SqlExpression).ToList();

            client.Type = "Subscription Listener";

            client.Name = mPriorityClientNamer(AzureConn.ConnectionName, partition.Priority);

            client.AssignMessageHelpers();

            client.FabricInitialize = () =>
            {
                AzureConn.TopicFabricInitialize(client.Name);
                var subDesc = AzureConn.SubscriptionFabricInitialize(client.Name, mSubscriptionId
                                                                     , autoDeleteSubscription: DeleteOnIdleTime
                                                                     , lockDuration: partition.FabricMaxMessageLock);
            };

            client.SupportsQueueLength = true;

            client.QueueLength = () =>
            {
                try
                {
                    var desc = AzureConn.NamespaceManager.GetSubscription(client.Name, mSubscriptionId);

                    client.QueueLengthLastPoll = DateTime.UtcNow;

                    return(desc.MessageCountDetails.ActiveMessageCount);
                }
                catch (Exception)
                {
                    return(null);
                }
            };

            client.CanStart = GetFilters().Count > 0;

            client.ClientCreate = () =>
            {
                var messagingFactory = MessagingFactory.CreateFromConnectionString(AzureConn.ConnectionString);
                var subClient        = messagingFactory.CreateSubscriptionClient(client.Name, mSubscriptionId);

                subClient.PrefetchCount = 50;

                subClient.RemoveRule("$default");
                SetFilters(subClient, client.Name, mSubscriptionId);

                return(subClient);
            };

            client.ClientRefresh = () =>
            {
                SetFilters(client.Client, client.Name, mSubscriptionId);
            };

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

                return(messages);
            };

            return(client);
        }