Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var hubName = "iothub-ehub-ps-demo-hu-375407-6fb5327dad";
            var iotHubConnectionString  = "Endpoint=sb://ihsuprodblres002dednamespace.servicebus.windows.net/;SharedAccessKeyName=iothubowner;SharedAccessKey=9E1KqYZankE1dYx3oRW6V6ioUxeJgUrJ8uHrFD9fmTA=";
            var storageConnectionString = "DefaultEndpointsProtocol=https;AccountName=psdemostorage01;AccountKey=c94Pe+2fxXC0lWqiUeDa+RWrSWVGGlU2EAQzc0pBJViOjlwQiM1aU6qdzhU2MyMw9KDIq6JK6GWR1p3UqRQeGA==;EndpointSuffix=core.windows.net";
            var storageContainerName    = "message-processor-host";
            var consumerGroupName       = PartitionReceiver.DefaultConsumerGroupName;

            var processor = new EventProcessorHost(
                hubName,
                consumerGroupName,
                iotHubConnectionString,
                storageConnectionString,
                storageContainerName);

            processor.RegisterEventProcessorAsync <LoggingEventProcessor>().Wait();

            var eventHubConfig = new EventHubConfiguration();

            eventHubConfig.AddEventProcessorHost(hubName, processor);

            var configuration = new JobHostConfiguration(storageConnectionString);

            configuration.UseEventHub(eventHubConfig);

            Console.WriteLine("Starting job host…");
            var host = new JobHost(configuration);

            host.RunAndBlock();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            var hubName = Configs.HUB_NAME;
            var iotHubConnctionString   = Configs.IOT_HUB_ENDPOINT_CONNECTION_STRING;
            var storgaeConnectionString = Configs.STORAGE_CONNECTION_STRING;
            var storageContainerName    = Configs.STORAGE_CONTAINER_NAME;
            var consumerGroupName       = PartitionReceiver.DefaultConsumerGroupName;

            var processor = new EventProcessorHost(
                hubName,
                consumerGroupName,
                iotHubConnctionString,
                storgaeConnectionString,
                storageContainerName);

            processor.RegisterEventProcessorAsync <LoggingEventProcessor>().Wait();

            var eventHubConfig = new EventHubConfiguration();

            eventHubConfig.AddEventProcessorHost(hubName, processor);

            var configuration = new JobHostConfiguration(storgaeConnectionString);

            configuration.UseEventHub(eventHubConfig);

            Console.WriteLine("Starting job host (event processor)...");
            var host = new JobHost(configuration);

            host.RunAndBlock();
        }
Ejemplo n.º 3
0
            public override Collection <Attribute> GetAttributes()
            {
                Collection <Attribute> attributes = new Collection <Attribute>();

                string eventHubName = Context.GetMetadataValue <string>("path");

                if (!string.IsNullOrEmpty(eventHubName))
                {
                    eventHubName = _nameResolver.ResolveWholeString(eventHubName);
                }

                string connectionString = Context.GetMetadataValue <string>("connection");

                if (!string.IsNullOrEmpty(connectionString))
                {
                    connectionString = _nameResolver.Resolve(connectionString);
                }

                if (Context.IsTrigger)
                {
                    attributes.Add(new EventHubTriggerAttribute(eventHubName));

                    string eventProcessorHostName  = Guid.NewGuid().ToString();
                    string storageConnectionString = _storageConnectionString;

                    string consumerGroup = Context.GetMetadataValue <string>("consumerGroup");
                    if (consumerGroup == null)
                    {
                        consumerGroup = Microsoft.ServiceBus.Messaging.EventHubConsumerGroup.DefaultGroupName;
                    }

                    var eventProcessorHost = new Microsoft.ServiceBus.Messaging.EventProcessorHost(
                        eventProcessorHostName,
                        eventHubName,
                        consumerGroup,
                        connectionString,
                        storageConnectionString);

                    _eventHubConfiguration.AddEventProcessorHost(eventHubName, eventProcessorHost);
                }
                else
                {
                    attributes.Add(new EventHubAttribute(eventHubName));

                    var client = Microsoft.ServiceBus.Messaging.EventHubClient.CreateFromConnectionString(connectionString, eventHubName);
                    _eventHubConfiguration.AddEventHubClient(eventHubName, client);
                }

                return(attributes);
            }
Ejemplo n.º 4
0
        private static void Main()
        {
            var eventHubConnectionString = ConfigurationManager.AppSettings["eventHubConnectionString"];
            var eventHubName             = ConfigurationManager.AppSettings["sourceEventHubName"];
            var storageAccountName       = ConfigurationManager.AppSettings["storageAccountName"];
            var storageAccountKey        = ConfigurationManager.AppSettings["storageAccountKey"];

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

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

            var eventHubConfig = new EventHubConfiguration();

            eventHubConfig.AddEventProcessorHost(eventHubName, eventProcessorHost);

            var config = new JobHostConfiguration(storageConnectionString);

            config.UseEventHub(eventHubConfig);

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

            var options = new EventProcessorOptions();

            options.ExceptionReceived += (sender, e) =>
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(e.Exception);
                Console.ResetColor();
            };

            eventProcessorHost.RegisterEventProcessorAsync <MessageProcessor>(options);

            var host = new JobHost(config);

            host.RunAndBlock();

            eventProcessorHost.UnregisterEventProcessorAsync().Wait();
        }
        public override void ApplyToConfig(JobHostConfigurationBuilder configBuilder)
        {
            if (configBuilder == null)
            {
                throw new ArgumentNullException("configBuilder");
            }
            EventHubConfiguration eventHubConfig = configBuilder.EventHubConfiguration;

            string connectionString = null;

            if (!string.IsNullOrEmpty(Connection))
            {
                connectionString = Utility.GetAppSettingOrEnvironmentValue(Connection);
            }

            if (this.IsTrigger)
            {
                string eventProcessorHostName = Guid.NewGuid().ToString();

                string storageConnectionString = configBuilder.Config.StorageConnectionString;

                var eventProcessorHost = new Microsoft.ServiceBus.Messaging.EventProcessorHost(
                    eventProcessorHostName,
                    this.Path,
                    Microsoft.ServiceBus.Messaging.EventHubConsumerGroup.DefaultGroupName,
                    connectionString,
                    storageConnectionString);

                eventHubConfig.AddEventProcessorHost(this.Path, eventProcessorHost);
            }
            else
            {
                var client = Microsoft.ServiceBus.Messaging.EventHubClient.CreateFromConnectionString(
                    connectionString, this.Path);

                eventHubConfig.AddEventHubClient(this.Path, client);
            }
        }