示例#1
0
        public Counter(Context ctx)
        {
            Context.Logger.Info("Counter constructor called");

            this.ctx = ctx;

            // Declare Input and Output schemas
            Dictionary <string, List <Type> > inputSchema = new Dictionary <string, List <Type> >();

            inputSchema.Add("default", new List <Type>()
            {
                typeof(string), typeof(char)
            });

            Dictionary <string, List <Type> > outputSchema = new Dictionary <string, List <Type> >();

            outputSchema.Add("default", new List <Type>()
            {
                typeof(string), typeof(int)
            });
            this.ctx.DeclareComponentSchema(new ComponentStreamSchema(inputSchema, outputSchema));

            // Demo how to get pluginConf info and enable ACK in Non-Tx topology
            if (Context.Config.pluginConf.ContainsKey(Constants.NONTRANSACTIONAL_ENABLE_ACK))
            {
                enableAck = (bool)(Context.Config.pluginConf[Constants.NONTRANSACTIONAL_ENABLE_ACK]);
            }
            Context.Logger.Info("enableAck: {0}", enableAck);

            //Demo how to get TopologyContext info
            if (Context.pluginType != SCPPluginType.SCP_NET_LOCAL)
            {
                Context.Logger.Info("TopologyContext info:");
                TopologyContext topologyContext = Context.TopologyContext;
                Context.Logger.Info("taskId: {0}", topologyContext.GetThisTaskId());
                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("taskNum: {0}", componentTasks.Count);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="tablename"></param>
        public EventHubWriter(Context context, Dictionary <string, Object> parms = null)
        {
            this.context   = context;
            this.appConfig = new AppConfig();

            Dictionary <string, List <Type> > inputSchema = new Dictionary <string, List <Type> >();

            inputSchema.Add(Constants.DEFAULT_STREAM_ID, new List <Type>()
            {
                typeof(string)
            });

            this.context.DeclareComponentSchema(new ComponentStreamSchema(inputSchema, null));

            TopologyContext topologyContext = Context.TopologyContext;

            if (Context.pluginType != SCPPluginType.SCP_NET_LOCAL)
            {
                Context.Logger.Info("EventHubWriter 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);
            }

            InitializeEventHub();

            if (Context.Config.pluginConf.ContainsKey(Constants.NONTRANSACTIONAL_ENABLE_ACK))
            {
                ackEnabled = (bool)(Context.Config.pluginConf[Constants.NONTRANSACTIONAL_ENABLE_ACK]);
            }

            globalStopwatch = new Stopwatch();
            globalStopwatch.Start();

            emitStopwatch = new Stopwatch();
            emitStopwatch.Start();
        }
示例#3
0
        public CountSum(Context ctx, StormTxAttempt txAttempt)
        {
            Context.Logger.Info("CountSum constructor called, TxId: {0}, AttemptId: {1}",
                                txAttempt.TxId, txAttempt.AttemptId);

            this.ctx       = ctx;
            this.txAttempt = txAttempt;

            // Declare Input and Output schemas
            Dictionary <string, List <Type> > inputSchema = new Dictionary <string, List <Type> >();

            inputSchema.Add("default", new List <Type>()
            {
                typeof(int)
            });

            Dictionary <string, List <Type> > outputSchema = new Dictionary <string, List <Type> >();

            outputSchema.Add("default", new List <Type>()
            {
                typeof(int)
            });
            this.ctx.DeclareComponentSchema(new ComponentStreamSchema(inputSchema, outputSchema));

            //demo how to get TopologyContext info
            if (Context.pluginType != SCPPluginType.SCP_NET_LOCAL)
            {
                Context.Logger.Info("TopologyContext info:");
                TopologyContext topologyContext = Context.TopologyContext;
                Context.Logger.Info("taskId: {0}", topologyContext.GetThisTaskId());
                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("taskNum: {0}", componentTasks.Count);
            }
        }
        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);
        }