Exemplo n.º 1
0
        public void Execute(SCPTuple tuple)
        {
            try
            {
                SerializableTweet tweet = tuple as SerializableTweet;
                //tweet.Text = tuple.GetString(0);
                //tweet.Id = tuple.GetLong(1);
                //tweet.RetweetCount = tuple.GetInteger(2);
                //tweet.FavoriteCount = tuple.GetInteger(3);
                //tweet.UserFollowerCount = tuple.GetInteger(4);
                Context.Logger.Info("SQL AZURE: " + tweet.ToString());

                //TODO: Insert or Upsert or Delete depending on your logic
                //Delete(new List<int>() { 1, 2 }, tuple.GetValues());
                //Upsert(new List<int>() { 1, 2 }, tuple.GetValues());
                List <object> rowValue = new List <object>();
                rowValue.Add(tweet.Id);
                rowValue.Add(tweet.Text);
                rowValue.Add(tweet.RetweetCount);
                rowValue.Add(tweet.FavoriteCount);
                rowValue.Add(tweet.Score);
                rowValue.Add(DateTime.UtcNow);
                Upsert(new List <int> {
                    1
                }, rowValue);
            }
            catch (Exception ex)
            {
                Context.Logger.Error("An error occured while executing Tuple Id: {0}. Exception Details:\r\n{1}",
                                     tuple.GetTupleId(), ex.ToString());
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// This is where you business logic around a tweet will go
        /// Here we are emitting the count and the tweet text to next bolt
        /// And also inserting the tweet into SQL Azure
        /// </summary>
        /// <param name="tweet"></param>
        public void ExecuteTweet(SerializableTweet tweet)
        {
            count++;
            Context.Logger.Info("ExecuteTweet: Count = {0}, Tweet = {1}", count, tweet.Text);

            //TODO: You can do something on other tweet fields
            //Like aggreagtions on tweet.Language etc

            //Emit the value to next bolt - SignalR & SQL Azure
            //Ensure that subsequent bolts align with the data fields and types you send
            this.context.Emit(new Values(count, tweet.Text));
        }
Exemplo n.º 3
0
        /// <summary>
        /// This is where you business logic around a tweet will go
        /// Here we are emitting the count and the tweet text to next bolt
        /// And also inserting the tweet into SQL Azure
        /// </summary>
        /// <param name="tweet"></param>
        public void ExecuteTweet(SerializableTweet tweet)
        {
            count++;
            Context.Logger.Info("ExecuteTweet: Count = {0}, Tweet = {1}", count, tweet.Text);

            //TODO: You can do something on other tweet fields
            //Like aggreagtions on tweet.Language etc

            //Emit the value to next bolt - SignalR & SQL Azure
            //Ensure that subsequent bolts align with the data fields and types you send
            this.context.Emit(new Values(count, tweet.Text));
        }
Exemplo n.º 4
0
        public void Execute(SCPTuple tuple)
        {
            var isTickTuple = tuple.GetSourceStreamId().Equals(Constants.SYSTEM_TICK_STREAM_ID);

            if (isTickTuple)
            {
                // Get top 10 higest score tweets from last time window
                Context.Logger.Debug($"Total tweets in window: {tweetCache.Count}");
                var topNTweets = tweetCache.OrderByDescending(o => o.Score).Take(Math.Min(10, tweetCache.Count)).ToList();

                // Emit it to TopNTweet Stream
                foreach (var tweet in topNTweets)
                {
                    //this.context.Emit(StormConstants.TOPNTWEETS_STREAM, new Values(tweet.Text, tweet.Id, tweet.RetweetCount, tweet.FavoriteCount, tweet.UserFollowerCount, tweet.Score));
                    this.context.Emit("TOPNTWEETS_STREAM", new Values(tweet));
                }

                // Remove all existing data and wait for new one
                tweetCache.Clear();
            }
            else
            {
                try
                {
                    // Process tuple and then acknowledge it
                    SerializableTweet tweet = tuple.GetValue(0) as SerializableTweet;

                    if (!tweetCache.Any(o => o.Id.Equals(tweet.Id)))
                    {
                        tweetCache.Add(tweet);
                    }

                    Context.Logger.Info(tweet.ToString());

                    if (enableAck)
                    {
                        this.context.Ack(tuple);
                        Context.Logger.Info("Total Ack: " + ++totalAck);
                    }
                }
                catch (Exception ex)
                {
                    Context.Logger.Error("An error occured while executing Tuple Id: {0}. Exception Details:\r\n{1}",
                                         tuple.GetTupleId(), ex.ToString());

                    //Fail the tuple if enableAck is set to true in TopologyBuilder so that the tuple is replayed.
                    if (enableAck)
                    {
                        this.context.Fail(tuple);
                    }
                }
            }
        }