コード例 #1
0
        public static async void Run(
            [ServiceBusTrigger("newreview", "aggregator", Connection = "topicConnectionString")] string topicMessage,
            ILogger log,
            [Blob("reviewsentiment", FileAccess.Read, Connection = "storageConnectionString")] CloudBlobContainer sentimentBlobContainer,
            [Blob("reviewentity", FileAccess.Read, Connection = "storageConnectionString")] CloudBlobContainer entityBlobContainer,
            [CosmosDB(databaseName: "theatreers", collectionName: "items", ConnectionStringSetting = "cosmosConnectionString")] IAsyncCollector <DecoratedReviewerMessage> reviewOutput
            )
        {
            DecoratedReviewerMessage decoratedMessage = JsonConvert.DeserializeObject <DecoratedReviewerMessage>(topicMessage);
            string         filename      = $"{decoratedMessage.MessageProperties.RequestCorrelationId}.json";
            CloudBlockBlob entityBlob    = entityBlobContainer.GetBlockBlobReference(filename);
            CloudBlockBlob sentimentBlob = sentimentBlobContainer.GetBlockBlobReference(filename);
            int            backoff       = 300;

            IList <EntityRecord> entitiesObject = await findBlob <IList <EntityRecord> >(entityBlob, backoff);

            string sentimentObject = await findBlob <string>(sentimentBlob, backoff);

            decoratedMessage.entities  = entitiesObject;
            decoratedMessage.sentiment = sentimentObject;
            decoratedMessage.doctype   = "review";

            log.LogInformation($"[Request Correlation ID: {decoratedMessage.MessageProperties.RequestCorrelationId}] :: entity downloaded :: {entitiesObject.FirstOrDefault().ToString()}");
            log.LogInformation($"[Request Correlation ID: {decoratedMessage.MessageProperties.RequestCorrelationId}] :: entity downloaded :: {sentimentObject}");

            try
            {
                await reviewOutput.AddAsync(decoratedMessage);

                await entityBlob.DeleteAsync();

                await sentimentBlob.DeleteAsync();

                log.LogInformation($"[Request Correlation ID: {decoratedMessage.MessageProperties.RequestCorrelationId}] :: Upload Complete {reviewOutput.ToString()}");
                log.LogInformation($"[Request Correlation ID: {decoratedMessage.MessageProperties.RequestCorrelationId}] :: Aggregation Clean-up Complete");
            }
            catch (Exception ex)
            {
                log.LogInformation($"[Request Correlation ID: {decoratedMessage.MessageProperties.RequestCorrelationId}] :: Aggregation Clean-up Incomplete :: {ex.Message}");
            }
        }