コード例 #1
0
        private void CreateEventProcessorHostClient(ref EventHubSettings eventHubSettings)
        {
            Trace.TraceInformation("Creating EventProcessorHost: {0}, {1}, {2}", this.Server.MachineName, eventHubSettings.name, eventHubSettings.consumerGroup);

            try
            {
                eventHubSettings.processorHost = new EventProcessorHost(this.Server.MachineName,
                                                                        eventHubSettings.name,
                                                                        eventHubSettings.consumerGroup.ToLowerInvariant(),
                                                                        eventHubSettings.connectionString,
                                                                        eventHubSettings.storageConnectionString);

                eventHubSettings.processorHostOptions = new EventProcessorOptions();
                eventHubSettings.processorHostOptions.ExceptionReceived    += WebSocketEventProcessor.ExceptionReceived;
                eventHubSettings.processorHostOptions.InitialOffsetProvider = (partitionId) => DateTime.UtcNow;
                //eventHubSettings.processorHostOptions.InitialOffsetProvider = partitionId =>
                //{
                //    return eventHubSettings.namespaceManager.GetEventHubPartition(eventHubSettings.client.Path, partitionId).LastEnqueuedOffset;
                //};

                Trace.TraceInformation("Registering EventProcessor for " + eventHubSettings.name);
                eventHubSettings.processorHost.RegisterEventProcessorAsync <WebSocketEventProcessor>(
                    eventHubSettings.processorHostOptions).Wait();
            }
            catch
            {
                Debug.Print("Error happened while trying to connect Event Hub");
            }
        }
コード例 #2
0
        private void CreateEventProcessorHostClient(ref EventHubSettings eventHubSettings)
        {
            Trace.TraceInformation("Creating EventProcessorHost: {0}, {1}, {2}", this.Server.MachineName, eventHubSettings.name, eventHubSettings.consumerGroup);
            eventHubSettings.client = EventHubClient.CreateFromConnectionString(eventHubSettings.connectionString,
                                                                                eventHubSettings.name);
            // Retrieve the storage account from the connection string.


            // Execute the insert operation.

            // Delete and recreate the consumer group
            // this allows to ensure we will start receiving only fresh messages when the site starts
            try
            {
                foreach (ConsumerGroupDescription consumerGroupDesc in eventHubSettings.namespaceManager.GetConsumerGroups(eventHubSettings.client.Path))
                {
                    // We remove any previously created consumergroups containing the word WebSite in the name
                    if (consumerGroupDesc.Name.Contains("WebSite") && !String.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME")) ||
                        consumerGroupDesc.Name.Contains("local") && String.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME")))
                    {
                        eventHubSettings.namespaceManager.DeleteConsumerGroup(eventHubSettings.name, consumerGroupDesc.Name);
                    }
                }
            }
            catch
            {
                // Error happened while trying to delete old ConsumerGroups.
                Debug.Print("Error happened while trying to delete old ConsumerGroups");
            }
            finally
            {
                // We create a new consumer group with a new mame each time to
                eventHubSettings.consumerGroup += DateTime.UtcNow.Ticks.ToString();
                eventHubSettings.namespaceManager.CreateConsumerGroupIfNotExists(eventHubSettings.name, eventHubSettings.consumerGroup);
            }

            eventHubSettings.processorHost = new EventProcessorHost(this.Server.MachineName,
                                                                    eventHubSettings.client.Path,
                                                                    eventHubSettings.consumerGroup.ToLowerInvariant(),
                                                                    eventHubSettings.connectionString,
                                                                    eventHubSettings.storageConnectionString);

            eventHubSettings.processorHostOptions = new EventProcessorOptions();
            eventHubSettings.processorHostOptions.ExceptionReceived    += WebSocketEventProcessor.ExceptionReceived;
            eventHubSettings.processorHostOptions.InitialOffsetProvider = (partitionId) => DateTime.UtcNow;
            //eventHubSettings.processorHostOptions.InitialOffsetProvider = partitionId =>
            //{
            //    return eventHubSettings.namespaceManager.GetEventHubPartition(eventHubSettings.client.Path, partitionId).LastEnqueuedOffset;
            //};

            Trace.TraceInformation("Registering EventProcessor for " + eventHubSettings.name);
            eventHubSettings.processorHost.RegisterEventProcessorAsync <WebSocketEventProcessor>(eventHubSettings.processorHostOptions).Wait();
        }
コード例 #3
0
        private void CreateEventProcessorHostClient(ref EventHubSettings eventHubSettings)
        {
            Trace.TraceInformation("Creating EventProcessorHost: {0}, {1}, {2}", this.Server.MachineName, eventHubSettings.name, eventHubSettings.consumerGroup);
            try
            {
                eventHubSettings.client = EventHubClient.CreateFromConnectionString(eventHubSettings.connectionString,
                                                                                    eventHubSettings.name);
            }
            catch (Exception ex)
            {
                // Error happened while trying to delete old ConsumerGroups.
                Debug.Print("Error happened while creating the eventhub client: " + ex.Message);
            }

            try
            {
                //eventHubSettings.processorHost = new EventProcessorHost(this.Server.MachineName,
                //    eventHubSettings.client.Path,
                //    eventHubSettings.consumerGroup.ToLowerInvariant(),
                //    eventHubSettings.connectionString,
                //    eventHubSettings.storageConnectionString);
                eventHubSettings.processorHost = new EventProcessorHost(this.Server.MachineName,
                                                                        eventHubSettings.name,
                                                                        eventHubSettings.consumerGroup,
                                                                        eventHubSettings.connectionString,
                                                                        eventHubSettings.storageConnectionString
                                                                        );

                //eventHubSettings.processorHostOptions = new EventProcessorOptions();
                //eventHubSettings.processorHostOptions.InitialOffsetProvider = (partitionId) => DateTime.UtcNow;
                //eventHubSettings.processorHostOptions.ExceptionReceived += WebSocketEventProcessor.ExceptionReceived;

                Trace.TraceInformation("Registering EventProcessor for " + eventHubSettings.name);
                //eventHubSettings.processorHost.RegisterEventProcessorAsync<WebSocketEventProcessor>(eventHubSettings.processorHostOptions).Wait();
                eventHubSettings.processorHost.RegisterEventProcessorAsync <WebSocketEventProcessor>().Wait();
            }
            catch (Exception e)
            {
                Debug.Print("Error happened while trying to connect Event Hub: " + e.ToString());
            }
        }
コード例 #4
0
        private void CreateEventProcessorHostClient(ref EventHubSettings eventHubSettings)
        {
            Trace.TraceInformation("Creating EventProcessorHost: {0}, {1}, {2}", this.Server.MachineName, eventHubSettings.name, eventHubSettings.consumerGroup);
            try
            {
                eventHubSettings.client = EventHubClient.CreateFromConnectionString(eventHubSettings.connectionString,
                                                                                eventHubSettings.name);

                // Delete and recreate the consumer group
                // this allows to ensure we will start receiving only fresh messages when the site starts

                foreach (ConsumerGroupDescription consumerGroupDesc in eventHubSettings.namespaceManager.GetConsumerGroups(eventHubSettings.client.Path))
                {
                    // We remove any previously created consumergroups containing the word WebSite in the name
                    if (consumerGroupDesc.Name.ToLowerInvariant().Contains("website") && !String.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME"))
                        || consumerGroupDesc.Name.ToLowerInvariant().Contains("local") && String.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME")))
                        eventHubSettings.namespaceManager.DeleteConsumerGroup(eventHubSettings.name, consumerGroupDesc.Name);
                }
            }
            catch
            {
                // Error happened while trying to delete old ConsumerGroups.
                Debug.Print("Error happened while trying to delete old ConsumerGroups");
            }
            finally
            {
                try
                {
                    // We create a new consumer group with a new mame each time to
                    eventHubSettings.consumerGroup += DateTime.UtcNow.Ticks.ToString();
                    eventHubSettings.namespaceManager.CreateConsumerGroupIfNotExists(eventHubSettings.name,
                        eventHubSettings.consumerGroup);
                }
                catch(Exception ex)
                {
                    Debug.Print("Error happened: " + ex.Message);
                }
            }

            try
            {
                eventHubSettings.processorHost = new EventProcessorHost(this.Server.MachineName,
                    eventHubSettings.client.Path,
                    eventHubSettings.consumerGroup.ToLowerInvariant(),
                    eventHubSettings.connectionString,
                    eventHubSettings.storageConnectionString);

                eventHubSettings.processorHostOptions = new EventProcessorOptions();
                eventHubSettings.processorHostOptions.ExceptionReceived += WebSocketEventProcessor.ExceptionReceived;
                eventHubSettings.processorHostOptions.InitialOffsetProvider = (partitionId) => DateTime.UtcNow;
                //eventHubSettings.processorHostOptions.InitialOffsetProvider = partitionId =>
                //{
                //    return eventHubSettings.namespaceManager.GetEventHubPartition(eventHubSettings.client.Path, partitionId).LastEnqueuedOffset;
                //};

                Trace.TraceInformation("Registering EventProcessor for " + eventHubSettings.name);
                eventHubSettings.processorHost.RegisterEventProcessorAsync<WebSocketEventProcessor>(
                    eventHubSettings.processorHostOptions).Wait();
            }
            catch
            {
                Debug.Print("Error happened while trying to connect Event Hub");
            }
        }
コード例 #5
0
        private void CreateEventProcessorHostClient(ref EventHubSettings eventHubSettings)
        {
            Trace.TraceInformation("Creating EventProcessorHost: {0}, {1}, {2}", this.Server.MachineName, eventHubSettings.name, eventHubSettings.consumerGroup);

            try
            {
                eventHubSettings.processorHost = new EventProcessorHost(this.Server.MachineName, 
                    eventHubSettings.name,
                    eventHubSettings.consumerGroup.ToLowerInvariant(),
                    eventHubSettings.connectionString,
                    eventHubSettings.storageConnectionString);

                eventHubSettings.processorHostOptions = new EventProcessorOptions();
                eventHubSettings.processorHostOptions.ExceptionReceived += WebSocketEventProcessor.ExceptionReceived;
                eventHubSettings.processorHostOptions.InitialOffsetProvider = (partitionId) => DateTime.UtcNow;
                //eventHubSettings.processorHostOptions.InitialOffsetProvider = partitionId =>
                //{
                //    return eventHubSettings.namespaceManager.GetEventHubPartition(eventHubSettings.client.Path, partitionId).LastEnqueuedOffset;
                //};

                Trace.TraceInformation("Registering EventProcessor for " + eventHubSettings.name);
                eventHubSettings.processorHost.RegisterEventProcessorAsync<WebSocketEventProcessor>(
                    eventHubSettings.processorHostOptions).Wait();
            }
            catch
            {
                Debug.Print("Error happened while trying to connect Event Hub");
            }

        }
コード例 #6
0
        private void CreateEventProcessorHostClient(ref EventHubSettings eventHubSettings)
        {
            Trace.TraceInformation("Creating EventProcessorHost: {0}, {1}, {2}", this.Server.MachineName, eventHubSettings.name, eventHubSettings.consumerGroup);
            try
            {
                eventHubSettings.client = EventHubClient.CreateFromConnectionString(eventHubSettings.connectionString,
                                                                                    eventHubSettings.name);

                // Delete and recreate the consumer group
                // this allows to ensure we will start receiving only fresh messages when the site starts

                foreach (ConsumerGroupDescription consumerGroupDesc in eventHubSettings.namespaceManager.GetConsumerGroups(eventHubSettings.client.Path))
                {
                    // We remove any previously created consumergroups containing the word WebSite in the name
                    if (consumerGroupDesc.Name.ToLowerInvariant().Contains("website") &&
                        !String.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME"))
                        ||
                        consumerGroupDesc.Name.ToLowerInvariant().Contains("local") &&
                        String.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME")))
                    {
                        eventHubSettings.namespaceManager.DeleteConsumerGroup(eventHubSettings.name, consumerGroupDesc.Name);
                    }
                }

                //Workaround to delete old blobs related to old consumer groups
                CloudBlobContainer eventHubBlobContainer = BlobHelper.SetUpContainer(eventHubSettings.storageConnectionString, eventHubSettings.name);

                string blobPerfix = String.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME")) ? "local" : "website";

                IEnumerable <CloudBlockBlob> oldBlobs = eventHubBlobContainer.ListBlobs(blobPerfix, true, BlobListingDetails.All).OfType <CloudBlockBlob>();
                foreach (var blob in oldBlobs)
                {
                    try
                    {
                        blob.DeleteIfExists();
                    }
                    catch (Exception)
                    {
                        Debug.Print("Error happened while trying to delete old ConsumerGroup related blob.");
                    }
                }
            }
            catch
            {
                // Error happened while trying to delete old ConsumerGroups.
                Debug.Print("Error happened while trying to delete old ConsumerGroups");
            }
            finally
            {
                try
                {
                    // We create a new consumer group with a new mame each time to
                    eventHubSettings.consumerGroup += DateTime.UtcNow.Ticks.ToString();
                    eventHubSettings.namespaceManager.CreateConsumerGroupIfNotExists(eventHubSettings.name,
                                                                                     eventHubSettings.consumerGroup);
                }
                catch (Exception ex)
                {
                    Debug.Print("Error happened: " + ex.Message);
                }
            }

            try
            {
                eventHubSettings.processorHost = new EventProcessorHost(this.Server.MachineName,
                                                                        eventHubSettings.client.Path,
                                                                        eventHubSettings.consumerGroup.ToLowerInvariant(),
                                                                        eventHubSettings.connectionString,
                                                                        eventHubSettings.storageConnectionString);

                eventHubSettings.processorHostOptions = new EventProcessorOptions();
                eventHubSettings.processorHostOptions.ExceptionReceived    += WebSocketEventProcessor.ExceptionReceived;
                eventHubSettings.processorHostOptions.InitialOffsetProvider = (partitionId) => DateTime.UtcNow;
                //eventHubSettings.processorHostOptions.InitialOffsetProvider = partitionId =>
                //{
                //    return eventHubSettings.namespaceManager.GetEventHubPartition(eventHubSettings.client.Path, partitionId).LastEnqueuedOffset;
                //};

                Trace.TraceInformation("Registering EventProcessor for " + eventHubSettings.name);
                eventHubSettings.processorHost.RegisterEventProcessorAsync <WebSocketEventProcessor>(
                    eventHubSettings.processorHostOptions).Wait();
            }
            catch
            {
                Debug.Print("Error happened while trying to connect Event Hub");
            }
        }