public static async void ProcessTweet([QueueTrigger(Strings.MarchMadnessQueueName)] MarchMadnessTweet tweet) { try { var indexClient = searchClient.Indexes.GetClient(searchIndex); await indexClient.Documents.IndexAsync(IndexBatch.Create(IndexAction.Create(IndexActionType.MergeOrUpload, tweet))); } catch (IndexBatchException ex) { // Sometimes when your Search service is under load, indexing will fail for some of the documents in // the batch. Depending on your application, you can take compensating actions like delaying and // retrying. For this simple demo, we just log the failed document keys and continue. Console.Error.WriteLine("Index batch exception: " + ex); throw; } catch (Exception ex) { Console.Error.WriteLine("Error processing tweet: " + tweet + ". Exception: " + ex); throw; } }
private static async Task SaveStatus(Status status) { // create a poco from the status var tweet = new MarchMadnessTweet() { TweetId = status.StatusID.ToString(), Source = ExtractSourceNameFromAnchor(status.Source), Text = status.Text, CreatedAt = status.CreatedAt, ScreenName = status.User.ScreenNameResponse, ProfileBackgroundColor = status.User.ProfileBackgroundColor, ProfileImageUrl = status.User.ProfileImageUrl, TimeZone = status.User.TimeZone, Followers = status.User.FollowersCount, Following = status.User.FriendsCount, Retweets = status.RetweetCount, Statuses = status.User.StatusesCount }; // convert to queue message and save var message = new CloudQueueMessage(JsonConvert.SerializeObject(tweet)); await _queue.AddMessageAsync(message); }