コード例 #1
0
        static void Main()
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                          .AddUserSecrets <Program>();

            IConfigurationRoot configuration = builder.Build();
            var eventHubConfig = new EventHubConfig();

            configuration.GetSection("EventHubConfig").Bind(eventHubConfig);

            Console.WriteLine("Setting from appsettings.json: " + eventHubConfig.StorageContainerName);
            Console.WriteLine("Setting from secrets.json: " + eventHubConfig.ConnectionString);

            MainAsync(eventHubConfig).GetAwaiter().GetResult();
        }
コード例 #2
0
        private static async Task MainAsync(EventHubConfig eventHubConfig)
        {
            string storageConnectionString = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", eventHubConfig.StorageAccountName, eventHubConfig.StorageAccountKey);

            Console.WriteLine("Registering EventProcessor...");

            var eventProcessorHost = new EventProcessorHost(
                eventHubConfig.Name,
                PartitionReceiver.DefaultConsumerGroupName,
                eventHubConfig.ConnectionString,
                storageConnectionString,
                eventHubConfig.StorageContainerName);

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

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

            // Disposes of the Event Processor Host
            await eventProcessorHost.UnregisterEventProcessorAsync();
        }