Ejemplo n.º 1
0
        private static async Task MainAsync(string[] args)
        {
            var configurationRoot       = new ConfigurationBuilder().AddUserSecrets <Program>().Build();
            var config                  = new TheConfig(configurationRoot);
            var connectionStringBuilder = new EventHubsConnectionStringBuilder(config.EventHubConnectionString)
            {
                EntityPath = config.EventHubName
            };

            EventHubClient eventHubClient = EventHubClient.CreateFromConnectionString(connectionStringBuilder.ToString());

            int numMessagesToSend = 100;

            for (var i = 0; i < numMessagesToSend; i++)
            {
                try
                {
                    var message = i.ToString();
                    Console.WriteLine($"Sending number: {message}");
                    await eventHubClient.SendAsync(new EventData(Encoding.UTF8.GetBytes(message)));
                }
                catch (Exception exception)
                {
                    Console.WriteLine($"{DateTime.Now} > Exception: {exception.Message}");
                }
            }

            Console.WriteLine($"{numMessagesToSend} messages sent.");

            await eventHubClient.CloseAsync();
        }
Ejemplo n.º 2
0
        public override Task StartAsync(CancellationToken cancellationToken)
        {
            _logger.LogInformation("Registering EventProcessor...");

            IConfiguration configuration = new ConfigurationBuilder().AddUserSecrets <Worker>().Build();
            var            config        = new TheConfig(configuration);

            _eventProcessorHost = new EventProcessorHost(
                config.EventHubName,
                PartitionReceiver.DefaultConsumerGroupName,
                config.EventHubConnectionString,
                config.StorageConnectionString,
                config.StorageContainerName);

            // Registers the Event Processor Host and starts receiving messages
            _eventProcessorHost.RegisterEventProcessorAsync <FizzBuzzPopEventProcessor>();
            return(base.StartAsync(cancellationToken));
        }
Ejemplo n.º 3
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     TheConfig.Save();
 }