Ejemplo 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());
            }
        }
Ejemplo n.º 2
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);
                    }
                }
            }
        }