/// <summary> /// Called when a task for this component is initialized within a worker on the cluster. /// It provides the spout with the environment in which the spout executes. /// </summary> /// <param name="config">The Storm configuration for this spout. This is the configuration provided to the topology merged in with cluster configuration on this machine.</param> /// <param name="topologyContext">This object can be used to get information about this task's place within the topology, including the task id and component id of this task, input and output information, etc.</param> public void Open(Config config, TopologyContext topologyContext) { return; }
public void Prepare(Config stormConf, TopologyContext context) { return; }
public void Open(IEmitter emitter, TopologyContext context) { this.emitter = emitter; }
public void InitializeEventHub() { Context.Logger.Info("Current AppConfig File: " + ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)); Context.Logger.Info("Current AppSettings: " + String.Join(Environment.NewLine, ConfigurationManager.AppSettings.AllKeys)); this.EventHubNamespace = ConfigurationManager.AppSettings["EventHubNamespace"]; if (String.IsNullOrWhiteSpace(this.EventHubNamespace)) { throw new ArgumentException("A required AppSetting cannot be null or empty", "EventHubNamespace"); } this.EventHubEntityPath = ConfigurationManager.AppSettings["EventHubEntityPath"]; if (String.IsNullOrWhiteSpace(this.EventHubEntityPath)) { throw new ArgumentException("A required AppSetting cannot be null or empty", "EventHubEntityPath"); } this.EventHubSharedAccessKeyName = ConfigurationManager.AppSettings["EventHubSharedAccessKeyName"]; if (String.IsNullOrWhiteSpace(this.EventHubSharedAccessKeyName)) { throw new ArgumentException("A required AppSetting cannot be null or empty", "EventHubSharedAccessKeyName"); } this.EventHubSharedAccessKey = ConfigurationManager.AppSettings["EventHubSharedAccessKey"]; if (String.IsNullOrWhiteSpace(this.EventHubSharedAccessKey)) { throw new ArgumentException("A required AppSetting cannot be null or empty", "EventHubSharedAccessKey"); } this.EventHubPartitions = ConfigurationManager.AppSettings["EventHubPartitions"]; if (String.IsNullOrWhiteSpace(this.EventHubPartitions)) { throw new ArgumentException("A required AppSetting cannot be null or empty", "EventHubPartitions"); } var builder = new ServiceBusConnectionStringBuilder(); builder.Endpoints.Add(new Uri("sb://" + this.EventHubNamespace + "." + EventHubFqnAddress)); builder.EntityPath = this.EventHubEntityPath; builder.SharedAccessKeyName = this.EventHubSharedAccessKeyName; builder.SharedAccessKey = this.EventHubSharedAccessKey; builder.TransportType = TransportType.Amqp; var partitionCount = int.Parse(this.EventHubPartitions); TopologyContext topologyContext = Context.TopologyContext; Context.Logger.Info(this.GetType().Name + " TopologyContext info:"); Context.Logger.Info("TaskId: {0}", topologyContext.GetThisTaskId()); var taskIndex = topologyContext.GetThisTaskIndex(); Context.Logger.Info("TaskIndex: {0}", taskIndex); string componentId = topologyContext.GetThisComponentId(); Context.Logger.Info("ComponentId: {0}", componentId); List <int> componentTasks = topologyContext.GetComponentTasks(componentId); Context.Logger.Info("ComponentTasks: {0}", componentTasks.Count); if (partitionCount != componentTasks.Count) { throw new Exception( String.Format("Component task count does not match partition count. Component: {0}, Tasks: {1}, Partition: {2}", componentId, componentTasks.Count, partitionCount)); } partitionId = taskIndex.ToString(); Context.Logger.Info(this.GetType().Name + " ConnectionString = {0}, ParitionId = {1}", builder.ToString(), partitionId); eventHubClient = EventHubClient.CreateFromConnectionString(builder.ToString()); eventHubSender = eventHubClient.CreatePartitionedSender(partitionId); }