예제 #1
0
            const int MaxReceiveBatchSize = 1000; // actual batches are typically much smaller

            public PartitionInstance(uint partitionId, int incarnation, ScriptedEventProcessorHost eventProcessorHost)
            {
                this.partitionId = partitionId;
                this.Incarnation = incarnation;
                this.host        = eventProcessorHost;
            }
예제 #2
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;
            }
            }
        }