12345678910111213141516171819202122232425262728293031323334353637383940 |
- using System;
- using System.Collections.Generic;
- using System.Text.Json;
- using System.Threading.Tasks;
- using Azure.Cosmos;
- using Microsoft.Azure.WebJobs;
- using Microsoft.Azure.WebJobs.Host;
- using Microsoft.Extensions.Logging;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK.Extension;
- namespace TEAMModelFunction
- {
- public class ServiceBusTopic
- {
- private readonly AzureCosmosFactory _azureCosmos;
- public ServiceBusTopic( AzureCosmosFactory azureCosmos)
- {
- _azureCosmos = azureCosmos;
- }
- [FunctionName("ServiceBusTopic")]
- public async Task Run([ServiceBusTrigger("test_topic_ActiveTask", "test_topic_ReciveTask", Connection = "ConnectionBusName")]string mySbMsg, ILogger log)
- {
- log.LogInformation($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
- var client = _azureCosmos.GetCosmosClient();
- List<object> classes = new List<object>();
- await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(queryText: $"select value(c) from c",requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Exam-hbcn") }))
- {
- using var json = await JsonDocument.ParseAsync(item.ContentStream);
- if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
- {
- foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
- {
- classes.Add(obj.ToObject<object>());
- }
- }
- }
- }
- }
- }
|