Beispiel #1
0
 /// <summary>
 /// Create a new host to process events from an Event Hub.
 ///
 /// <para>Since Event Hubs are frequently used for scale-out, high-traffic scenarios, generally there will
 /// be only one host per process, and the processes will be run on separate machines. However, it is
 /// supported to run multiple hosts on one machine, or even within one process, if throughput is not
 /// a concern.</para>
 ///
 /// This overload of the constructor uses the default, built-in lease and checkpoint managers. The
 /// Azure Storage account specified by the storageConnectionString parameter is used by the built-in
 /// managers to record leases and checkpoints.
 /// </summary>
 /// <param name="eventHubPath">The name of the EventHub.</param>
 /// <param name="consumerGroupName">The name of the consumer group within the Event Hub.</param>
 /// <param name="eventHubConnectionString">Connection string for the Event Hub to receive from.</param>
 /// <param name="storageConnectionString">Connection string to Azure Storage account used for leases and checkpointing.</param>
 /// <param name="leaseContainerName">Azure Storage container name for use by built-in lease and checkpoint manager.</param>
 public EventProcessorHost(
     string eventHubPath,
     string consumerGroupName,
     string eventHubConnectionString,
     string storageConnectionString,
     string leaseContainerName)
     : this(EventProcessorHost.CreateHostName(null),
            eventHubPath,
            consumerGroupName,
            eventHubConnectionString,
            storageConnectionString,
            leaseContainerName)
 {
 }
Beispiel #2
0
        // The EventProcessorHost can't pass itself to the AzureStorageCheckpointLeaseManager constructor
        // because it is still being constructed. Do other initialization here also because it might throw and
        // hence we don't want it in the constructor.
        internal void Initialize(EventProcessorHost host)
        {
            this.host = host;

            // Assign partition manager options.
            this.leaseDuration      = host.PartitionManagerOptions.LeaseDuration;
            this.leaseRenewInterval = host.PartitionManagerOptions.RenewInterval;

            // Create storage default request options.
            this.defaultRequestOptions = new BlobRequestOptions()
            {
                // Gets or sets the server timeout interval for a single HTTP request.
                ServerTimeout = TimeSpan.FromSeconds(this.LeaseRenewInterval.TotalSeconds / 2),

                // Gets or sets the maximum execution time across all potential retries for the request.
                MaximumExecutionTime = TimeSpan.FromSeconds(this.LeaseRenewInterval.TotalSeconds)
            };

            // Storage suggests to use at least 10 seconds timeout at list-blobs calls.
            this.listBlobsRequestOptions = new BlobRequestOptions()
            {
                ServerTimeout        = this.defaultRequestOptions.ServerTimeout,
                MaximumExecutionTime = this.defaultRequestOptions.MaximumExecutionTime
            };
            this.listBlobsRequestOptions.ServerTimeout = this.listBlobsRequestOptions.ServerTimeout < MinListBlobsTimeout ?
                                                         MinListBlobsTimeout : this.listBlobsRequestOptions.ServerTimeout;

#if FullNetFx
            // Proxy enabled?
            if (this.host.EventProcessorOptions != null && this.host.EventProcessorOptions.WebProxy != null)
            {
                this.operationContext = new OperationContext
                {
                    Proxy = this.host.EventProcessorOptions.WebProxy
                };
            }
#endif

            // Create storage client and configure max execution time.
            // Max execution time will apply to any storage call unless otherwise specified by custom request options.
            var storageClient = this.cloudStorageAccount.CreateCloudBlobClient();
            storageClient.DefaultRequestOptions = new BlobRequestOptions
            {
                MaximumExecutionTime = AzureStorageCheckpointLeaseManager.storageMaximumExecutionTime
            };

            this.eventHubContainer      = storageClient.GetContainerReference(this.leaseContainerName);
            this.consumerGroupDirectory = this.eventHubContainer.GetDirectoryReference(this.storageBlobPrefix + this.host.ConsumerGroupName);
        }
Beispiel #3
0
 /// <summary>
 /// Create a new host to process events from an Event Hub with provided <see cref="TokenProvider"/>
 /// </summary>
 /// <param name="endpointAddress">Fully qualified domain name for Event Hubs. Most likely, {yournamespace}.servicebus.windows.net</param>
 /// <param name="eventHubPath">The name of the EventHub.</param>
 /// <param name="consumerGroupName">The name of the consumer group within the Event Hub.</param>
 /// <param name="tokenProvider">Token provider which will generate security tokens for authorization.</param>
 /// <param name="cloudStorageAccount">Azure Storage account used for leases and checkpointing.</param>
 /// <param name="leaseContainerName">Azure Storage container name for use by built-in lease and checkpoint manager.</param>
 public EventProcessorHost(
     Uri endpointAddress,
     string eventHubPath,
     string consumerGroupName,
     ITokenProvider tokenProvider,
     CloudStorageAccount cloudStorageAccount,
     string leaseContainerName)
     : this(EventProcessorHost.CreateHostName(null),
            endpointAddress,
            eventHubPath,
            consumerGroupName,
            tokenProvider,
            cloudStorageAccount,
            leaseContainerName)
 {
 }
Beispiel #4
0
 /// <summary>
 /// Create a new host to process events from an Event Hub with provided <see cref="TokenProvider"/>
 /// </summary>
 /// <param name="endpointAddress">Fully qualified domain name for Event Hubs. Most likely, {yournamespace}.servicebus.windows.net</param>
 /// <param name="eventHubPath">The name of the EventHub.</param>
 /// <param name="consumerGroupName">The name of the consumer group within the Event Hub.</param>
 /// <param name="tokenProvider">Token provider which will generate security tokens for authorization.</param>
 /// <param name="cloudStorageAccount">Azure Storage account used for leases and checkpointing.</param>
 /// <param name="leaseContainerName">Azure Storage container name for use by built-in lease and checkpoint manager.</param>
 /// <param name="storageBlobPrefix">Prefix used when naming blobs within the storage container.</param>
 /// <param name="operationTimeout">Operation timeout for Event Hubs operations.</param>
 /// <param name="transportType">Transport type on connection.</param>
 public EventProcessorHost(
     Uri endpointAddress,
     string eventHubPath,
     string consumerGroupName,
     ITokenProvider tokenProvider,
     CloudStorageAccount cloudStorageAccount,
     string leaseContainerName,
     string storageBlobPrefix    = null,
     TimeSpan?operationTimeout   = null,
     TransportType transportType = TransportType.Amqp)
     : this(EventProcessorHost.CreateHostName(null),
            endpointAddress,
            eventHubPath,
            consumerGroupName,
            tokenProvider,
            cloudStorageAccount,
            leaseContainerName,
            storageBlobPrefix,
            operationTimeout,
            transportType)
 {
 }
        private static async Task MainAsync(string[] args)
        {
            Console.WriteLine("Registering EventProcessor...");

            // Ownership of a partition to an EPH instance (or a consumer) is tracked through the Azure Storage account that is provided for tracking.
            // https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-event-processor-host
            var eventProcessorHost = new Microsoft.Azure.EventHubs.Processor.EventProcessorHost(
                EventHubName,
                PartitionReceiver.DefaultConsumerGroupName,
                EventHubNamespaceConnectionString,
                StorageConnectionString,
                StorageContainerName);

            // Registers the Event Processor Host and starts receiving messages
            await eventProcessorHost.RegisterEventProcessorAsync <SimpleEventProcessor>();

            Console.WriteLine("Receiving. Press enter key to stop worker.");
            Console.ReadLine();

            // Disposes of the Event Processor Host
            await eventProcessorHost.UnregisterEventProcessorAsync();
        }
Beispiel #6
0
        // The EventProcessorHost can't pass itself to the AzureStorageCheckpointLeaseManager constructor
        // because it is still being constructed. Do other initialization here also because it might throw and
        // hence we don't want it in the constructor.
        internal void Initialize(EventProcessorHost host)
        {
            this.host = host;

            // Assign partition manager options.
            this.leaseDuration      = host.PartitionManagerOptions.LeaseDuration;
            this.leaseRenewInterval = host.PartitionManagerOptions.RenewInterval;

            // Set storage renew request options.
            // Lease renew calls shouldn't wait more than leaseRenewInterval
            this.renewRequestOptions = new BlobRequestOptions()
            {
                ServerTimeout        = this.leaseRenewInterval,
                MaximumExecutionTime = TimeSpan.FromMinutes(1)
            };

#if NET461
            // Proxy enabled?
            if (this.host.EventProcessorOptions != null && this.host.EventProcessorOptions.WebProxy != null)
            {
                this.operationContext = new OperationContext
                {
                    Proxy = this.host.EventProcessorOptions.WebProxy
                };
            }
#endif

            // Create storage client and configure max execution time.
            // Max execution time will apply to any storage calls except renew.
            var storageClient = this.cloudStorageAccount.CreateCloudBlobClient();
            storageClient.DefaultRequestOptions = new BlobRequestOptions
            {
                MaximumExecutionTime = AzureStorageCheckpointLeaseManager.storageMaximumExecutionTime
            };

            this.eventHubContainer      = storageClient.GetContainerReference(this.leaseContainerName);
            this.consumerGroupDirectory = this.eventHubContainer.GetDirectoryReference(this.storageBlobPrefix + this.host.ConsumerGroupName);
        }
 public EventHubPartitionPump(EventProcessorHost host, Lease lease)
     : base(host, lease)
 {
 }
Beispiel #8
0
 internal PartitionManager(EventProcessorHost host)
 {
     this.host = host;
     this.cancellationTokenSource = new CancellationTokenSource();
     this.partitionPumps          = new ConcurrentDictionary <string, PartitionPump>();
 }