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); }
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); } }