Ejemplo n.º 1
0
        public async Task <string> OpenAsync(CancellationToken cancellationToken)
        {
            var listener = new EventHubsListener(_configuration);

            var parser = new EventHubListenerMessageJsonParser();

            var builder = new MessageRouterBuilder();

            var clusteringSerializer = new CsvOutputFormatter("id", "type", "version", "enqueueTimeUtc",
                                                              "gameSessionId", "lat", "lon", "geoHash", "geoHashPrecision", "geoHashCenterLat", "geoHashCenterLon",
                                                              "rnd");

            var clusteringDlsOutputManager = new DataLakeStoreOutputManager(
                clusteringSerializer,
                new PipelineDateFilePathAlgorithm(newFileOption: NewFileNameOptions.Every5Minutes),
                _serviceClientCredentials,
                _subscription,
                _dataLakeName);

            var clusteringConsoleOutputManager = new ConsoleOutputManager(clusteringSerializer);

            builder.Pipeline("clustering")
            .HandlesMessageType("geo-location", "1.0.0")
            .HandlesMessageType("geo-location", "1.0.1")
            .AddHandler(new RandomIntMessageHandler())
            .OutputTo(clusteringConsoleOutputManager, clusteringDlsOutputManager);


            // Build all pipelines
            var router = builder.Build();

            // Attach the differeing parts of the message processor together
            _messageProcessor = new MessageProcessor <EventHubListenerMessage>(listener, parser, router);

            // The following method will never exit
            //await messageProcessor.ProcessAndBlockAsync();

            return(_configuration.EventHubPath);
        }
Ejemplo n.º 2
0
        private static void Main(string[] args)
        {
            Greet();

            SetupConfigurationProviders();

            // Check that all configurations are set before continuing
            var configStatus = CheckConfigurationStatus(
                NAH_EHListener_ConnectionString,
                NAH_EHListener_EventHubPath,
                NAH_EHListener_ConsumerGroup,
                NAH_EHListener_StorageConnectionString,
                NAH_EHListener_LeaseContainerName,
                NAH_AAD_Domain,
                NAH_AAD_ClientId,
                NAH_AAD_ClientSecret,
                NAH_Azure_SubscriptionId,
                NAH_Azure_DLSOutputManager_AccountName);

            if (configStatus != ConfigurationStatus.Ok)
            {
                // Exiting due to missing configuration
                Console.WriteLine("Press any key to continue");
                Console.ReadKey(true);
                return;
            }


            // Setup Listener. This will be the same for all pipelines we are building.
            var listenerConfig = new EventHubsListenerConfiguration
            {
                EventHubConnectionString = s_configuration[NAH_EHListener_ConnectionString],
                EventHubPath             = s_configuration[NAH_EHListener_EventHubPath],
                ConsumerGroupName        = s_configuration[NAH_EHListener_ConsumerGroup],
                StorageConnectionString  = s_configuration[NAH_EHListener_StorageConnectionString],
                LeaseContainerName       = s_configuration[NAH_EHListener_LeaseContainerName]
            };
            var listener = new EventHubsListener(listenerConfig);

            // Setup Message Parser. By default we are using Nether JSON Messages
            // Setting up parser that knows how to parse those messages.
            var parser = new EventHubListenerMessageJsonParser();

            // User a builder to create routing infrastructure for messages and the pipelines
            var builder = new MessageRouterBuilder();

            // Setting up "Geo Clustering Recipe"

            var clusteringSerializer = new CsvOutputFormatter("id", "type", "version", "enqueueTimeUtc", "gameSessionId", "lat", "lon", "geoHash", "geoHashPrecision", "geoHashCenterLat", "geoHashCenterLon");

            var clusteringDlsOutputManager = new DataLakeStoreOutputManager(
                clusteringSerializer,
                new PipelineDateFilePathAlgorithm(newFileOption: NewFileNameOptions.Every5Minutes),

                domain: s_configuration[NAH_AAD_Domain],
                clientId: s_configuration[NAH_AAD_ClientId],
                clientSecret: s_configuration[NAH_AAD_ClientSecret],
                subscriptionId: s_configuration[NAH_Azure_SubscriptionId],
                adlsAccountName: s_configuration[NAH_Azure_DLSOutputManager_AccountName]);

            var clusteringConsoleOutputManager = new ConsoleOutputManager(clusteringSerializer);

            builder.Pipeline("clustering")
            .HandlesMessageType("geo-location", "1.0.0")
            .HandlesMessageType("geo-location", "1.0.1")
            .AddHandler(new GeoHashMessageHandler {
                CalculateGeoHashCenterCoordinates = true
            })
            .OutputTo(clusteringConsoleOutputManager, clusteringDlsOutputManager);


            // Build all pipelines
            var router = builder.Build();

            // Attach the differeing parts of the message processor together
            var messageProcessor = new MessageProcessor <EventHubListenerMessage>(listener, parser, router);

            // Run in an async context since main method is not allowed to be marked as async
            Task.Run(async() =>
            {
                await messageProcessor.ProcessAndBlockAsync();
            }).GetAwaiter().GetResult();
        }