示例#1
0
        private static async Task MainAsync(string[] args)
        {
            Console.WriteLine("Registering EventProcessor...");

            //string EventHubConnectionString = args[0];
            //string EventHubName = args[1];
            string EventHubConnectionString = "Endpoint=sb://sbehnspmtmt9filevalidator.servicebus.windows.net/;SharedAccessKeyName=ehpmtevtmt9validated-listen;SharedAccessKey=9MrR5pTKIRmjTUbqOZWTU719yi+Nje0e8lD/dCq0L3A=;EntityPath=ehpmtevtmt9validated";
            string EventHubName             = "ehpmtevtmt9validated";

            string StorageContainerName = "logsdata";
            string StorageAccountName   = "datastoreeventhub";
            string StorageAccountKey    = "aU/QBn63Cn2XQZkfOZdHGjoyU73bWAIlAk+2S1+yg/NMUj2kNcdfgjCIf1uUgddleB6lMneYowaNFx4lgXh0/w==";

            string StorageConnectionString = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", StorageAccountName, StorageAccountKey);

            var eventProcessorHost = new EventProcessorHost(
                EventHubName,
                PartitionReceiver.DefaultConsumerGroupName,
                EventHubConnectionString,
                StorageConnectionString,
                StorageContainerName);

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

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

            // Disposes of the Event Processor Host
            await eventProcessorHost.UnregisterEventProcessorAsync();
        }
示例#2
0
        private static void Main(string[] args)
        {
            const string eventHubConnectionString = "";
            const string eventHubName             = "";


            const string storageAccountName      = "";
            const string storageAccountKey       = "";
            var          storageConnectionString = $"DefaultEndpointsProtocol=https;AccountName={storageAccountName};AccountKey={storageAccountKey}";

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

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Registering with Event Hubs...");
            var options = new EventProcessorOptions();

            options.ExceptionReceived += (sender, e) => { Console.WriteLine(e.Exception); };
            eventProcessorHost.RegisterEventProcessorAsync <DataPersistenceConsumer>(options).Wait();

            Console.WriteLine("Receiving. Press enter key to stop worker...");
            Console.ReadLine();
            eventProcessorHost.UnregisterEventProcessorAsync().Wait();
        }
示例#3
0
        private static void Main(string[] args)
        {
            try
            {
                const string eventHubConnectionString =
                    "Endpoint=sb://shield.servicebus.windows.net/;SharedAccessKeyName=Admin;SharedAccessKey=TcvQArcvlzlyiUXnaWfnFwisb3O8WGh1VxiyG+VwvRM=";
                const string eventHubName       = "applicationmetadata";
                const string storageAccountName = "aegisanalytics";
                const string storageAccountKey  =
                    "vXKCLoUsia4HMHBSf1Jx4YzbKMkbk9Hex5kCVgTqD0thQHKdj6uNQsBzHpPp4uOsJ36b/6YYUXAMn/qVv/gOjA==";
                var storageConnectionString =
                    $"DefaultEndpointsProtocol=https;AccountName={storageAccountName};AccountKey={storageAccountKey}";

                var eventProcessorHostName = Guid.NewGuid().ToString();
                var 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 <WebTrafficEventProcessor>(options).Wait();

                Console.WriteLine("Receiving. Press enter key to stop worker.");
                Console.ReadLine();
                eventProcessorHost.UnregisterEventProcessorAsync().Wait();
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                Console.ReadLine();
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            string eventHubConnectionString = "Endpoint=sb://novanteh.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=/X/1/IdRHCqqugRdSieg40PYpGwbCKQIQsmJRJSAGjM=";
            string eventHubName             = "outgoingmsg";
            string storageAccountName       = "novanteventproc9648";
            string storageAccountKey        = "Vv3vWTAHj/MxcBg+zNQURKE2v0NniFnxtb6Cg7jR8/THMrPS+QCiMudJS5paBXb9iFVScRdN7rX33P6oxWu5hQ==";
            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();
        }
示例#5
0
 public void Dispose()
 {
     if (_eventProcessorHost != null)
     {
         _eventProcessorHost.UnregisterEventProcessorAsync().GetAwaiter().GetResult();
     }
 }
示例#6
0
        private static void Main(string[] args)
        {
            const string eventHubConnectionString = "";
            const string eventHubName             = "";

            // create a new publisher access key with send permissions in the Azure EventHub - Shared access policies
            const string publisherConnectionString = "";
            const string storageAccountName        = "";
            const string storageAccountKey         = "";
            var          storageConnectionString   = $"DefaultEndpointsProtocol=https;AccountName={storageAccountName};AccountKey={storageAccountKey}";

            var publisher = new Publisher();

            publisher.Init(publisherConnectionString);

            var strings = new List <string> {
                "Hello", "World"
            };

            publisher.Publish(strings);

            var eventProcessorHostName = Guid.NewGuid().ToString();
            var 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 <Consumer>(options).Wait();

            Console.WriteLine("Receiving. Press enter key to stop worker...");
            Console.ReadLine();
            eventProcessorHost.UnregisterEventProcessorAsync().Wait();
        }
        private void OnStopping()
        {
            _logger.LogInformation("OnStopping has been called.");

            // Perform on-stopping activities here
            _eventProcessorHost.UnregisterEventProcessorAsync();
        }
示例#8
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();
        }
示例#9
0
        private static async Task MainAsync(string[] args)
        {
            //carica le impostazioni in appsettings
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile(
                "appsettings.json",
                optional: true,
                reloadOnChange: true);
            var configuration = builder.Build();



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

            var eventProcessorHost = new EventProcessorHost(
                configuration["ConnectionStrings:EventHubPath"],
                PartitionReceiver.DefaultConsumerGroupName,
                configuration["ConnectionStrings:EventHubCS"],
                configuration["ConnectionStrings:StorageAccountCS"],
                configuration["ConnectionStrings:StorageContainer"]);

            // Registers the Event Processor Host and starts receiving messages
            await eventProcessorHost.RegisterEventProcessorFactoryAsync(
                new TeleEventProcessorFactory(configuration["ConnectionStrings:DefaultConnection"]));

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

            // Disposes of the Event Processor Host
            await eventProcessorHost.UnregisterEventProcessorAsync();
        }
示例#10
0
        private static async Task MainAsync(string[] args)
        {
            Console.WriteLine("Registering EventProcessor...");

            //Event hub settings
            string EventHubName             = Configuration["EventHubName"];
            string EventHubConnectionString = Configuration[EventHubConnectionStringSecret];

            //Storage settings
            string StorageContainerName    = Configuration["StorageContainerName"];
            string StorageConnectionString = Configuration[StorageAccountConnectionStringSecret];

            //Setup event processor host
            var eventProcessorHost = new EventProcessorHost(
                EventHubName,
                PartitionReceiver.DefaultConsumerGroupName,
                EventHubConnectionString,
                StorageConnectionString,
                StorageContainerName);

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

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

            // Disposes of the Event Processor Host
            await eventProcessorHost.UnregisterEventProcessorAsync();
        }
示例#11
0
        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();
        }
示例#12
0
 public static void CronJob([TimerTrigger("* */1 * * * *")] TimerInfo timer)
 {
     try
     {
         Console.WriteLine(String.Format("Inicio lectura mensajes : {0}", DateTime.Now.ToString()));
         string storageConnectionString = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}",
                                                        Configuracion.StorageAccountName, Configuracion.
                                                        StorageAccountKey);
         string             _guid = Guid.NewGuid().ToString();
         string             eventProcessorHostName = _guid;
         EventProcessorHost eventProcessorHost     = new EventProcessorHost(
             eventProcessorHostName,
             Configuracion.EventHubName,
             EventHubConsumerGroup.DefaultGroupName,
             Configuracion.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();
         Console.WriteLine(String.Format("Fin lectura mensajes : {0}", DateTime.Now.ToString()));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public async Task HostReregisterShouldFail()
        {
            await using (var scope = await EventHubScope.CreateAsync(1))
            {
                var connectionString   = TestUtility.BuildEventHubsConnectionString(scope.EventHubName);
                var eventProcessorHost = new EventProcessorHost(
                    string.Empty,
                    PartitionReceiver.DefaultConsumerGroupName,
                    connectionString,
                    TestUtility.StorageConnectionString,
                    scope.EventHubName.ToLower());

                try
                {
                    // Calling register for the first time should succeed.
                    TestUtility.Log("Registering EventProcessorHost for the first time.");
                    await eventProcessorHost.RegisterEventProcessorAsync <TestEventProcessor>();

                    await Assert.ThrowsAsync <InvalidOperationException>(async() =>
                    {
                        TestUtility.Log("Registering EventProcessorHost for the second time which should fail.");
                        await eventProcessorHost.RegisterEventProcessorAsync <TestEventProcessor>();
                    });
                }
                finally
                {
                    await eventProcessorHost.UnregisterEventProcessorAsync();
                }
            }
        }
示例#14
0
        public static async Task Main(string[] args)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                          .AddEnvironmentVariables();


            var configuration = builder.Build();

            var connectionString        = configuration["EventHub:ListenConnectionString"];
            var storageConnectionString = configuration["EventHub:StorageConnectionString"];
            var consumerGroup           = configuration["EventHub:ConsumerGroup"];
            var leaseContainerName      = configuration["EventHub:StorageContainerName"];
            var eventHubName            = configuration["EventHub:Name"];


            Console.WriteLine($"Register the {nameof(TestEventProcessor)}");

            var eventProcessorHost = new EventProcessorHost(eventHubName, consumerGroup, connectionString,
                                                            storageConnectionString, leaseContainerName);

            await eventProcessorHost.RegisterEventProcessorAsync <TestEventProcessor>().ConfigureAwait(false);

            Console.WriteLine("Waiting for incoming events ...");
            Console.WriteLine("Press any key to shutdown");
            Console.ReadLine();

            await eventProcessorHost.UnregisterEventProcessorAsync().ConfigureAwait(false);
        }
示例#15
0
        static async Task MainAsync(string[] args)
        {
            Console.WriteLine("Registering EventProcessor...");

            var connectionString               = "Endpoint=sb://huntappeventhub.servicebus.windows.net/;SharedAccessKeyName=SendListen;SharedAccessKey=5ZAynJMui0LEfsIkZEQTdmRzZQv1C3iHw2XLziS68AI=";
            var entityPath                     = "games";
            var storageAccountName             = "huntappstorage";
            var storageAccountContainer        = "events";
            var storageAccountKey              = "0ZMsQe9PdwKzP9y/d8cxcWn9nGH/2zlATiBsRYVmyCCiw84Nn4BSYtZ6Cc+kLLDkVGlcrv2x2DA8ndkK+JoqMQ==";
            var storageAccountConnectionString = $"DefaultEndpointsProtocol=https;AccountName={storageAccountName};AccountKey={storageAccountKey}";

            var eventProcessorHost = new EventProcessorHost(
                entityPath,
                PartitionReceiver.DefaultConsumerGroupName,
                connectionString,
                storageAccountConnectionString,
                storageAccountContainer);

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

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

            // Disposes of the Event Processor Host
            await eventProcessorHost.UnregisterEventProcessorAsync();
        }
示例#16
0
        private static async Task CheckpointLatest(EventHubRuntimeInformation runtimeInformation)
        {
            var leasedPartitionIds = new HashSet <string>();
            var stopwatch          = new Stopwatch();

            EventProcessorHost processorHost = GetEventProcessorHost();

            var factory = new CheckpointerFactory(() => new Checkpointer
            {
                OnOpen       = partitionContext => leasedPartitionIds.Add(partitionContext.PartitionId),
                OnCheckpoint = eventData => stopwatch.Restart()
            });
            await processorHost.RegisterEventProcessorFactoryAsync(factory);

            do
            {
                await Task.Delay(10);
            }while (leasedPartitionIds.Count < runtimeInformation.PartitionCount);

            stopwatch.Start();
            do
            {
                await Task.Delay(10);
            }while (stopwatch.Elapsed.TotalSeconds < 1.0);
            stopwatch.Stop();

            await processorHost.UnregisterEventProcessorAsync();
        }
示例#17
0
        public static async Task Main(string[] args)
        {
            string hostName = "host-" + Guid.NewGuid().ToString().Substring(0, 5);

            Console.WriteLine($"Registering EventProcessor {hostName}");

            var eventProcessorHost = new EventProcessorHost(
                hostName,
                EventHubName,
                PartitionReceiver.DefaultConsumerGroupName,
                EventHubConnectionString,
                StorageConnectionString,
                StorageContainerName);

            // Registers the Event Processor Host and starts receiving messages
            await eventProcessorHost.RegisterEventProcessorAsync <SimpleEventProcessor>(new EventProcessorOptions()
            {
                InitialOffsetProvider = (partitionId) => EventPosition.FromEnd()
            });

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

            // Disposes of the Event Processor Host
            await eventProcessorHost.UnregisterEventProcessorAsync();
        }
示例#18
0
        public async Task RunAsync(CancellationToken ct)
        {
            PrintBootstrapInfo();
            CheckConfiguration();

            await RunEventProcessorAsync();

            var refreshLogicTask   = RefreshLogicAsync(ct);
            var logThroughtputTask = LogThroughputAsync(ct);

            while (!ct.IsCancellationRequested)
            {
                try
                {
                    await Task.Delay(TimeSpan.FromSeconds(30), ct);
                }
                catch (OperationCanceledException)
                {
                    // Task was canceled. Nothing to do
                }
            }

            await eventProcessorHost.UnregisterEventProcessorAsync();

            await Task.WhenAll(refreshLogicTask, logThroughtputTask);
        }
示例#19
0
        protected override async Task OnCloseAsync(CancellationToken cancellationToken)
        {
            _logger.LogInformation(nameof(OnCloseAsync));
            await _host.UnregisterEventProcessorAsync();

            await base.OnCloseAsync(cancellationToken);
        }
        private static async Task MainAsync(string[] args)
        {
            string[] cassandraDbIp = new string[1];
            cassandraDbIp[0] = "192.168.1.103";


            SimpleEventProcessor.failedTimer.Interval = 5000;
            SimpleEventProcessor.failedTimer.Elapsed += FailedTimer_Elapsed;
            SimpleEventProcessor.failedTimer.Start();

            dal.StartCassandraSession(cassandraDbIp, null, null);

            Console.WriteLine("Initialized cassandra session");

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

            var eventProcessorHost = new EventProcessorHost(
                eventHubName,
                PartitionReceiver.DefaultConsumerGroupName,
                connectionString,
                StorageConnectionString,
                StorageContainerName);

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

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

            // Disposes of the Event Processor Host
            await eventProcessorHost.UnregisterEventProcessorAsync();
        }
示例#21
0
        private static async Task MainAsync()
        {
            Console.WriteLine("Registering EventProcessor...");

            var eventProcessorHost = new EventProcessorHost(Constants.GstnReqEventHub,
                                                            PartitionReceiver.DefaultConsumerGroupName,
                                                            Constants.GstnReqHubConnectionRead,
                                                            Constants.BlobStorageConnection,
                                                            "gstn-req-event-hub-container");
            //var eventProcessorHost = new EventProcessorHost(ConfigurationManager.AppSettings["GstnReqEventHub"].ToString(),
            //                                              PartitionReceiver.DefaultConsumerGroupName,
            //                                               ConfigurationManager.AppSettings["GstnReqHubConnectionRead"].ToString(),
            //                                              ConfigurationManager.AppSettings["BlobStorageConnection"].ToString(),
            //                                              ConfigurationManager.AppSettings["BlobContainer"].ToString());

            // registration fails and retry
            var options = new Microsoft.Azure.EventHubs.Processor.EventProcessorOptions()
            {
                MaxBatchSize   = 10,
                ReceiveTimeout = TimeSpan.FromSeconds(5),
                //InitialOffsetProvider = (partitionId) => "4312342208",
                //InitialOffsetProvider = (partitionId) => 98585,
            };
            await eventProcessorHost.RegisterEventProcessorAsync <EventHubProcessor>(options);

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

            // Disposes of the Event Processor Host
            //On Shutdown unregister the application from event Hub
            // Webhook call to shutdown
            // async health monitoring and log
            //
            await eventProcessorHost.UnregisterEventProcessorAsync();
        }
示例#22
0
        private static async Task StartAsync()
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json");
            IConfiguration configuration = builder.Build();

            var ehConnectionString      = configuration["EhConnectionString"];
            var eventHubName            = configuration["EhEntityPath"];
            var storageContainerName    = configuration["StorageContainerName"];
            var storageAccountName      = configuration["StorageAccountName"];
            var storageAccountKey       = configuration["StorageAccountKey"];
            var storageConnectionString = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", storageAccountName, storageAccountKey);

            var eventProcessorHost = new EventProcessorHost(
                Guid.NewGuid().ToString(),
                eventHubName,
                PartitionReceiver.DefaultConsumerGroupName,
                ehConnectionString,
                storageConnectionString,
                storageContainerName
                );

            var eventProcessorOptions = new EventProcessorOptions
            {
                InitialOffsetProvider = (partitionId) => EventPosition.FromEnqueuedTime(DateTime.UtcNow)
            };
            await eventProcessorHost.RegisterEventProcessorAsync <SimpleEventProcessor>(eventProcessorOptions);

            Console.WriteLine("Receiving. Press Enter to stop worker.");
            Console.ReadLine();
            await eventProcessorHost.UnregisterEventProcessorAsync();
        }
示例#23
0
        static async Task MainAsync(string[] args)
        {
            IConfiguration configuration = new ConfigurationBuilder()
                                           .SetBasePath(Directory.GetCurrentDirectory())
                                           .AddJsonFile("settings.json", true, true)
                                           .AddJsonFile("local.settings.json", false, true)
                                           .Build();

            string StorageConnectionString = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", configuration["StorageAccountName"], configuration["StorageAccountKey"]);

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

            var eventProcessorHost = new EventProcessorHost(
                configuration["EventHubName"],
                PartitionReceiver.DefaultConsumerGroupName,
                configuration["EventHubConnectionString"],
                StorageConnectionString,
                configuration["StorageContainerName"]);

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

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

            // Disposes of the Event Processor Host
            await eventProcessorHost.UnregisterEventProcessorAsync();
        }
示例#24
0
        private async Task RunAsync()
        {
            Console.WriteLine("Registering EventProcessor...");

            var eventProcessorHost = new EventProcessorHost(
                EhEntityPath,
                PartitionReceiver.DefaultConsumerGroupName,
                EhConnectionString,
                StorageConnectionString,
                StorageContainerName);

            var eventProcessorOptions = new EventProcessorOptions();

            eventProcessorOptions.SetExceptionHandler(e => {
                Console.WriteLine("Error: " + e.Exception);
            });

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

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

            // Disposes of the Event Processor Host
            await eventProcessorHost.UnregisterEventProcessorAsync();
        }
示例#25
0
 private async void CleanUp()
 {
     if (eventProcessorHost != null)
     {
         await eventProcessorHost.UnregisterEventProcessorAsync();
     }
 }
示例#26
0
        static async Task <int> Run(string eventHubConnectionString, string eventHubName, string storageConnectionString, string storageContainerName, string consumerGroup)
        {
            Console.WriteLine("Running...");
            Console.WriteLine($"Connecting to {eventHubConnectionString} with {storageConnectionString}");
            Console.WriteLine($"Consumer group is:  {consumerGroup}");
            EventProcessorHost eventProcessorHost = new EventProcessorHost(
                eventHubName,
                consumerGroup == null ? PartitionReceiver.DefaultConsumerGroupName : consumerGroup,
                eventHubConnectionString,
                storageConnectionString,
                storageContainerName);

            // Registers the Event Processor Host and starts receiving messages
            await eventProcessorHost.RegisterEventProcessorAsync <SimpleEventProcessor>(
                new EventProcessorOptions
            {
                InitialOffsetProvider = partitionId => EventPosition.FromEnqueuedTime(DateTime.UtcNow)
            });

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

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

            return(0);
        }
示例#27
0
        private static async Task ProcesarMensajesEventHub(string[] args)
        {
            //RECUPERAMOS LA CADENA EVENTHUB
            //Y STORAGE DEL CONFIG
            String cadenaeventhub =
                ConfigurationManager.AppSettings["eventhub"];
            String cadenastorage =
                ConfigurationManager.AppSettings["cuentastorage"];

            Console.WriteLine("Comenzando el procesado de mensajes");
            //CREAMOS EL PROCESADOR DE MENSAJES
            EventProcessorHost procesadormensajes =
                new EventProcessorHost(
                    "PROCESADOR CONSOLA",
                    "centromensajestajamar",
                    EventHubConsumerGroup.DefaultGroupName,
                    cadenaeventhub, cadenastorage);
            //CREAMOS OPCIONES PARA EL PROCESO
            EventProcessorOptions opcionesproceso = new EventProcessorOptions()
            {
                MaxBatchSize   = 100,
                PrefetchCount  = 1,
                ReceiveTimeOut = TimeSpan.FromSeconds(20)
            };

            //REGISTRAMOS EL PROCESO CON LA CLASE QUE
            //ADMINISTRARA LA RECEPCION DE MENSAJES
            await procesadormensajes.RegisterEventProcessorAsync <ProcesadorMensajes>();

            Console.WriteLine("Recibiendo. Pulse ENTER cuando quiera finalizar.");
            Console.ReadLine();

            //FINALIZAMOS LA LECTURA DE MENSAJES
            await procesadormensajes.UnregisterEventProcessorAsync();
        }
        static void Main(string[] args)
        {
            string eventHubConnectionString = ConfigurationManager.AppSettings["EventHubConnectionString"];
            string eventHubName             = ConfigurationManager.AppSettings["EventHubName"];
            string storageAccountName       = ConfigurationManager.AppSettings["StorageAccountName"];
            string storageAccountKey        = ConfigurationManager.AppSettings["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);

            try
            {
                Console.WriteLine("Registering EventProcessor...");
                var options = new EventProcessorOptions();
                options.ExceptionReceived += (sender, e) => { Console.WriteLine(e.Exception); };
                eventProcessorHost.RegisterEventProcessorAsync <SimpleEventProcessor>(options).Wait();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }


            Console.WriteLine("Receiving. Press enter key to stop worker.");
            Console.ReadLine();
            eventProcessorHost.UnregisterEventProcessorAsync().Wait();
        }
示例#29
0
        private static async Task ReceiveMessages(string[] args)
        {
            const string listenEventHubConnectionString = "<<<Listen Event Hub ConnectionString>>>";
            const string eventHubName         = "<<<Event Hub Name>>>";
            const string storageContainerName = "<<<Storage Container Name>>>";
            const string storageAccountName   = "<<<Storage Account Name>>>";
            const string storageAccountKey    = "<<<StorageAccountKey>>>";

            var storageConnectionString = $"DefaultEndpointsProtocol=https;AccountName={storageAccountName};AccountKey={storageAccountKey}";

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

            var eventProcessorHost = new EventProcessorHost(
                eventHubName,
                PartitionReceiver.DefaultConsumerGroupName,
                listenEventHubConnectionString,
                storageConnectionString,
                storageContainerName);

            var processorOptions = new EventProcessorOptions {
            };
            // Registers the Event Processor Host and starts receiving messages
            await eventProcessorHost.RegisterEventProcessorAsync <SimpleEventProcessor>(new EventProcessorOptions());

            Console.WriteLine("Receiving.");

            // Disposes of the Event Processor Host
            await eventProcessorHost.UnregisterEventProcessorAsync();
        }
示例#30
0
 public static async Task Unregister()
 {
     if (eventProcessorHost != null)
     {
         await eventProcessorHost.UnregisterEventProcessorAsync();
     }
 }
示例#31
0
        public async Task BasicEventProcessorHost()
        {
            await using var scope = await EventHubScope.CreateAsync(1);

            #region Snippet:EventHubs_Migrate_T1_BasicEventProcessorHost
#if SNIPPET
            var storageConnectionString = "<< CONNECTION STRING FOR THE STORAGE ACCOUNT >>";
            var blobContainerName       = "<< NAME OF THE BLOB CONTAINER >>";

            var eventHubsConnectionString = "<< CONNECTION STRING FOR THE EVENT HUBS NAMESPACE >>";
            var eventHubName  = "<< NAME OF THE EVENT HUB >>";
            var consumerGroup = "<< NAME OF THE EVENT HUB CONSUMER GROUP >>";
#else
            var storageConnectionString = TestUtility.StorageConnectionString;
            var blobContainerName       = "migragionsample";

            var eventHubsConnectionString = TestUtility.EventHubsConnectionString;
            var eventHubName  = scope.EventHubName;
            var consumerGroup = PartitionReceiver.DefaultConsumerGroupName;
#endif

            var eventProcessorHost = new EventProcessorHost(
                eventHubName,
                consumerGroup,
                eventHubsConnectionString,
                storageConnectionString,
                blobContainerName);

            try
            {
                // Registering the processor class will also signal the
                // host to begin processing events.

                await eventProcessorHost.RegisterEventProcessorAsync <SimpleEventProcessor>();

                // The processor runs in the background, to allow it to process,
                // this example will wait for 30 seconds and then trigger
                // cancellation.

                using var cancellationSource = new CancellationTokenSource();
                cancellationSource.CancelAfter(TimeSpan.FromSeconds(30));

                await Task.Delay(Timeout.Infinite, cancellationSource.Token);
            }
            catch (TaskCanceledException)
            {
                // This is expected when the cancellation token is
                // signaled.
            }
            finally
            {
                // Unregistering the processor class will signal the
                // host to stop processing.

                await eventProcessorHost.UnregisterEventProcessorAsync();
            }

            #endregion
        }
示例#32
0
 public void Dispose()
 {
     if (_host != null)
     {
         _host.UnregisterEventProcessorAsync().Wait();
         _host = null;
     }
 }
示例#33
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();
        }
示例#34
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();
        }
示例#35
0
文件: Program.cs 项目: danvy/sigfox
 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();
 }
示例#36
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();
        }
        public void ProcessMessages(ref EventProcessorHost host, ref object thelock, ref bool registered, bool active)
        {
            ServicePointManager.DefaultConnectionLimit = 12;

            lock (thelock)
            {
                if (active)
                {
                    if (!registered)
                    {
                        try
                        {
                            EventProcessorOptions options = new EventProcessorOptions();
                            options.InitialOffsetProvider = (partitionId) => DateTime.UtcNow;

                            host.RegisterEventProcessorAsync<MessageProcessor>(options).Wait();
                            registered = true;
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.Message);
                            registered = false;
                        }
                    }
                }
                else
                {
                    if (registered)
                    {
                        try
                        {
                            host.UnregisterEventProcessorAsync().Wait();
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.Message);
                        }
                        finally
                        {
                            registered = false;
                        }
                    }
                }
            }
        }
示例#38
0
        static void Main(string[] args)
        {
            string eventHubConnectionString = "{Endpoint=sb://infotron-ns.servicebus.windows.net/;SharedAccessKeyName=ReceiveRule;SharedAccessKey=qHLYZvpuX2aBLijgkLJew4CpdUEPHlt6BSLQ/8ZjELU=}";
              string eventHubName = "{infotron}";
              string storageAccountName = "{infotroneventhubstorage}";
              string storageAccountKey = "{+QJ2u4jJNKaU9EUcFGlHa2yWQOTZjrRHF3DS4ZmpoJYfPIydqvAKj7MouytLnvR/1qdaUSc1rrNBeHtQbBeaYQ==}";
              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();
        }
示例#39
0
        static void Main(string[] args)
        {
            string eventHubConnectionString = "<reader connection string>";
            string eventHubName = "<hub name>";
            string storageAccountName = "<storage account name";
            string storageAccountKey = "<storage account key>";
            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();
        }
        static void Main(string[] args)
        {
            string iotHubConnectionString = "{iot hub connection string}";
            string iotHubD2cEndpoint = "messages/events";
            StoreEventProcessor.StorageConnectionString = "{storage connection string}";
            StoreEventProcessor.ServiceBusConnectionString = "{service bus send connection string}";


            StoreEventProcessor.QueueName = "softdatiot";

            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();
        }
示例#41
0
        public static void ReceivePartitionMessage()
        {
            string storageAccountName = "elsaotuo";
            string storageAccountKey =
                "AV49N0PZ1Qlz42b0w47EPoPbNLULgxYOWxsO4IvFmrAkZPzkdGCKKOJqyiHVGfAPex6HhkDSWpNQAIuPmBHBMA==";
            string storageConnectionString =
                String.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}",
                    storageAccountName, storageAccountKey);

            string eventProcessorHostName = Guid.NewGuid().ToString();
            EventProcessorHost eventProcessorHost = new EventProcessorHost("1", eventHubName,
                EventHubConsumerGroup.DefaultGroupName, eventHubConnectionString, storageConnectionString);
            Console.WriteLine("Registering EventProcessor...");
            eventProcessorHost.RegisterEventProcessorAsync<EventProcessor>(new EventProcessorOptions()
            {
                //InitialOffsetProvider = (partitionId) => DateTime.UtcNow
            }).Wait();
            eventProcessorHost.UnregisterEventProcessorAsync().Wait();
        }
示例#42
0
        // Please set the following connection strings in app.config for this WebJob to run:
        // AzureWebJobsDashboard and AzureWebJobsStorage
        static void Main()
        {
            var host = new JobHost();
            string iotHubConnectionString = ConfigurationManager.AppSettings["iotHubConnectionString"];

            //https://azure.microsoft.com/en-us/documentation/articles/iot-hub-devguide/#endpoints
            string iotHubD2cEndpoint = "messages/events";
            SKSEventProcessor.StorageConnectionString = ConfigurationManager.AppSettings["storageConnectionString"];
            SKSEventProcessor.ServiceBusConnectionString = ConfigurationManager.AppSettings["serviceBusConnectionString"];

            string eventProcessorHostName = Guid.NewGuid().ToString();
            EventProcessorHost eventProcessorHost = new EventProcessorHost(eventProcessorHostName, iotHubD2cEndpoint, EventHubConsumerGroup.DefaultGroupName, iotHubConnectionString, SKSEventProcessor.StorageConnectionString,"messages-events");

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

            Console.WriteLine("Receiving. Press enter key to stop worker.");
            host.RunAndBlock();
            eventProcessorHost.UnregisterEventProcessorAsync().Wait();
        }
示例#43
0
        static void Main(string[] args)
        {
            string eventHubConnectionString = ConfigurationManager.AppSettings["eventHubReceiveRuleConnectionString"];
            string eventHubName = ConfigurationManager.AppSettings["eventHubName"];
            string storageAccountName = ConfigurationManager.AppSettings["storageAccountName"];
            string storageAccountKey = ConfigurationManager.AppSettings["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();
        }
示例#44
0
        static void Main(string[] args)
        {
            string eventHubName = "myeventhub";
               string eventHubConnectionString =
                "Endpoint=sb://myeventhub-johnson.servicebus.windows.net/;SharedAccessKeyName=ListenKeyMyEventHub;SharedAccessKey=bdIVbIb/zpblWEXtTVRWs0wfL/tPKyMFyPWI9+9PFP8=";

            string storageAccountName = "jwwas";
            string storageAccountKey = "cKBEo0jEgIDq7qApSr0KRNP+lD+yOylDomrpfI9CNrhfAeQwW0iE+/UAlX9A7sAcFn5Phm3muu9Qs2igBqRNfA==";
            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();
        }
示例#45
0
文件: Program.cs 项目: danvy/sigfox
 static void Main(string[] args)
 {
     var eventHubName = "dispatch";
     var consumerGroup = "log";
     var busConnectionString = ConfigurationManager.ConnectionStrings["SigfoxDemoDispatchListener"].ConnectionString;
     var storageConnectionString = ConfigurationManager.ConnectionStrings["SigfoxDemoStorage"].ConnectionString;
     Console.CancelKeyPress += Console_CancelKeyPress;
     var eventHubClient = EventHubClient.CreateFromConnectionString(busConnectionString, eventHubName);
     if (consumerGroup == null)
         consumerGroup = eventHubClient.GetDefaultConsumerGroup().GroupName;
     var eventProcessorHost = new EventProcessorHost("DispatchLogProcessor", eventHubClient.Path,
         consumerGroup, busConnectionString, storageConnectionString, eventHubName.ToLowerInvariant());
     eventProcessorHost.RegisterEventProcessorAsync<EventProcessor>().Wait();
     while (true)
     {
         Console.WriteLine("Waiting for new messages " + DateTime.UtcNow);
         Thread.Sleep(1000);
         if (breaking)
             break;
     }
     eventProcessorHost.UnregisterEventProcessorAsync().Wait();
 }
        static void Main(string[] args)
        {
            string eventProcessorHostName = Guid.NewGuid().ToString();
            EventProcessorHost eventProcessorHost = new EventProcessorHost(
                eventProcessorHostName,
                _eventHubName,
                EventHubConsumerGroup.DefaultGroupName,
                _consumerConnectionStr,
                _storageConnectionStr);

            try
            {
                eventProcessorHost.RegisterEventProcessorAsync<SimpleEventProcessor>().Wait();

                ObserverRegistry registry = new ObserverRegistry();
                foreach (IObserver observer in registry.GetObservers())
                {
                    SimpleEventProcessor.OnMessageReceived += new EventHandler<MessageReceivedEventArgs>(
                    (sender, e) => observer.When(e));
                }
                
                var producer = EventHubClient.CreateFromConnectionString(_producerConnectionStr, _eventHubName);

                while (true)
                {
                    producer.Send(new EventData(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString())));
                    Task.Delay(TimeSpan.FromSeconds(30)).Wait();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            finally
            {
                eventProcessorHost.UnregisterEventProcessorAsync().Wait();
            }
        }
示例#47
0
        static void Main(string[] args)
        {
            // string eventHubConnectionString = "Endpoint=sb://sensnet-ns.servicebus.windows.net/;SharedAccessKeyName=receiver;SharedAccessKey=nKDaV5RlOrWBSO325P/1LU9qH3znVm+K30nF+dEsnB0=";
            // string eventHubName = "motiontracker";
            string eventHubConnectionString = "Endpoint=sb://sensnet-ns.servicebus.windows.net/;SharedAccessKeyName=manager;SharedAccessKey=ud0mrmEm+jTmQpVqI5EPNxQyfhuTBlspl7lvLmoLXoM=";
            string eventHubName = "discovery";
            string storageAccountName = "sensenet";
            string storageAccountKey = "iSsBgDqpkWeLhGZLWF1LZ21qUUeEeGUxHk1wS84wZ80hxujvPGNMhGxm+MdoL6HTKdTeTjAJrSEiBI1MzrOtaw==";
            string storageConnectionString = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}",
                storageAccountName, storageAccountKey);

            CloudStorageAccount storageAccount = CreateStorageAccountFromConnectionString(CloudConfigurationManager.GetSetting("StorageConnectionString"));

            // Create a blob client for interacting with the blob service.
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            Console.WriteLine("1. Creating Container");
            CloudBlobContainer container = blobClient.GetContainerReference("motiontracker");
            try
            {
                container.CreateIfNotExists();
            }
            catch (StorageException)
            {
                Console.WriteLine("If you are running with the default configuration please make sure you have started the storage emulator. Press the Windows key and type Azure Storage to select and run it from the list of applications - then restart the sample.");
                Console.ReadLine();
                throw;
            }

            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();
        }
示例#48
0
        static void Main(string[] args)
        {
            Bifrost.Configuration.Configure.DiscoverAndConfigure();

            var eventProcessorHostName = "";
            var eventHubConnectionString = "";
            var eventHubName = "";
            var storageAccountName = "";
            var storageAccountKey = "";
            var storageConnectionString = $"DefaultEndpointsProtocol=https;AccountName={storageAccountName};AccountKey={storageAccountKey}";

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

            eventProcessorHost.RegisterEventProcessorFactoryAsync(new EventProcessorFactory());

            try
            {
#if (DEBUG)
                Console.WriteLine("Processing");
                Console.ReadLine();
#else
                var config = new JobHostConfiguration();

                var host = new JobHost(config);
                host.RunAndBlock();
#endif
            }
            finally
            {

                eventProcessorHost.UnregisterEventProcessorAsync().Wait();
            }
        }
        async Task StartProcessor(CancellationToken token)
        {
            try
            {
                // Initialize
                _eventProcessorHost = new EventProcessorHost(
                    Environment.MachineName,
                    _configurationProvider.GetConfigurationSettingValue("eventHub.HubName").ToLowerInvariant(),
                    EventHubConsumerGroup.DefaultGroupName,
                    _configurationProvider.GetConfigurationSettingValue("eventHub.ConnectionString"),
                    _configurationProvider.GetConfigurationSettingValue("eventHub.StorageConnectionString"));

                _factory = new DeviceAdministrationProcessorFactory(_deviceLogic, _configurationProvider);
                Trace.TraceInformation("DeviceEventProcessor: Registering host...");
                var options = new EventProcessorOptions();
                options.ExceptionReceived += OptionsOnExceptionReceived;
                await _eventProcessorHost.RegisterEventProcessorFactoryAsync(_factory);

                // processing loop
                while (!token.IsCancellationRequested)
                {
                    Trace.TraceInformation("DeviceEventProcessor: Processing...");
                    await Task.Delay(TimeSpan.FromMinutes(5), token);

                    // Any additional incremental processing can be done here (like checking states, etc).
                }

                // cleanup
                await _eventProcessorHost.UnregisterEventProcessorAsync();
            }
            catch (Exception e)
            {
                Trace.TraceInformation("Error in DeviceEventProcessor.StartProcessor, Exception: {0}", e.Message);
            }
            _running = false;
        }
        static void Main(string[] args)
        {
            string eventHubConnectionString = AppConfig.eventHubConnectionString;
            string eventHubName = AppConfig.eventHubName;
            string storageAccountName = AppConfig.storageAccountName;
            string storageAccountKey = AppConfig.storageAccountKey;
            string consumerGroupName = AppConfig.consumerGroupName;
            string storageConnectionString = AppConfig.storageConnectionString;

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

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

            Console.WriteLine("Receiving. Press enter key to stop worker.");
            Console.ReadLine();
            eventProcessorHost.UnregisterEventProcessorAsync().Wait();
        }
        private static void Main(string[] args)
        {
            var ehDefinition = new EventHubDefinition
            {
                ServiceNamespace = "windowsiot1",
                DeviceId = "windows10iot",
                EventHubName = "windowsiot1eventhub",
                ConnectionString = "Endpoint=sb://windowsiot1.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=gyj5SAwTzrVE3f1XFuT4uyC7bqB82hcPu61D/wx7kl8=",
                StorageAccountKey = "FyOzVoluW3xGYWWslUdwYk9yPYOi5C+K69bDDQpGIvZ4SwFRXfuFtd0I/sJCxC0k26GLWQK1OY+BSiyAdFzbww==",
                StorageAccountName = "ehstorage1"
            };

            var storageConnectionString = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", ehDefinition.StorageAccountName, ehDefinition.StorageAccountKey);

            var eventProcessorHostName = Guid.NewGuid().ToString();
            var eventProcessorHost = new EventProcessorHost(eventProcessorHostName, ehDefinition.EventHubName, EventHubConsumerGroup.DefaultGroupName, ehDefinition.ConnectionString, storageConnectionString);

            System.Console.WriteLine(DateTime.Now + ":Registering EventProcessor...");
            eventProcessorHost.RegisterEventProcessorAsync<SimpleEventProcessor>().Wait();

            System.Console.WriteLine(DateTime.Now + ":Receiving. Press enter key to stop worker.");
            System.Console.ReadLine();
            eventProcessorHost.UnregisterEventProcessorAsync().Wait();
        }
        private async Task StartProcessor(CancellationToken token)
        {
            try
            {
                string hostName = Environment.MachineName;
                string eventHubPath = _configurationProvider.GetConfigurationSettingValue("RulesEventHub.Name");
                string consumerGroup = EventHubConsumerGroup.DefaultGroupName;
                string eventHubConnectionString = _configurationProvider.GetConfigurationSettingValue("RulesEventHub.ConnectionString");
                string storageConnectionString = _configurationProvider.GetConfigurationSettingValue("device.StorageConnectionString");

                _eventProcessorHost = new EventProcessorHost(
                    hostName,
                    eventHubPath,
                    consumerGroup,
                    eventHubConnectionString,
                    storageConnectionString);

                _factory = new ActionProcessorFactory(
                    _actionLogic,
                    _actionMappingLogic,
                    _configurationProvider);

                Trace.TraceInformation("ActionEventProcessor: Registering host...");
                var options = new EventProcessorOptions();
                options.ExceptionReceived += OptionsOnExceptionReceived;
                await _eventProcessorHost.RegisterEventProcessorFactoryAsync(_factory);

                // processing loop
                while (!token.IsCancellationRequested)
                {
                    Trace.TraceInformation("ActionEventProcessor: Processing...");
                    await Task.Delay(TimeSpan.FromMinutes(5), token);
                }

                // cleanup
                await _eventProcessorHost.UnregisterEventProcessorAsync();
            }
            catch (Exception e)
            {
                Trace.TraceError("Error in ActionProcessor.StartProcessor, Exception: {0}", e.ToString());
            }
            _isRunning = false;
        }
示例#53
0
文件: Program.cs 项目: leestott/Beats
        static void Main(string[] args)
        {
            string eventHubConnectionString = "Endpoint=sb://beats-ns.servicebus.windows.net/;SharedAccessKeyName=manage;SharedAccessKey=hyZPOugpflLQ6/nIlwzKh3uqwtQa1NwLOOL9yxWPR+s=";
            string eventHubName = "beats";
            string storageAccountName = "beast";
            string storageAccountKey = "qIol5cl06GF1OO8anp2r5Kl1yCR7WcBQcTUSSZ3Ta48Knrrl6vpTgAWhyrRTR1C/54BAvKMbuXOjSuak7UpMBw==";
            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();
        }