protected override async Task StartAsync()
        {
            InfoLogging("StartAsync called");

            try
            {
                if (_host == null)
                    _host = _clientFactory.CreateEventProcessorHost(EventHubPath, BaseHostName, ConsumerGroupName);

                await _host
                    .RegisterEventProcessorFactoryAsync(ProcessorFactory, CreateEventProcessorOptions())
                    .ConfigureAwait(false);

                while (!Token.IsCancellationRequested)
                {
                    await Task.Delay(TimeSpan.FromSeconds(5)).ConfigureAwait(false);
                }
            }
            catch (Exception exception)
            {
                ErrorLogging("An error happened with the EventProcessorHost", exception);
            }
            
            if (_host != null)
            {
                InfoLogging("Unregistering Event Processor");
                await _host.UnregisterEventProcessorAsync().ConfigureAwait(false);    
            }
            InfoLogging("StartAsync completes");
        }
Example #2
0
        public async void ReadUsingEventHubProcessor()
        {
            string serviceBusNamespace = "iotmc-ns";
            string eventHubName = "iotmc";
            string eventHubSASKeyName = "Device01";
            string eventHubSASKey = "<< Add your SAS here >>";

            string storageAccountName = "iotmc";
            string storageAccountKey = "<< add your Storage Account key here >>"; 

            string storageConnectionString = String.Format(@"DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", storageAccountName, storageAccountKey);
            string eventHubConnectionString = ServiceBusConnectionStringBuilder.CreateUsingSharedAccessKey(
                ServiceBusEnvironment.CreateServiceUri("sb", serviceBusNamespace, string.Empty),
                eventHubSASKeyName,
                eventHubSASKey);

            EventHubClient eventHubClient = EventHubClient.CreateFromConnectionString(eventHubConnectionString, eventHubName);
            EventHubConsumerGroup eventHubConsumerGroup = eventHubClient.GetDefaultConsumerGroup();

            EventProcessorHost eventProcessorHost = new EventProcessorHost("MSTechDemoWorker", eventHubClient.Path, eventHubConsumerGroup.GroupName, eventHubConnectionString, storageConnectionString);
            //await eventProcessorHost.RegisterEventProcessorAsync<EventHubEventProcessor>();

            //Ignore older messages even if they are still in the event hub store
            Task t = eventProcessorHost.RegisterEventProcessorAsync<EventHubEventProcessor>(new EventProcessorOptions()
            {
                InitialOffsetProvider = (partitionId) => { return DateTime.UtcNow.AddHours(-1); }
            });
            t.Wait();
        }
Example #3
0
 public EventReceiver(IEventProcessorFactory processorFactory, string eventHubName, string consumerGroupName, 
     string eventHubConnectionString, string checkpointConnectionString)
 {
     _processorFactory = processorFactory;
     _host = new EventProcessorHost(Environment.MachineName, eventHubName, consumerGroupName,
         eventHubConnectionString, checkpointConnectionString);
 }
        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 12;

            Trace.TraceInformation("Alarms has been started");

            var eventHubName = RoleEnvironment.GetConfigurationSettingValue("EventHubName");
            var serviceBusConnectionString = RoleEnvironment.GetConfigurationSettingValue("Azure.ServiceBus.ConnectionString");
            var storageConnectionString = RoleEnvironment.GetConfigurationSettingValue("Azure.Storage.ConnectionString");

            var builder = new ServiceBusConnectionStringBuilder(serviceBusConnectionString);
            builder.TransportType = TransportType.Amqp;

            var eventHubReceiveClient = EventHubClient.CreateFromConnectionString(builder.ToString(), eventHubName);

            var eventHubConsumerGroup = eventHubReceiveClient.GetDefaultConsumerGroup();

            var eventProcessorHost = new EventProcessorHost( "AlarmsWorker",
                                                             eventHubName,
                                                             eventHubConsumerGroup.GroupName,
                                                             builder.ToString(),
                                                             storageConnectionString);

            eventProcessorHost.RegisterEventProcessorAsync<MessageProcessor>();

            return base.OnStart();
        }
Example #5
0
        private async static void Run(TypeContainer tc)
        {
            string eventHubConfigFile = _settings.EventHubConfigFile;
            var eventHubConfig = ConfigUtility.ReadConfig<Dictionary<string, string>>(eventHubConfigFile);
            string eventHubName = eventHubConfig["EventHubName"];
            string eventHubConnectionString = eventHubConfig["EventHubConnectionString"];
            string azureStorageConnectionString = eventHubConfig["AzureStorageConnectionString"];
            string eventProcessorHostName = "IoTEventHubTSDBWriter";
            try
            {
               EventProcessorHost host = new EventProcessorHost(
                           eventProcessorHostName,
                           eventHubName,
                           EventHubConsumerGroup.DefaultGroupName,
                           eventHubConnectionString,
                           azureStorageConnectionString,
                           eventHubName.ToLowerInvariant());

                IEventProcessorFactory factory = new TsdbEventProcessorFactory();
                IInitializer factoryInitializer = factory as IInitializer;
                factoryInitializer.Initialize(_settings);
                var options = new EventProcessorOptions();
                options.ExceptionReceived += Options_ExceptionReceived; 
                await host.RegisterEventProcessorFactoryAsync(factory, options);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Example #6
0
        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 12;

            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.

            bool result = base.OnStart();

            Trace.TraceInformation("KAIT.PushNotificationService has been started");
        
            string storage = "DefaultEndpointsProtocol=https;AccountName=inceptionasamonitoring;AccountKey=Lwtx59G+gypbFHrk0+DT8ggdk045CQBp/qXrlUlclVqOhTyIIo7u72DnnEhWzu6bgPtnJ948Ad4M2/gSWx7osw==";

            string serviceBus = "Endpoint=sb://inceptioningess-ns.servicebus.windows.net/;SharedAccessKeyName=ListenPolicy;SharedAccessKey=jMkbgtpkPb9pwVTKLoIKhuKAgN6Q6BHHpf00kPQ2AxU=";

                                   
            string eventHubName = "interactionsnotifications";
                                   
            EventHubClient client = EventHubClient.CreateFromConnectionString(serviceBus, eventHubName);

            Trace.TraceInformation("Consumer group is: " + client.GetDefaultConsumerGroup().GroupName);

            _host = new EventProcessorHost("singleworker", eventHubName, client.GetDefaultConsumerGroup().GroupName, serviceBus, storage);

            Trace.TraceInformation("Created event processor host...");



            return result;
        }
        static void Main(string[] args)
        {
            string eventHubConnectionString = Environment.GetEnvironmentVariable("APIMEVENTS-EVENTHUB-CONNECTIONSTRING", EnvironmentVariableTarget.Process);
            string eventHubName = Environment.GetEnvironmentVariable("APIMEVENTS-EVENTHUB-NAME", EnvironmentVariableTarget.Process);
            string storageAccountName = Environment.GetEnvironmentVariable("APIMEVENTS-STORAGEACCOUNT-NAME", EnvironmentVariableTarget.Process);
            string storageAccountKey = Environment.GetEnvironmentVariable("APIMEVENTS-STORAGEACCOUNT-KEY", EnvironmentVariableTarget.Process);

            string storageConnectionString = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}",
                storageAccountName, storageAccountKey);

            string eventProcessorHostName = Guid.NewGuid().ToString();
            var eventProcessorHost = new EventProcessorHost(
                                                eventProcessorHostName,
                                                eventHubName,
                                                EventHubConsumerGroup.DefaultGroupName,
                                                eventHubConnectionString,
                                                storageConnectionString);

            var logger = new ConsoleLogger(LogLevel.Debug);
            logger.LogDebug("Registering EventProcessor...");

            var httpMessageProcessor = new RunscopeHttpMessageProcessor(new HttpClient(), logger);

            eventProcessorHost.RegisterEventProcessorFactoryAsync(
                new ApimHttpEventProcessorFactory(httpMessageProcessor, logger));

            Console.WriteLine("Receiving. Press enter key to stop worker.");
            Console.ReadLine();
            eventProcessorHost.UnregisterEventProcessorAsync().Wait();
        }
Example #8
0
        public override void Run()
        {
            Trace.TraceInformation("WorkerRole1 is running");
            NewRelic.Api.Agent.NewRelic.SetTransactionName("Worker", "Run"); var watch = Stopwatch.StartNew();
            //  Start listening for actuation events from actuatorHub.
            string eventHubConnectionString = "Endpoint=sb://azureiothub.servicebus.windows.net/;SharedAccessKeyName=ReceiveRule;SharedAccessKey=6lIJjmHJRKkrEPPIPS45Su2GP2oQ2TjwvAzf2hPYr/Q=";
            string eventHubName = "actuatorhub";
            string storageAccountName = "azureiotstorage";
            string storageAccountKey = "OE8ELPPu30uc1BVRW21WH3Sb6aoTkRNbP4vmYX0eLAukYNS9prF13laVUJHQkx0hVrIeDt88a5TAwQflEcTqNg==";
            string storageConnectionString = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}",
                storageAccountName, storageAccountKey);

            string eventProcessorHostName = Guid.NewGuid().ToString();
            eventProcessorHost = new EventProcessorHost(eventProcessorHostName, eventHubName, EventHubConsumerGroup.DefaultGroupName, eventHubConnectionString, storageConnectionString);
            Trace.WriteLine("Registering EventProcessor...");
            eventProcessorHost.RegisterEventProcessorAsync<EventProcessor>().Wait();

            NewRelic.Api.Agent.NewRelic.RecordResponseTimeMetric("Run", watch.ElapsedMilliseconds);

            try
            {
                this.RunAsync(this.cancellationTokenSource.Token).Wait();
            }
            finally
            {
                this.runCompleteEvent.Set();
            }

        }
Example #9
0
        //Event Hubsの使用
        //https://azure.microsoft.com/ja-jp/documentation/articles/event-hubs-csharp-ephcs-getstarted/
        static void Main(string[] args)
        {
            Properties.Settings settings = new Properties.Settings();

            //string eventHubConnectionString = "{Event Hub connection string}";
            //string eventHubName = "{Event Hub name}";
            string eventHubName = settings.EventHubName;
            string eventHubConnectionString = settings.EventHubConnectionString;

            //string storageAccountName = "{storage account name}";
            //string storageAccountKey = "{storage account key}";
            string storageAccountName = settings.StorageAccountName;
            string storageAccountKey = settings.StorageAccountKey;

            string storageConnectionString = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", storageAccountName, storageAccountKey);

            string eventProcessorHostName = Guid.NewGuid().ToString();
            EventProcessorHost eventProcessorHost = new EventProcessorHost(eventProcessorHostName, eventHubName, EventHubConsumerGroup.DefaultGroupName, eventHubConnectionString, storageConnectionString);
            Console.WriteLine("Registering EventProcessor...");
            var options = new EventProcessorOptions();
            options.ExceptionReceived += (sender, e) => { Console.WriteLine(e.Exception); };
            eventProcessorHost.RegisterEventProcessorAsync<SimpleEventProcessor>(options).Wait();

            Console.WriteLine("Receiving. Press enter key to stop worker.");
            Console.ReadLine();
            eventProcessorHost.UnregisterEventProcessorAsync().Wait();
        }
        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 12;

            // For information on handling configuration changes
            // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.

            bool result = base.OnStart();

            Trace.TraceInformation("EventsForwarding OnStart()...\n");

            connectionString = ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString"];
            eventHubName = ConfigurationManager.AppSettings["Microsoft.ServiceBus.EventHubName"];

            string storageAccountName = ConfigurationManager.AppSettings["AzureStorage.AccountName"];
            string storageAccountKey = ConfigurationManager.AppSettings["AzureStorage.Key"];
            string storageAccountString = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}",
                storageAccountName, storageAccountKey);

            string iotHubConnectionString = ConfigurationManager.AppSettings["AzureIoTHub.ConnectionString"];
            iotHubServiceClient = ServiceClient.CreateFromConnectionString(iotHubConnectionString);
            eventHubClient = EventHubClient.CreateFromConnectionString(connectionString, eventHubName);

            var defaultConsumerGroup = eventHubClient.GetDefaultConsumerGroup();

            string eventProcessorHostName = "SensorEventProcessor";
            EventProcessorHost eventProcessorHost = new EventProcessorHost(eventProcessorHostName, eventHubName, defaultConsumerGroup.GroupName, connectionString, storageAccountString);
            eventProcessorHost.RegisterEventProcessorAsync<SensorEventProcessor>().Wait();

            Trace.TraceInformation("Receiving events...\n");

            return result;
        }
        public static async Task<ColdStorageCoordinator> CreateAsync(string hostName, Configuration configuration)
        {
            ColdStorageEventSource.Log.InitializingEventHubListener(configuration.EventHubName, configuration.ConsumerGroupName);

            var storageAccount = CloudStorageAccount.Parse(configuration.BlobWriterStorageAccount);

            Func<string, IBlobWriter> blobWriterFactory =
                    partitionId =>
                        new RollingBlobWriter.RollingBlobWriter(new PartitionAndDateNamingStrategy(partitionId, configuration.BlobPrefix),
                            storageAccount,
                            configuration.ContainerName,
                            configuration.RollSizeForBlobWriterMb);

            var ns = NamespaceManager.CreateFromConnectionString(configuration.EventHubConnectionString);
            try
            {
                await ns.GetConsumerGroupAsync(configuration.EventHubName, configuration.ConsumerGroupName);
            }
            catch (Exception e)
            {
                ColdStorageEventSource.Log.InvalidEventHubConsumerGroupName(e, configuration.EventHubName, configuration.ConsumerGroupName);
                throw;
            }

            ColdStorageEventSource.Log.ConsumerGroupFound(configuration.EventHubName, configuration.ConsumerGroupName);

            var eventHubId = ConfigurationHelper.GetEventHubName(ns.Address, configuration.EventHubName);

            var factory = new ColdStorageEventProcessorFactory(
                blobWriterFactory,
                configuration.CircuitBreakerWarningLevel,
                configuration.CircuitBreakerTripLevel,
                configuration.CircuitBreakerStallInterval,
                configuration.CircuitBreakerLogCooldownInterval,
                eventHubId
            );

            var options = new EventProcessorOptions()
            {
                MaxBatchSize = configuration.MaxBatchSize,
                PrefetchCount = configuration.PreFetchCount,
                ReceiveTimeOut = configuration.ReceiveTimeout,
                InvokeProcessorAfterReceiveTimeout = true
            };

            options.ExceptionReceived += 
                (s, e) => ColdStorageEventSource.Log.ErrorProcessingMessage(e.Exception, e.Action);
          
            var host = new EventProcessorHost(
                hostName,
                consumerGroupName: configuration.ConsumerGroupName,
                eventHubPath: configuration.EventHubName,
                eventHubConnectionString: configuration.EventHubConnectionString,
                storageConnectionString: configuration.CheckpointStorageAccount);


            await host.RegisterEventProcessorFactoryAsync(factory, options);

            return new ColdStorageCoordinator(host);
        }
 public async Task TearDownAsync()
 {
     if (_host != null)
     {
         await _host.UnregisterEventProcessorAsync();
         _host = null;
     }
 }
Example #13
0
        public void Start()
        {
            string eventProcessorHostName = Guid.NewGuid().ToString();
            eventProcessorHost = new EventProcessorHost(eventProcessorHostName, Config.EVENT_HUB_NAME,
                EventHubConsumerGroup.DefaultGroupName, Config.EVENT_HUB_CONNECTION_STRING, Config.GetStorageConnectionString());
            SimpleEventProcessor.Clients = this.Clients;
            SimpleEventProcessor.Host = eventProcessorHost;

            eventProcessorHost.RegisterEventProcessorAsync<SimpleEventProcessor>();
        }
        public void MessageProcessingWithPartitionDistribution()
        {
            EventHubClient eventHubClient = EventHubClient.CreateFromConnectionString(eventHubConnectionString, this.eventHubName);

            // Get the default Consumer Group
            defaultConsumerGroup = eventHubClient.GetDefaultConsumerGroup();
            string blobConnectionString = ConfigurationManager.AppSettings["AzureStorageConnectionString"]; // Required for checkpoint/state
            eventProcessorHost = new EventProcessorHost("singleworker", eventHubClient.Path, defaultConsumerGroup.GroupName, this.eventHubConnectionString, blobConnectionString);
            eventProcessorHost.RegisterEventProcessorAsync<SimpleEventProcessor>().Wait();
        }
Example #15
0
 public void RegisterEventProcessor(string blobConnectionString, string hostName)
 {
     EventHubClient eventHubClient = EventHubClient.CreateFromConnectionString(eventHubConnectionString,
         this.eventHubName);
     Trace.TraceInformation("register string :" + eventHubConnectionString+ blobConnectionString);
     //Use custom consumer group
     eventProcessorHost = new EventProcessorHost(hostName, eventHubClient.Path,
         EventHubConsumerGroup.DefaultGroupName, this.eventHubConnectionString, blobConnectionString);
     Trace.TraceInformation("Registering event processor");
     eventProcessorHost.RegisterEventProcessorAsync<EventProcessor>().Wait();
 }
 public async void ProcessEvents()
 {
     eventHubName = "azureguidanceevnthub";
     connectionString = GetServiceBusConnectionString();
     NamespaceManager namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
     eventHubClient = EventHubClient.CreateFromConnectionString(connectionString, eventHubName);
     defaultConsumerGroup = eventHubClient.GetDefaultConsumerGroup();
     string blobConnectionString = ConfigurationManager.AppSettings["AzureStorageConnectionString"]; // Required for checkpoint/state
     eventProcessorHost = new EventProcessorHost("AzureGuidanceReceiver", eventHubClient.Path, defaultConsumerGroup.GroupName, connectionString, blobConnectionString);
     await eventProcessorHost.RegisterEventProcessorAsync<SimpleEventProcessor>();
                 
 }
Example #17
0
 public override bool OnStart()
 {
     WorkerHelper.InitContext();
     _host = WorkerHelper.GetEventProcessorHostByKey(ConstLib.KEY_SYS);
     // 设置最大并发连接数
     ServicePointManager.DefaultConnectionLimit = 12;
     // 有关处理配置更改的信息,
     // 请参见 http://go.microsoft.com/fwlink/?LinkId=166357 上的 MSDN 主题。
     bool result = base.OnStart();
     //Trace.TraceInformation("HubWorker has been started");
     return result;
 }
        public static async Task<WarmStorageCoordinator> CreateAsync(string hostName, Configuration configuration)
        {
            WarmStorageEventSource.Log.InitializingEventHubListener(configuration.EventHubName, configuration.ConsumerGroupName);

            Func<string, IElasticSearchWriter> elasticSearchWriterFactory = partitionId => 
                new ElasticSearchWriter.ElasticSearchWriter(
                    configuration.ElasticSearchUrl,
                    configuration.ElasticSearchIndexPrefix,
                    configuration.ElasticSearchIndexType,
                    configuration.RetryCount
                );

            var ns = NamespaceManager.CreateFromConnectionString(configuration.EventHubConnectionString);
            try
            {
                await ns.GetConsumerGroupAsync(configuration.EventHubName, configuration.ConsumerGroupName);
            }
            catch (Exception e)
            {
                WarmStorageEventSource.Log.InvalidEventHubConsumerGroupName(e, configuration.EventHubName, configuration.ConsumerGroupName);
                throw;
            }

            WarmStorageEventSource.Log.ConsumerGroupFound(configuration.EventHubName, configuration.ConsumerGroupName);

            var eventHubId = ConfigurationHelper.GetEventHubName(ns.Address, configuration.EventHubName);

            var buildingLookupService = new BuildingLookupService();
            await buildingLookupService.InitializeAsync();

            var factory = new WarmStorageEventProcessorFactory(elasticSearchWriterFactory, eventHubId, buildingLookupService);

            var options = new EventProcessorOptions()
            {
                MaxBatchSize = configuration.MaxBatchSize,
                PrefetchCount = configuration.PreFetchCount,
                ReceiveTimeOut = configuration.ReceiveTimeout
            };

            options.ExceptionReceived += 
                (s, e) => WarmStorageEventSource.Log.ErrorProcessingMessage(e.Exception, e.Action);

            var host = new EventProcessorHost(
                hostName,
                consumerGroupName: configuration.ConsumerGroupName,
                eventHubPath: configuration.EventHubName,
                eventHubConnectionString: configuration.EventHubConnectionString,
                storageConnectionString: configuration.CheckpointStorageAccount);

            await host.RegisterEventProcessorFactoryAsync(factory, options);

            return new WarmStorageCoordinator(host);
        }
Example #19
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            string eventHubConnectionString = ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString"];
            string eventHubName = ConfigurationManager.AppSettings["EventHubName"];
            string storageConnectionString = ConfigurationManager.AppSettings["Microsoft.WindowsAzure.Storage.ConnectionString"];

            string eventProcessorHostName = Guid.NewGuid().ToString();
            eventProcessorHost = new EventProcessorHost(eventProcessorHostName, eventHubName, EventHubConsumerGroup.DefaultGroupName, eventHubConnectionString, storageConnectionString);
            eventProcessorHost.RegisterEventProcessorAsync<FEZSpiderEventHubProcessor>();
        }
        /// <summary>
        /// Add a connection for listening on events from an event hub.
        /// </summary>
        /// <param name="eventHubName">Name of the event hub</param>
        /// <param name="listener">initialized listener object</param>
        /// <remarks>The EventProcessorHost type is from the ServiceBus SDK.
        /// Allow callers to bind to EventHubConfiguration without needing to have a direct assembly reference to the ServiceBus SDK.
        /// The compiler needs to resolve all types in all overloads, so give methods that use the ServiceBus SDK types unique non-overloaded names
        /// to avoid eager compiler resolution.
        /// </remarks>
        public void AddEventProcessorHost(string eventHubName, EventProcessorHost listener)
        {
            if (eventHubName == null)
            {
                throw new ArgumentNullException("eventHubName");
            }
            if (listener == null)
            {
                throw new ArgumentNullException("listener");
            }

            _listeners[eventHubName] = listener;
        }
Example #21
0
        /// <summary>
        /// This is the main entry point for your service instance.
        /// </summary>
        /// <param name="cancelServiceInstance">Canceled when Service Fabric terminates this instance.</param>
        protected override async Task RunAsync(CancellationToken cancelServiceInstance)
        {
            string eventHubName             = "hub-1";
            string eventHubConnectionString = "[Event Hub connection string 1]";
            string storageConnectionString  = "[Storage account connection string]";

            eventHubClient = EventHubClient.CreateFromConnectionString(eventHubConnectionString, eventHubName);

            string             eventProcessorHostName = Guid.NewGuid().ToString();
            EventProcessorHost eventProcessorHost     = new EventProcessorHost(eventProcessorHostName, eventHubName, EventHubConsumerGroup.DefaultGroupName, eventHubConnectionString, storageConnectionString);

            await eventProcessorHost.RegisterEventProcessorAsync <NumberConverter>();
        }
        /// <summary>
        /// Add a connection for listening on events from an event hub. 
        /// </summary>
        /// <param name="eventHubName">Name of the event hub</param>
        /// <param name="listener">initialized listener object</param>
        /// <remarks>The EventProcessorHost type is from the ServiceBus SDK. 
        /// Allow callers to bind to EventHubConfiguration without needing to have a direct assembly reference to the ServiceBus SDK. 
        /// The compiler needs to resolve all types in all overloads, so give methods that use the ServiceBus SDK types unique non-overloaded names
        /// to avoid eager compiler resolution. 
        /// </remarks>
        public void AddEventProcessorHost(string eventHubName, EventProcessorHost listener)
        {
            if (eventHubName == null)
            {
                throw new ArgumentNullException("eventHubName");
            }
            if (listener == null)
            {
                throw new ArgumentNullException("listener");
            }

            _listeners[eventHubName] = listener;
        }
Example #23
0
        static void Main(string[] args)
        {
            string eventHubConnectionString = ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString"];
            string eventHubName = ConfigurationManager.AppSettings["EventHubName"];
            string storageConnectionString = ConfigurationManager.AppSettings["Microsoft.WindowsAzure.Storage.ConnectionString"];

            string eventProcessorHostName = Guid.NewGuid().ToString();
            EventProcessorHost eventProcessorHost = new EventProcessorHost(eventProcessorHostName, eventHubName, EventHubConsumerGroup.DefaultGroupName, eventHubConnectionString, storageConnectionString);
            eventProcessorHost.RegisterEventProcessorAsync<Pi2EventHubProcessor>().Wait();

            Console.WriteLine("Receiving. Press enter key to stop worker.");
            Console.ReadLine();
        }
Example #24
0
        public MessageProcessorService(ITelemetryInsightsLogger logger, IEventProcessorFactory factory, EventProcessorHost host)
        {
            _logger  = logger;
            _factory = factory;
            _host    = host;

            _options = new EventProcessorOptions
            {
                MaxBatchSize   = 200,
                PrefetchCount  = 500,
                ReceiveTimeout = TimeSpan.FromMinutes(2),
            };
        }
        public static async Task <EventProcessorHost> AttachProcessorForHub(
            string processorName,
            string serviceBusConnectionString,
            string offsetStorageConnectionString,
            string eventHubName,
            string consumerGroupName,
            IEventProcessorFactory processorFactory)
        {
            var eventProcessorHost = new EventProcessorHost(eventHubName, consumerGroupName, serviceBusConnectionString, offsetStorageConnectionString, processorName);
            await eventProcessorHost.RegisterEventProcessorFactoryAsync(processorFactory);

            return(eventProcessorHost);
        }
Example #26
0
        public async Task <bool> RegisterEventMessageConsumerAsync <TEventProcessor>(string name)
            where TEventProcessor : EventProcessorDefault
        {
            ConsumerConfigurationsOptions consumerConfiguration = GetConsumerConfiguration(name);

            if (EventProcessorHostList != null && EventProcessorHostList.Any(s => s.EventHubPath == consumerConfiguration.EventHubName))
            {
                return(false);
            }

            eventProcessorHost = new EventProcessorHost(
                consumerConfiguration.EventHubName,
                !string.IsNullOrWhiteSpace(consumerConfiguration.ConsumerGroupName) ? consumerConfiguration.ConsumerGroupName : PartitionReceiver.DefaultConsumerGroupName,
                consumerConfiguration.ConnectionString,
                consumerConfiguration.StorageConnectionString,
                consumerConfiguration.StorageContainerName)
            {
                PartitionManagerOptions = new PartitionManagerOptions
                {
                    RenewInterval = TimeSpan.FromSeconds(consumerConfiguration.RenewIntervalInSeconds),
                    LeaseDuration = TimeSpan.FromSeconds(consumerConfiguration.LeaseDurationInSeconds)
                }
            };

            var eventProcessorOptions = new EventProcessorOptions()
            {
                MaxBatchSize   = consumerConfiguration.NumberOfEventsPerRequest,
                ReceiveTimeout = TimeSpan.FromSeconds(consumerConfiguration.ReceiveTimeoutInSeconds)
            };

            DateTime offsetStartDateTime;

            if (!string.IsNullOrEmpty(consumerConfiguration.OffsetStartDateTime) && DateTime.TryParse(consumerConfiguration.OffsetStartDateTime, out offsetStartDateTime))
            {
                eventProcessorOptions.InitialOffsetProvider = (partitionId) => EventPosition.FromEnqueuedTime(offsetStartDateTime);
            }
            else
            {
                eventProcessorOptions.InitialOffsetProvider = (partitionId) => EventPosition.FromStart();
            }


            EventProcessorFactory <TEventProcessor> eventProcessorFactory = new EventProcessorFactory <TEventProcessor>(consumerConfiguration, ServiceProvider, Configuration);

            await eventProcessorHost.RegisterEventProcessorFactoryAsync(eventProcessorFactory, eventProcessorOptions);

            EventProcessorHostList.Add(eventProcessorHost);
            EventProcessorFactoryList.Add(name, eventProcessorFactory);

            return(true);
        }
Example #27
0
        private async Task ConnectToIotHubAsync(CancellationToken ct)
        {
            EventProcessorHost eventProcessorHost;

            // Get configuration settings
            string iotHubTelemetryConsumerGroup = ConfigurationProvider.GetConfigurationSettingValue("IotHubTelemetryConsumerGroup");
            string iotHubEventHubName           = ConfigurationProvider.GetConfigurationSettingValue("IotHubEventHubName");
            string iotHubEventHubEndpointIotHubOwnerConnectionString = ConfigurationProvider.GetConfigurationSettingValue("IotHubEventHubEndpointIotHubOwnerConnectionString");
            string solutionStorageAccountConnectionString            = ConfigurationProvider.GetConfigurationSettingValue("SolutionStorageAccountConnectionString");

            // Initialize EventProcessorHost.
            Trace.TraceInformation("Creating EventProcessorHost for IoTHub: {0}, ConsumerGroup: {1}, ConnectionString: {2}, StorageConnectionString: {3}",
                                   iotHubEventHubName, iotHubTelemetryConsumerGroup, iotHubEventHubEndpointIotHubOwnerConnectionString, solutionStorageAccountConnectionString);
            string StorageContainerName = "telemetrycheckpoints";

            eventProcessorHost = new EventProcessorHost(
                iotHubEventHubName,
                iotHubTelemetryConsumerGroup,
                iotHubEventHubEndpointIotHubOwnerConnectionString,
                solutionStorageAccountConnectionString,
                StorageContainerName);

            // Registers the Event Processor Host and starts receiving messages.
            EventProcessorOptions options = new EventProcessorOptions();

            options.InitialOffsetProvider = ((partitionId) => DateTime.UtcNow);
            options.SetExceptionHandler(EventProcessorHostExceptionHandler);
            try
            {
                await eventProcessorHost.RegisterEventProcessorAsync <MessageProcessor>(options);

                Trace.TraceInformation($"EventProcessor successfully registered");
            }
            catch (Exception e)
            {
                Trace.TraceInformation($"Exception during register EventProcessorHost '{e.Message}'");
            }

            // Wait till shutdown.
            while (true)
            {
                if (ct.IsCancellationRequested)
                {
                    Trace.TraceInformation($"Application is shutting down. Unregistering EventProcessorHost...");
                    await eventProcessorHost.UnregisterEventProcessorAsync();

                    return;
                }
                await Task.Delay(1000);
            }
        }
Example #28
0
        private async Task StartInternalAsync(OnlineTrainerSettingsInternal settings, OnlineTrainerState state = null, byte[] model = null)
        {
            this.LastStartDateTimeUtc = DateTime.UtcNow;
            this.perfCounters         = new PerformanceCounters(settings.Metadata.ApplicationID);

            // setup trainer
            this.trainer = new Learner(settings, this.DelayedExampleCallback, this.perfCounters);

            if (settings.ForceFreshStart || model != null)
            {
                this.trainer.FreshStart(state, model);
            }
            else
            {
                await this.trainer.FindAndResumeFromState();
            }

            // setup factory
            this.trainProcessorFactory = new TrainEventProcessorFactory(settings, this.trainer, this.perfCounters);

            // setup host
            var serviceBusConnectionStringBuilder = new ServiceBusConnectionStringBuilder(settings.JoinedEventHubConnectionString);
            var joinedEventhubName = serviceBusConnectionStringBuilder.EntityPath;

            serviceBusConnectionStringBuilder.EntityPath = string.Empty;

            this.eventProcessorHost = new EventProcessorHost(settings.Metadata.ApplicationID, joinedEventhubName,
                                                             EventHubConsumerGroup.DefaultGroupName, serviceBusConnectionStringBuilder.ToString(), settings.StorageConnectionString);

            // used by this.InitialOffsetProvider if no checkpointed state is found
            this.eventHubStartDateTimeUtc = settings.EventHubStartDateTimeUtc;

            await this.eventProcessorHost.RegisterEventProcessorFactoryAsync(
                this.trainProcessorFactory,
                new EventProcessorOptions { InitialOffsetProvider = this.InitialOffsetProvider });

            // don't perform too often
            this.perfUpdater = new SafeTimer(
                TimeSpan.FromMilliseconds(500),
                this.UpdatePerformanceCounters);

            this.telemetry.TrackTrace(
                "OnlineTrainer started",
                SeverityLevel.Information,
                new Dictionary <string, string>
            {
                { "CheckpointPolicy", settings.CheckpointPolicy.ToString() },
                { "VowpalWabbit", settings.Metadata.TrainArguments },
                { "ExampleTracing", settings.EnableExampleTracing.ToString() }
            });
        }
        public void Bus_PublishAsync_EventHub_Nominal()
        {
            var id = Guid.NewGuid();

            bool testOk = false;

            var message = new TestMessage()
            {
                SomeData = id.ToString()
            };

            var  serializer = new JSONSerializer();
            var  publisher  = new AzureEventHubPublishTransport(serializer);
            IBus bus        = new Bus(serializer, new AzureStorageQueueSendTransport(serializer), publisher);

            bus.Context = new AFBusMessageContext();

            bus.PublishAsync(message, TOPICNAME).Wait();

            var eventProcessorHost = new EventProcessorHost(TOPICNAME, PartitionReceiver.DefaultConsumerGroupName, SettingsUtil.GetSettings <string>(SETTINGS.AZURE_EVENTHUB), SettingsUtil.GetSettings <string>(SETTINGS.AZURE_STORAGE), "eventhubcontainer");

            // Registers the Event Processor Host and starts receiving messages
            var readingTask = eventProcessorHost.RegisterEventProcessorFactoryAsync(new AzureStreamProcessorFactory(stringMessage =>

            {
                var finalMessageEnvelope = JsonConvert.DeserializeObject <AFBusMessageEnvelope>(stringMessage, new JsonSerializerSettings()
                {
                    TypeNameHandling = TypeNameHandling.Objects,
                    TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple
                });

                var finalMessage = JsonConvert.DeserializeObject <TestMessage>(finalMessageEnvelope.Body, new JsonSerializerSettings()
                {
                    TypeNameHandling = TypeNameHandling.Objects,
                    TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple
                });

                testOk = testOk || (id.ToString() == finalMessage.SomeData);
            }));



            Task.Delay(5000).Wait();


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

            Assert.IsTrue(testOk);
        }
 public Task InitializeEventProcessor(string connectionString, string eventHubName, string storageConnectionString, string path, string cGroup = null, string vin = null, string activityId = null)
 {
     Filter.BlockingCollection = new BlockingCollection<string>(int.MaxValue);
     Filter.EventDataCollection = new BlockingCollection<EventData>(int.MaxValue);
     Filter.Path = path;
     Filter.Vin = vin;
     Filter.ActivityId = activityId;
     this.eventHubClient = EventHubClient.CreateFromConnectionString(connectionString, eventHubName);
     this.consumerGroup = string.IsNullOrWhiteSpace(cGroup)
          ? eventHubClient.GetDefaultConsumerGroup()
          : eventHubClient.GetConsumerGroup(cGroup);
     this.eventProcessorHost = new EventProcessorHost("EventHubReader", eventHubClient.Path, this.consumerGroup.GroupName, connectionString, storageConnectionString);
     return this.eventProcessorHost.RegisterEventProcessorAsync<EventProcessor>();
 }
        public static async Task<WarmStorageCoordinator> CreateAsync(string hostName, Configuration configuration)
        {
            WarmStorageEventSource.Log.InitializingEventHubListener(configuration.EventHubName, configuration.ConsumerGroupName);

            Func<string, IElasticSearchWriter> elasticSearchWriterFactory = partitionId => 
                new ElasticSearchWriter.ElasticSearchWriter(
                    configuration.ElasticSearchUrl,
                    configuration.ElasticSearchIndexPrefix,
                    configuration.ElasticSearchIndexType,
                    configuration.RetryCount
                );

            var ns = NamespaceManager.CreateFromConnectionString(configuration.EventHubConnectionString);
            try
            {
                await ns.GetConsumerGroupAsync(configuration.EventHubName, configuration.ConsumerGroupName);
            }
            catch (Exception e)
            {
                WarmStorageEventSource.Log.InvalidEventHubConsumerGroupName(e, configuration.EventHubName, configuration.ConsumerGroupName);
                throw;
            }

            WarmStorageEventSource.Log.ConsumerGroupFound(configuration.EventHubName, configuration.ConsumerGroupName);

            var eventHubId = ConfigurationHelper.GetEventHubName(ns.Address, configuration.EventHubName);

            var factory = new WarmStorageEventProcessorFactory(elasticSearchWriterFactory, eventHubId);

            var options = new EventProcessorOptions()
            {
                MaxBatchSize = configuration.MaxBatchSize,
                PrefetchCount = configuration.PreFetchCount,
                ReceiveTimeOut = configuration.ReceiveTimeout
            };

            options.ExceptionReceived += 
                (s, e) => WarmStorageEventSource.Log.ErrorProcessingMessage(e.Exception, e.Action);

            var host = new EventProcessorHost(
                hostName,
                consumerGroupName: configuration.ConsumerGroupName,
                eventHubPath: configuration.EventHubName,
                eventHubConnectionString: configuration.EventHubConnectionString,
                storageConnectionString: configuration.CheckpointStorageAccount);

            await host.RegisterEventProcessorFactoryAsync(factory, options);

            return new WarmStorageCoordinator(host);
        }
        public void MessageProcessingWithPartitionDistribution()
        {
            EventHubClient eventHubClient = EventHubClient.CreateFromConnectionString(eventHubConnectionString, this.eventHubName);

            // Get the default Consumer Group
            defaultConsumerGroup = eventHubClient.GetConsumerGroup(this.consumerGroup);
            string blobConnectionString =
                ConfigurationManager.AppSettings["AzureStorageConnectionString"]; // Required for checkpoint/state

            eventProcessorHost =
                new EventProcessorHost("singleworker", eventHubClient.Path, defaultConsumerGroup.GroupName, this.eventHubConnectionString, blobConnectionString);

            eventProcessorHost.RegisterEventProcessorAsync <MetricsEventProcessor>().Wait();
        }
        static void Main(string[] args)
        {
            var ehConnectionString = CloudConfigurationManager.GetSetting("ehConnectionString");
            var ehName = CloudConfigurationManager.GetSetting("ehName");
            var storageConnectionString = CloudConfigurationManager.GetSetting("azureTableConnection");

            //var storageProcHost = new EventProcessorHost(Guid.NewGuid().ToString(), ehName, "storage", ehConnectionString, storageConnectionString);
            //storageProcHost.RegisterEventProcessorAsync<StorageProcessor>().Wait();

            var entityProcHost = new EventProcessorHost(Guid.NewGuid().ToString(), ehName, "servicefabric", ehConnectionString, storageConnectionString);
            entityProcHost.RegisterEventProcessorAsync<EntityProcessor>().Wait();

            Console.ReadLine();
        }
 public Task InitializeEventProcessor(string connectionString, string eventHubName, string storageConnectionString, string path, string cGroup = null, string vin = null, string activityId = null)
 {
     Filter.BlockingCollection  = new BlockingCollection <string>(int.MaxValue);
     Filter.EventDataCollection = new BlockingCollection <EventData>(int.MaxValue);
     Filter.Path         = path;
     Filter.Vin          = vin;
     Filter.ActivityId   = activityId;
     this.eventHubClient = EventHubClient.CreateFromConnectionString(connectionString, eventHubName);
     this.consumerGroup  = string.IsNullOrWhiteSpace(cGroup)
          ? eventHubClient.GetDefaultConsumerGroup()
          : eventHubClient.GetConsumerGroup(cGroup);
     this.eventProcessorHost = new EventProcessorHost("EventHubReader", eventHubClient.Path, this.consumerGroup.GroupName, connectionString, storageConnectionString);
     return(this.eventProcessorHost.RegisterEventProcessorAsync <EventProcessor>());
 }
Example #35
0
        public static async Task <EventProcessorHost> AttachProcessorForHub(
            string processorName,
            string eventHubConnection,
            string storageConnection,
            string eventHubName,
            string consumerGroup,
            IEventProcessorFactory factory)
        {
            var eventProcessorHost = new EventProcessorHost(processorName, eventHubName, consumerGroup,
                                                            eventHubConnection, storageConnection);
            await eventProcessorHost.RegisterEventProcessorFactoryAsync(factory);

            return(eventProcessorHost);
        }
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            eventProcessorHost = new EventProcessorHost(
                "plantgrow",
                "realtimeweb",
                "Azure-IoT-hub-endpoint-url"
                , "Azure-Storage_account-Access_keys-connection_string-url", "data1");

            // Registers the Event Processor Host and starts receiving messages
            await eventProcessorHost.RegisterEventProcessorFactoryAsync(new AzureStreamProcessorFactory(_subService), new EventProcessorOptions
            {
                InitialOffsetProvider = (pid) => EventPosition.FromEnqueuedTime(DateTime.UtcNow)
            });
        }
        private static EventProcessorHost RegisterEventProcessor <T>(string serviceBus, string eventHubName,
                                                                     string consumerKeyName, string consumerHash,
                                                                     string storageConnectionString) where T : IEventProcessor
        {
            string serviceBusConnectionString = Constants.GetBusConnectionString(serviceBus, consumerKeyName, consumerHash);
            var    eventClient        = EventHubClient.CreateFromConnectionString(serviceBusConnectionString, eventHubName);
            var    eventProcessorHost = new EventProcessorHost(Environment.MachineName, eventHubName,
                                                               eventClient.GetDefaultConsumerGroup().GroupName, serviceBusConnectionString, storageConnectionString);

            Console.WriteLine("Registering EventProcessor...");
            eventProcessorHost.RegisterEventProcessorAsync <ConsoleEventProcessor>().Wait();

            return(eventProcessorHost);
        }
Example #38
0
        public static async Task SetupEventProcessorDeviceMessages()
        {
            EventProcessorHost eventProcessorHost = new EventProcessorHost(Guid.NewGuid().ToString(),
                                                                           Strings.EventHubNameC2D.ToLowerInvariant(),
                                                                           Strings.EventHubConsumerGroupNameC2D,
                                                                           Strings.EventHubConnectionStringC2D,
                                                                           Strings.BLOBStorageConnectionstring);

            Console.WriteLine("Registering Cloud to Device EventProcessor...");
            var options = new EventProcessorOptions();

            options.ExceptionReceived += (sender, e) => { Console.WriteLine(e.Exception); };
            await eventProcessorHost.RegisterEventProcessorAsync <SmartHVACDeviceEventProcessor>(options);
        }
Example #39
0
        internal static EventProcessorHostPartition GetPartitionContext(string partitionId       = "0", string eventHubPath = "path",
                                                                        string consumerGroupName = "group", string owner    = null)
        {
            var processor = new EventProcessorHost(consumerGroupName,
                                                   "Endpoint=sb://test.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=abc123=",
                                                   eventHubPath,
                                                   new EventProcessorOptions(),
                                                   Int32.MaxValue, null);

            return(new EventProcessorHostPartition(partitionId)
            {
                ProcessorHost = processor
            });
        }
Example #40
0
        static void Main(string[] args)
        {
            string eventHubConnectionString = ConfigurationManager.AppSettings["Microsoft.ServiceBus.ConnectionString"];
            string eventHubName             = ConfigurationManager.AppSettings["EventHubName"];
            string storageConnectionString  = ConfigurationManager.AppSettings["Microsoft.WindowsAzure.Storage.ConnectionString"];

            string             eventProcessorHostName = Guid.NewGuid().ToString();
            EventProcessorHost eventProcessorHost     = new EventProcessorHost(eventProcessorHostName, eventHubName, EventHubConsumerGroup.DefaultGroupName, eventHubConnectionString, storageConnectionString);

            eventProcessorHost.RegisterEventProcessorAsync <Pi2EventHubProcessor>().Wait();

            Console.WriteLine("Receiving. Press enter key to stop worker.");
            Console.ReadLine();
        }
        EventProcessorHost IEventProcessorHostFactory.Create()
        {
            string eventProcessorHostName = $"MyEventProcessor-{DateTime.Now}";
            var    eventProcessorHost     = new EventProcessorHost(
                eventProcessorHostName,
                _myEventHubConfig.EventHubName,
                PartitionReceiver.DefaultConsumerGroupName,
                _myEventHubConfig.SenderConnString,
                _myEventHubConfig.StorageAccConnString,
                _myEventHubConfig.StorageContainerName
                );

            return(eventProcessorHost);
        }
Example #42
0
        /// <summary>
        /// Initialze a new instance of the event process host
        /// </summary>
        /// <returns>event processor host</returns>
        private async Task <EventProcessorHost> InitalizeEventProcessorHostAsync()
        {
            // start listening to the event hub
            var eventHubName  = ServiceFabricUtil.GetServiceFabricConfigSetting("EventHubName").Result?.ToString();
            var consumerGroup = ServiceFabricUtil.GetServiceFabricConfigSetting("ConsumerGroupName").Result?.ToString();

            var eventProcessorHost = new EventProcessorHost(
                eventHubName,
                consumerGroup,
                await SecretsStore.Instance.GetMetricsEventHubListenerConnectionStringAsync(),
                await SecretsStore.Instance.GetMetricsStorageConnectionStringAsync(),
                "metricsingestor");

            return(eventProcessorHost);
        }
Example #43
0
        async Task CheckpointEveryMessageReceived()
        {
            var eventProcessorHost = new EventProcessorHost(
                null,
                PartitionReceiver.DefaultConsumerGroupName,
                TestUtility.EventHubsConnectionString,
                TestUtility.StorageConnectionString,
                this.LeaseContainerName);

            var runResult = await RunGenericScenario(eventProcessorHost, totalNumberOfEventsToSend : 10,
                                                     checkpointLastEvent : false, checkpoingEveryEvent : true);

            // Validate there were not failures.
            Assert.True(runResult.NumberOfFailures == 0, $"RunResult returned with {runResult.NumberOfFailures} failures!");
        }
Example #44
0
        private static async Task StartReceivingCommandsAsync()
        {
            Console.WriteLine("Registering EventProcessor...");

            EventProcessorHost eventProcessorHost = CreateEventProcessorHost();

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

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

            // Disposes of the Event Processor Host
            await eventProcessorHost.UnregisterEventProcessorAsync();
        }
        static void Main(string[] args)
        {
            var ehConnectionString      = CloudConfigurationManager.GetSetting("ehConnectionString");
            var ehName                  = CloudConfigurationManager.GetSetting("ehName");
            var storageConnectionString = CloudConfigurationManager.GetSetting("azureTableConnection");

            //var storageProcHost = new EventProcessorHost(Guid.NewGuid().ToString(), ehName, "storage", ehConnectionString, storageConnectionString);
            //storageProcHost.RegisterEventProcessorAsync<StorageProcessor>().Wait();

            var entityProcHost = new EventProcessorHost(Guid.NewGuid().ToString(), ehName, "servicefabric", ehConnectionString, storageConnectionString);

            entityProcHost.RegisterEventProcessorAsync <EntityProcessor>().Wait();

            Console.ReadLine();
        }
Example #46
0
        /// <summary>
        /// Initialze a new instance of the event process host
        /// </summary>
        /// <returns>event processor host</returns>
        private async Task <EventProcessorHost> InitalizeEventProcessorHostAsync()
        {
            // start listening to the event hub
            var eventHubName  = Utility.GetConfigValue("EventHubName");
            var consumerGroup = Utility.GetConfigValue("ConsumerGroupName");

            var eventProcessorHost = new EventProcessorHost(
                eventHubName,
                consumerGroup,
                await SecretsStore.Instance.GetMetricsEventHubListenerConnectionStringAsync(),
                await SecretsStore.Instance.GetMetricsStorageConnectionStringAsync(),
                "metricsingestor");

            return(eventProcessorHost);
        }
Example #47
0
        static async Task MainAsync()
        {
            string eventHubConnectionString = "Endpoint=sb://yazha-ns.servicebus.windows.net/;SharedAccessKeyName=listen;SharedAccessKey=MFg5Ef9ueC4tYcXHrMOR+a6p9XLCQYWBUrNxMxsSk04=";
            string eventHubName             = "scalehubtest";
            string storageAccountName       = "yazha";
            string storageAccountKey        = "c4KmKhEIK0uR519ANRTIz50y7XtAdkB1nvrsy27C9JB1sajHrzY5McuEuufHuVgSqQAsj52tdv0igr2xOkD7PA==";
            string storageConnectionString  = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}",
                                                            storageAccountName, storageAccountKey);

            int         count    = 32;
            List <Task> taskList = new List <Task>();

            for (int i = 0; i < count; i++)
            {
                var tmp  = i;
                var task = Task.Run(async() =>
                {
                    string eventProcessorHostName         = Guid.NewGuid().ToString();
                    EventProcessorHost eventProcessorHost = new EventProcessorHost(eventProcessorHostName, eventHubName, EventHubConsumerGroup.DefaultGroupName, eventHubConnectionString, storageConnectionString);
                    var factory = new EventProcessorFactory(tmp);
                    await eventProcessorHost.RegisterEventProcessorFactoryAsync(factory);
                });
                taskList.Add(task);
            }

            Task.WaitAll(taskList.ToArray());

            //var t1 = Task.Run(async () =>
            //{
            //    string eventProcessorHostName = Guid.NewGuid().ToString();
            //    EventProcessorHost eventProcessorHost = new EventProcessorHost(eventProcessorHostName, eventHubName, EventHubConsumerGroup.DefaultGroupName, eventHubConnectionString, storageConnectionString);
            //    await eventProcessorHost.RegisterEventProcessorAsync<SimpleEventProcessor>();
            //});

            //var t2 = Task.Run(async () =>
            //{
            //    var eventProcessorHostName = Guid.NewGuid().ToString();
            //    EventProcessorHost eventProcessorHost2 = new EventProcessorHost(eventProcessorHostName, eventHubName, EventHubConsumerGroup.DefaultGroupName, eventHubConnectionString, storageConnectionString);
            //    var factory = new EventProcessorFactory();
            //    await eventProcessorHost2.RegisterEventProcessorFactoryAsync(factory);
            //});

            //Task.WaitAll(t1, t2);



            Console.WriteLine("Receiving. Press enter key to stop worker.");
        }
Example #48
0
        public async void StartEventProcessor()
        {
            var eventProcessorHost = new EventProcessorHost(
                conf.HubName,
                PartitionReceiver.DefaultConsumerGroupName,
                conf.ConnectionString,
                string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", conf.AccountName, conf.AccountKey),
                conf.ContainerName
                );

            this.eventProcessorHost = eventProcessorHost;

            // Registers the Event Processor Host and starts receiving messages
            // https://stackoverflow.com/questions/33371803/how-to-pass-parameters-to-an-implementation-of-ieventprocessor
            await eventProcessorHost.RegisterEventProcessorFactoryAsync(new EventProcessorFactory(collector, GetSourceId()));
        }
Example #49
0
        public async Task Connect(string hubName, string hubConnStr, string storageName, string storageConnStr, string consumerGroup)
        {
            this.eventProcessorHost = new EventProcessorHost(
                hubName,
                consumerGroup != string.Empty ? consumerGroup : PartitionReceiver.DefaultConsumerGroupName,
                hubConnStr,
                storageConnStr,
                storageName);

            EventProcessorOptions options = new EventProcessorOptions()
            {
                ReceiveTimeout = TimeSpan.FromSeconds(RECEIVE_TIMEOUT_SECS),
            };

            await this.eventProcessorHost.RegisterEventProcessorAsync <CustomEventProcessor>(options);
        }
Example #50
0
        static void Main(string[] args)
        {
            string iotHubConnectionString = ConfigurationManager.AppSettings["iotHubConnectionString"];//"HostName={iothub-name}.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey={shared-key}";
            string iotHubD2cEndpoint = "messages/events";
            StoreEventProcessor.StorageConnectionString = ConfigurationManager.AppSettings["storageConnectionString"];// "DefaultEndpointsProtocol =https;AccountName={storage-name};AccountKey={storage-key}";
            StoreEventProcessor.ServiceBusConnectionString = ConfigurationManager.AppSettings["serviceBusConnectionString"];//"Endpoint=sb://{servicebus-name}.servicebus.windows.net/;SharedAccessKeyName={servicebus-key}";

            string eventProcessorHostName = Guid.NewGuid().ToString();
            EventProcessorHost eventProcessorHost = new EventProcessorHost(eventProcessorHostName, iotHubD2cEndpoint, EventHubConsumerGroup.DefaultGroupName, iotHubConnectionString, StoreEventProcessor.StorageConnectionString, "messages-events");
            Console.WriteLine("Registering EventProcessor...");
            eventProcessorHost.RegisterEventProcessorAsync<StoreEventProcessor>().Wait();

            Console.WriteLine("Receiving. Press enter key to stop worker.");
            Console.ReadLine();
            eventProcessorHost.UnregisterEventProcessorAsync().Wait();
        }
Example #51
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            _logger.LogInformation("Message Service ... Registering EventProcessor...");
            _logger.LogInformation($"Consumer Group: {EventHubConsumerGroup}");

            eventProcessorHost = new EventProcessorHost(
                MsgSvcEventHubName,
                EventHubConsumerGroup,
                EventHubConnectionString,
                StorageConnectionString,
                StorageContainerName);

            // Registers the Event Processor Host and starts receiving messages
            //await eventProcessorHost.RegisterEventProcessorAsync<MsgServiceEventProcessor>();
            await eventProcessorHost.RegisterEventProcessorFactoryAsync(new MsgServiceEventProcessorFactory(_config, _logger, _telemetryClient));
        }
Example #52
0
        async Task StartEventProcessorHost()
        {
            string eventHubConnectionString = CloudConfigurationManager.GetSetting("ServiceBusConnectionString");
            string blobConnectionString     = CloudConfigurationManager.GetSetting("AzureStorageConnectionString");
            // Required for checkpoint/state
            string EventHubName = CloudConfigurationManager.GetSetting("EventHubName");

            eventProcessorHost = new EventProcessorHost(System.Environment.MachineName, EventHubName,
                                                        EventHubConsumerGroup.DefaultGroupName, eventHubConnectionString, blobConnectionString);
            EventProcessorOptions options = new EventProcessorOptions()
            {
                MaxBatchSize = 8192
            };

            await eventProcessorHost.RegisterEventProcessorAsync <DashboardEventHubProcessor>();
        }
        public static async Task ReceiveAsync()
        {
            Console.WriteLine("Receive Started...");
            var eventProcessorHost = new EventProcessorHost(
                Constants.EhEntityPath,
                PartitionReceiver.DefaultConsumerGroupName,
                Constants.EhConnectionString,
                Constants.StorageConnectionString,
                Constants.StorageContainerName);

            await eventProcessorHost.RegisterEventProcessorAsync <EventProcessor>();

            Console.WriteLine("Receiving. Press ENTER to stop worker.");
            Console.ReadLine();
            await eventProcessorHost.UnregisterEventProcessorAsync();
        }
Example #54
0
        static async Task Main(string[] args)
        {
            var host = new EventProcessorHost(
                HubName,
                consumerGroupName,
                HubConnectionString,
                BlobConnectionString,
                ProcessorLeaseContainerName);

            await host.RegisterEventProcessorAsync <TemperatureEventProcessor>();

            Console.WriteLine("Event processor started, press enter to stop...");

            Console.ReadLine();
            await host.UnregisterEventProcessorAsync();
        }
Example #55
0
        static void Main(string[] args)
        {
            string iotHubConnectionString = "HostName=xylotohub.azure-devices.net;SharedAccessKeyName=iothubowner;SharedAccessKey=aFtv5GRYaWWtJvsTp9NETXQh8O4mqFCqxL+F0tArtM0=";
            string iotHubD2cEndpoint = "messages/events";
            StoreEventProcessor.StorageConnectionString = "DefaultEndpointsProtocol=https;AccountName=devneuzyhubsa1;AccountKey=idRO5Eetw3XbdkFRUwtwPhlOuwe2xBPgsv3WjyhknyR0RzstIb7jyDc+R4cWfEhaRuWMZ9NA+uvGQhB5rIfeEw==;BlobEndpoint=https://devneuzyhubsa1.blob.core.windows.net/;TableEndpoint=https://devneuzyhubsa1.table.core.windows.net/;QueueEndpoint=https://devneuzyhubsa1.queue.core.windows.net/;FileEndpoint=https://devneuzyhubsa1.file.core.windows.net/";
            StoreEventProcessor.ServiceBusConnectionString = "Endpoint=sb://devneuzyhubsb2.servicebus.windows.net/;SharedAccessKeyName=send;SharedAccessKey=KXm1zyrKJ+3cuFL5junQfJw5hXEkEgOVzaGhcoFt7fA=";

            string eventProcessorHostName = Guid.NewGuid().ToString();
            EventProcessorHost eventProcessorHost = new EventProcessorHost(eventProcessorHostName, iotHubD2cEndpoint, EventHubConsumerGroup.DefaultGroupName, iotHubConnectionString, StoreEventProcessor.StorageConnectionString, "messages-events");
            Console.WriteLine("Registering EventProcessor...");
            eventProcessorHost.RegisterEventProcessorAsync<StoreEventProcessor>().Wait();

            Console.WriteLine("Receiving. Press enter key to stop worker.");
            Console.ReadLine();
            eventProcessorHost.UnregisterEventProcessorAsync().Wait();
        }
Example #56
0
        static void Main(string[] args)
        {
            string eventHubConnectionString = "讀取原則的連接字串";
              string eventHubName = "事件中樞名稱";
              string storageAccountName = "儲存體帳戶名稱";
              string storageAccountKey = "儲存體存取金鑰";
              string storageConnectionString = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}",
                  storageAccountName, storageAccountKey);

              string eventProcessorHostName = Guid.NewGuid().ToString();
              EventProcessorHost eventProcessorHost = new EventProcessorHost(eventProcessorHostName, eventHubName, EventHubConsumerGroup.DefaultGroupName, eventHubConnectionString, storageConnectionString);
              eventProcessorHost.RegisterEventProcessorAsync<ReceiveProcessor>().Wait();

              Console.WriteLine("Receiving.Press enter key to stop worker.");
              Console.ReadLine();
        }
Example #57
0
        static void Main(string[] args)
        {
            string storageAccountName = "bobjacapidemo";
            string storageAccountKey = "lvYpWSHkdHpCOnv91B4tGLClqeIIe0ouDW9mBAYAlm69NrHGHXhW/jrIJx5nTMgkxPWGzOoJ1jVMTCFjVvh9mg==";
            string storageConnectionString = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}",
                storageAccountName, storageAccountKey);

            string eventHubConnectionString = "Endpoint=sb://bobjacsb.servicebus.windows.net/;SharedAccessKeyName=Receiving;SharedAccessKey=RjMnP8d1rUzYF9knM7eB3lGrV231/WAtEOCI5dI8AtM=";
            string eventProcessorHostName = Guid.NewGuid().ToString();
            string eventHubName = "apimgtdemo";
            EventProcessorHost eventProcessorHost = new EventProcessorHost(eventProcessorHostName, eventHubName, EventHubConsumerGroup.DefaultGroupName, eventHubConnectionString, storageConnectionString);
            eventProcessorHost.RegisterEventProcessorAsync<ApiManagementEventProcessor>().Wait();

            Console.WriteLine("Receiving.  Press enter key to stop worker.");
            Console.ReadLine();
        }
Example #58
0
 public static void Main()
 {
     var eventHubName = "alert";
     var consumerGroup = "email";
     var eventProcessorName = "EmailAlertProcessor";
     var busConnectionString = ConfigurationManager.ConnectionStrings["SigfoxDemoAlertListener"].ConnectionString;
     var storageConnectionString = ConfigurationManager.ConnectionStrings["SigfoxDemoStorage"].ConnectionString;
     if (!WebJobsHelper.RunAsWebJobs)
         Console.CancelKeyPress += Console_CancelKeyPress;
     EventHubClient eventHubClient = null;
     var retries = 3;
     while (retries > 0)
     {
         try
         {
             retries--;
             eventHubClient = EventHubClient.CreateFromConnectionString(busConnectionString, eventHubName);
             retries = 0;
         }
         catch (Exception e)
         {
             Console.Error.WriteLine("Error opening source Event Hub: " + e.Message);
             if (retries == 0)
                 throw;
         }
     }
     if (consumerGroup == null)
         consumerGroup = eventHubClient.GetDefaultConsumerGroup().GroupName;
     var eventProcessorHost = new EventProcessorHost(eventProcessorName, eventHubClient.Path,
         consumerGroup, busConnectionString, storageConnectionString, eventHubName.ToLowerInvariant());
     eventProcessorHost.RegisterEventProcessorAsync<EventProcessor>().Wait();
     while (true)
     {
         if (WebJobsHelper.RunAsWebJobs)
         {
             Thread.Sleep(50);
         }
         else
         {
             Console.WriteLine("Waiting for new messages " + DateTime.UtcNow);
             Thread.Sleep(1000);
         }
         if (quit || WebJobsHelper.NeedShutdown)
             break;
     }
     eventProcessorHost.UnregisterEventProcessorAsync().Wait();
 }
Example #59
0
        private static void InitializeEventProcessorHost()
        {
            Trace.WriteLine("Initializing EventProcessor Host");

            string hostName = CreateUniqueHostname();

            try
            {
                _host = new EventProcessorHost(hostName, _eventHubPath, _consumerGroupName, _eventHubConnectionString, _storageConnectionString);
                Trace.WriteLine($"{hostName} created successfully.");
            }
            catch (Exception ex)
            {
                Trace.WriteLine($"Host creation failed: {ex.Message}\n\n{ex.StackTrace.ToString()}");
                throw;
            }
        }
Example #60
0
        static void Main(string[] args)
        {
            string eventHubConnectionString = "Endpoint=sb://gftesthub-ns.servicebus.windows.net/;SharedAccessKeyName=ReceiveRule;SharedAccessKey=wEO+aZpuPDKDp4Z8zBUlbLQ5CEhEtBqKfjztpo5MM3Y=";
            string eventHubName = "gftesthub";
            string storageAccountName = "gfeventhubstorage";
            string storageAccountKey = "DkOjsj/2NSWY62+N79+kJbR9EvPk5seonYab5U5g95n4qfKvPUPVAqNPY7R3QdX64HBomXmsCfBQIH6HMHABIw==";
            string storageConnectionString = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", storageAccountName, storageAccountKey);

            string eventProcessorHostName = Guid.NewGuid().ToString();
            EventProcessorHost eventProcessorHost = new EventProcessorHost(eventProcessorHostName, eventHubName, EventHubConsumerGroup.DefaultGroupName, eventHubConnectionString, storageConnectionString);
            Console.WriteLine("Registering EventProcessor...");
            eventProcessorHost.RegisterEventProcessorAsync<SimpleEventProcessor>().Wait();

            Console.WriteLine("Receiving. Press enter key to stop worker.");
            Console.ReadLine();
            eventProcessorHost.UnregisterEventProcessorAsync().Wait();
        }