示例#1
0
        internal TaskOrchestrationDispatcher(MessagingFactory messagingFactory,
                                             TrackingDispatcher trackingDispatcher,
                                             TaskHubDescription taskHubDescription,
                                             TaskHubWorkerSettings workerSettings,
                                             string orchestratorEntityName,
                                             string workerEntityName,
                                             string trackingEntityName,
                                             NameVersionObjectManager <TaskOrchestration> objectManager)
            : base("TaskOrchestration Dispatcher", item => item.Session == null ? string.Empty : item.Session.SessionId)
        {
            this.taskHubDescription = taskHubDescription;
            settings = workerSettings.Clone();
            this.orchestratorEntityName         = orchestratorEntityName;
            this.workerEntityName               = workerEntityName;
            this.trackingEntityName             = trackingEntityName;
            this.messagingFactory               = messagingFactory;
            this.messagingFactory.PrefetchCount = PrefetchCount;
            this.objectManager      = objectManager;
            orchestratorQueueClient = this.messagingFactory.CreateQueueClient(this.orchestratorEntityName);
            workerSender            = this.messagingFactory.CreateMessageSender(this.workerEntityName, this.orchestratorEntityName);

            trackingDipatcher = trackingDispatcher;
            if (trackingDipatcher != null)
            {
                isTrackingEnabled = true;
                trackingSender    = this.messagingFactory.CreateMessageSender(this.trackingEntityName,
                                                                              this.orchestratorEntityName);
            }
            maxConcurrentWorkItems = settings.TaskOrchestrationDispatcherSettings.MaxConcurrentOrchestrations;
        }
示例#2
0
        /// <summary>
        ///     Creates all the underlying entities in Service bus and Azure Storage (if specified) for
        ///     the TaskHubWorker and TaskHubClient's operations. If TaskHub already exists then this is a no-op
        /// </summary>
        public void CreateHubIfNotExists(TaskHubDescription description)
        {
            NamespaceManager namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);

            IEnumerable <QueueDescription> queueDescriptions =
                namespaceManager.GetQueues("startswith(path, '" + hubName + "') eq TRUE");

            List <QueueDescription> descriptions = queueDescriptions.ToList();

            if (!descriptions.Any(q => string.Equals(q.Path, orchestratorEntityName)))
            {
                SafeCreateQueue(namespaceManager, orchestratorEntityName, true,
                                description.MaxTaskOrchestrationDeliveryCount);
            }

            if (!descriptions.Any(q => string.Equals(q.Path, workerEntityName)))
            {
                SafeCreateQueue(namespaceManager, workerEntityName, false, description.MaxTaskActivityDeliveryCount);
            }

            if (!descriptions.Any(q => string.Equals(q.Path, trackingEntityName)))
            {
                SafeCreateQueue(namespaceManager, trackingEntityName, true, description.MaxTrackingDeliveryCount);
            }

            if (!string.IsNullOrEmpty(tableStoreConnectionString))
            {
                var client = new TableClient(hubName, tableStoreConnectionString);
                client.CreateTableIfNotExists();
            }
        }
示例#3
0
 internal TrackingDispatcher(MessagingFactory messagingFactory,
                             TaskHubDescription taskHubDescription,
                             TaskHubWorkerSettings workerSettings,
                             string tableConnectionString,
                             string hubName,
                             string trackingEntityName)
     : base("Tracking Dispatcher", item => item == null ? string.Empty : item.Session.SessionId)
 {
     this.taskHubDescription = taskHubDescription;
     settings = workerSettings.TrackingDispatcherSettings.Clone();
     this.trackingEntityName             = trackingEntityName;
     this.messagingFactory               = messagingFactory;
     this.messagingFactory.PrefetchCount = PrefetchCount;
     tableClient            = new TableClient(hubName, tableConnectionString);
     maxConcurrentWorkItems = settings.MaxConcurrentTrackingSessions;
 }
 internal TaskActivityDispatcher(MessagingFactory messagingFactory,
                                 TaskHubDescription taskHubDescription,
                                 TaskHubWorkerSettings workerSettings,
                                 string orchestratorQueueName,
                                 string workerQueueName,
                                 NameVersionObjectManager <TaskActivity> objectManager)
     : base("TaskActivityDispatcher", item => item.MessageId)
 {
     this.taskHubDescription = taskHubDescription;
     settings = workerSettings.Clone();
     this.orchestratorQueueName = orchestratorQueueName;
     this.workerQueueName       = workerQueueName;
     this.messagingFactory      = messagingFactory;
     this.objectManager         = objectManager;
     maxConcurrentWorkItems     = settings.TaskActivityDispatcherSettings.MaxConcurrentActivities;
 }
        public void TestMaxDeliveryCountIfNew()
        {
            var desc = new TaskHubDescription
            {
                MaxTaskActivityDeliveryCount = 100,
                MaxTaskOrchestrationDeliveryCount = 100,
                MaxTrackingDeliveryCount = 100,
            };

            taskHub.CreateHubIfNotExists(desc);
            TaskHubDescription retDesc = taskHub.GetTaskHubDescriptionAsync().Result;

            Assert.AreEqual(desc.MaxTaskActivityDeliveryCount, retDesc.MaxTaskActivityDeliveryCount);
            Assert.AreEqual(desc.MaxTaskOrchestrationDeliveryCount, retDesc.MaxTaskOrchestrationDeliveryCount);
            Assert.AreEqual(desc.MaxTrackingDeliveryCount, retDesc.MaxTrackingDeliveryCount);

            taskHub.DeleteHub();
        }
示例#6
0
        /// <summary>
        ///     Creates all the underlying entities in Service bus and Azure Storage (if specified) for
        ///     the TaskHubWorker and TaskHubClient's operations. If TaskHub already existed then
        ///     it would be deleted and recreated. Instance store creation can be controlled via parameter.
        /// </summary>
        public void CreateHub(TaskHubDescription description, bool createInstanceStore)
        {
            NamespaceManager namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);

            SafeDeleteQueue(namespaceManager, orchestratorEntityName);
            SafeDeleteQueue(namespaceManager, workerEntityName);
            SafeDeleteQueue(namespaceManager, trackingEntityName);

            CreateQueue(namespaceManager, orchestratorEntityName, true, description.MaxTaskOrchestrationDeliveryCount);
            CreateQueue(namespaceManager, workerEntityName, false, description.MaxTaskActivityDeliveryCount);
            CreateQueue(namespaceManager, trackingEntityName, true, description.MaxTrackingDeliveryCount);

            if (!string.IsNullOrEmpty(tableStoreConnectionString) && createInstanceStore)
            {
                var client = new TableClient(hubName, tableStoreConnectionString);
                client.DeleteTableIfExists();
                client.CreateTableIfNotExists();
            }
        }
示例#7
0
        /// <summary>
        ///     Starts the TaskHubWorker so it begins processing orchestrations and activities
        /// </summary>
        /// <returns></returns>
        public TaskHubWorker Start()
        {
            lock (thisLock)
            {
                if (isStarted)
                {
                    throw new InvalidOperationException("TaskHub is already started");
                }

                TaskHubDescription taskHubDescription = GetTaskHubDescription();

                orchestrationDispatcher =
                    new TaskOrchestrationDispatcher(Utils.CreateMessagingFactory(connectionString),
                                                    string.IsNullOrEmpty(tableStoreConnectionString)
                            ? null
                            : new TrackingDispatcher(
                                                        Utils.CreateMessagingFactory(connectionString),
                                                        taskHubDescription,
                                                        workerSettings,
                                                        tableStoreConnectionString, hubName,
                                                        trackingEntityName),
                                                    taskHubDescription,
                                                    workerSettings,
                                                    orchestratorEntityName, workerEntityName,
                                                    trackingEntityName, orchestrationManager);

                activityDispatcher =
                    new TaskActivityDispatcher(
                        Utils.CreateMessagingFactory(connectionString),
                        taskHubDescription,
                        workerSettings,
                        orchestratorEntityName,
                        workerEntityName,
                        activityManager);

                orchestrationDispatcher.Start();
                activityDispatcher.Start();

                isStarted = true;
            }
            return(this);
        }
示例#8
0
        /// <summary>
        ///     Gets the TaskHubDescription for the configured TaskHub
        /// </summary>
        /// <returns></returns>
        public async Task <TaskHubDescription> GetTaskHubDescriptionAsync()
        {
            NamespaceManager namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);

            var description = new TaskHubDescription();

            IEnumerable <QueueDescription> queueDescriptions =
                await namespaceManager.GetQueuesAsync("startswith(path, '" + hubName + "') eq TRUE");

            List <QueueDescription> descriptions = queueDescriptions.ToList();

            QueueDescription orchestratorQueueDescription =
                descriptions.Single(q => string.Equals(q.Path, orchestratorEntityName));
            QueueDescription activityQueueDescription = descriptions.Single(q => string.Equals(q.Path, workerEntityName));
            QueueDescription trackingQueueDescription =
                descriptions.Single(q => string.Equals(q.Path, trackingEntityName));

            description.MaxTaskOrchestrationDeliveryCount = orchestratorQueueDescription.MaxDeliveryCount;
            description.MaxTaskActivityDeliveryCount      = activityQueueDescription.MaxDeliveryCount;
            description.MaxTrackingDeliveryCount          = trackingQueueDescription.MaxDeliveryCount;

            return(description);
        }
示例#9
0
 /// <summary>
 ///     Creates all the underlying entities in Service bus and Azure Storage (if specified) for
 ///     the TaskHubWorker and TaskHubClient's operations. If TaskHub already exists then this is a no-op
 /// </summary>
 public void CreateHubIfNotExists()
 {
     CreateHubIfNotExists(TaskHubDescription.CreateDefaultDescription());
 }
示例#10
0
 /// <summary>
 ///     Creates all the underlying entities in Service bus and Azure Storage (if specified) for
 ///     the TaskHubWorker and TaskHubClient's operations. If TaskHub already existed then
 ///     it would be deleted and recreated.
 /// </summary>
 public void CreateHub(TaskHubDescription description)
 {
     CreateHub(description, true);
 }
示例#11
0
 /// <summary>
 ///     Creates all the underlying entities in Service bus and Azure Storage (if specified) for
 ///     the TaskHubWorker and TaskHubClient's operations. If TaskHub already existed then
 ///     it would be deleted and recreated. Instance store creation can be controlled via parameter.
 /// </summary>
 public void CreateHub(bool createInstanceStore)
 {
     CreateHub(TaskHubDescription.CreateDefaultDescription(), createInstanceStore);
 }
示例#12
0
        // Management operations

        /// <summary>
        ///     Creates all the underlying entities in Service bus and Azure Storage (if specified) for
        ///     the TaskHubWorker and TaskHubClient's operations. If TaskHub already existed then
        ///     it would be deleted and recreated.
        /// </summary>
        public void CreateHub()
        {
            CreateHub(TaskHubDescription.CreateDefaultDescription(), true);
        }