示例#1
0
        Task ITaskHub.StartAsync()
        {
            this.shutdownTokenSource = new CancellationTokenSource();

            this.host.NumberPartitions = this.numberPartitions;
            var creationTimestamp = DateTime.UtcNow;
            var startPositions    = new long[this.numberPartitions];

            // create a client
            var clientId     = Guid.NewGuid();
            var clientSender = new SendWorker(this.shutdownTokenSource.Token);

            this.client = this.host.AddClient(clientId, default, clientSender);
 public MemoryClientQueue(TransportAbstraction.IClient client, CancellationToken cancellationToken, ILogger logger)
     : base(cancellationToken, $"Client.{Client.GetShortId(client.ClientId)}", logger)
 {
     this.client = client;
 }
示例#3
0
        async Task ITaskHub.StartAsync()
        {
            this.shutdownSource = new CancellationTokenSource();

            // load the taskhub parameters
            var jsonText = await this.taskhubParameters.DownloadTextAsync().ConfigureAwait(false);

            this.parameters  = JsonConvert.DeserializeObject <TaskhubParameters>(jsonText);
            this.taskhubGuid = this.parameters.TaskhubGuid.ToByteArray();

            // check that we are the correct taskhub!
            if (this.parameters.TaskhubName != this.settings.HubName)
            {
                throw new InvalidOperationException($"The specified taskhub name does not match the task hub name in {this.taskhubParameters.Name}");
            }

            this.host.NumberPartitions = (uint)this.parameters.StartPositions.Length;

            this.connections = new EventHubsConnections(this.settings.ResolvedTransportConnectionString, this.parameters.PartitionHubs, this.parameters.ClientHubs)
            {
                Host        = host,
                TraceHelper = this.traceHelper,
            };

            await this.connections.StartAsync(this.parameters.StartPositions.Length);

            this.client = this.host.AddClient(this.ClientId, this.parameters.TaskhubGuid, this);

            this.clientEventLoopTask = Task.Run(this.ClientEventLoop);

            if (PartitionHubs.Length > 1)
            {
                throw new NotSupportedException("Using multiple eventhubs for partitions is not yet supported.");
            }

            if (this.client == null)
            {
                throw new InvalidOperationException("client must be started before partition hosting is started.");
            }

            string partitionsHub = PartitionHubs[0];

            switch (this.settings.PartitionManagement)
            {
            case PartitionManagementOptions.EventProcessorHost:
            {
                this.traceHelper.LogInformation("Registering EventProcessorHost with EventHubs");

                this.eventProcessorHost = new EventProcessorHost(
                    partitionsHub,
                    EventHubsTransport.PartitionConsumerGroup,
                    this.settings.ResolvedTransportConnectionString,
                    this.settings.ResolvedStorageConnectionString,
                    this.cloudBlobContainer.Name);

                var processorOptions = new EventProcessorOptions()
                {
                    InitialOffsetProvider = (s) => EventPosition.FromSequenceNumber(this.parameters.StartPositions[int.Parse(s)] - 1),
                    MaxBatchSize          = 300,
                    PrefetchCount         = 500,
                };

                await this.eventProcessorHost.RegisterEventProcessorFactoryAsync(this, processorOptions).ConfigureAwait(false);

                break;
            }

            case PartitionManagementOptions.Scripted:
            {
                this.traceHelper.LogInformation($"Starting scripted partition host");
                this.scriptedEventProcessorHost = new ScriptedEventProcessorHost(
                    partitionsHub,
                    EventHubsTransport.PartitionConsumerGroup,
                    this.settings.ResolvedTransportConnectionString,
                    this.settings.ResolvedStorageConnectionString,
                    this.cloudBlobContainer.Name,
                    this.host,
                    this,
                    this.connections,
                    this.parameters,
                    this.settings,
                    this.traceHelper,
                    this.settings.WorkerId);

                var thread = new Thread(() => this.scriptedEventProcessorHost.StartEventProcessing(this.settings, this.partitionScript));
                thread.Name = "ScriptedEventProcessorHost";
                thread.Start();
                break;
            }

            case PartitionManagementOptions.ClientOnly:
            {
                break;
            }
            }
        }