コード例 #1
0
        public static async Task<EventHubMonitor> CreateAsync(
            Configuration configuration,
            TimeSpan pauseBetweenParitions,
            TimeSpan pauseAfterAllPartitions
            )
        {
            var nsm = CreateNamespaceManager(configuration, pauseBetweenParitions);

            // We create a partially applied function so that 
            // we'll only need to pass the partition id later.
            Func<string, Task<PartitionDescription>> getEventHubPartitionAsync =
                partitionId => nsm.GetEventHubPartitionAsync(configuration.EventHubName, configuration.ConsumerGroupName, partitionId);

            var eventhub = await nsm.GetEventHubAsync(configuration.EventHubName).ConfigureAwait(false);

            // Construct a reference to the blob container.
            var storageAccount = CloudStorageAccount.Parse(configuration.CheckpointStorageAccount);
            var blobClient = storageAccount.CreateCloudBlobClient();
            var checkpointContainer = blobClient.GetContainerReference(configuration.EventHubName);

            // The `PartitionCheckpointManager` manages the complexity 
            // of getting the latest checkpoint for each parition.
            var checkpoints = new PartitionCheckpointManager(
                configuration.ConsumerGroupName,
                eventhub.PartitionIds,
                checkpointContainer
                );

            return new EventHubMonitor(
                eventhub.PartitionIds,
                checkpoints.GetLastCheckpointAsync,
                getEventHubPartitionAsync,
                pauseBetweenParitions,
                pauseAfterAllPartitions);
        }
コード例 #2
0
        private static NamespaceManager CreateNamespaceManager(Configuration configuration, TimeSpan timeout)
        {
            var endpoint = ServiceBusEnvironment.CreateServiceUri("sb", configuration.EventHubNamespace, string.Empty);
            var connectionString = ServiceBusConnectionStringBuilder.CreateUsingSharedAccessKey(endpoint,
                configuration.EventHubSasKeyName,
                configuration.EventHubSasKey);

            var nsm = NamespaceManager.CreateFromConnectionString(connectionString);
            nsm.Settings.OperationTimeout = timeout;
            return nsm;
        }
コード例 #3
0
 public static Task<EventHubMonitor> CreateAsync(Configuration configuration)
 {
     return CreateAsync(configuration,
         TimeSpan.FromSeconds(2),
         TimeSpan.FromSeconds(30));
 }