日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用VS code 创建 Azure Functions,从blob触发,解析,发送至Service Bus

發布時間:2023/12/10 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用VS code 创建 Azure Functions,从blob触发,解析,发送至Service Bus 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

場景:

某設備定時于每天23:00左右將一天的運行日志.devicelogtxt上傳到Azure Blob,期待Blob文件上傳后, 自動通過Azure Functions 解析文件并將文件內容寫入到服務總線Service Bus的隊列中。

?

?

上傳的文件格式為:

?

步驟:

  • 下載并安裝VS Code;

  • 下載VS Code 擴展:Azure Account/Funxtions/Nuget;

  • 將VS Code Azure 調整成Azure-China;

  • 在VS Code上登錄Azure China賬號;

  • 下載安裝Azure Functions Core Tools以便進行本地調試;

  • 在Azrue Portal上準備Functions/Blob/Service Bus 環境;

  • ?在VS Code創建Functions;

  • 在本地調試Functions;

  • 使用VS Code直接發布Functions;

  • ?

    本實戰的完整視頻:

    ?

    ??https://v.qq.com/x/page/m3037qoso1i.html

    ?

    需要安裝的三個擴展:

    Azure Account

    ?

    Azure Functions

    ?

    NuGet Package Manager

    ?

    在VS Code中創建Functions步驟:

    ?

    選擇一個文件夾

    ?

    選擇C#語言

    ?

    選擇一個Blob觸發器

    ?

    Function 名稱,可以保持默認

    ?

    命名空間名稱,可以保持默認

    ?

    創建新的本地配置文件

    ?

    選擇創建好的storage 賬戶

    ?

    填寫要監控的容器

    ?

    選擇 存儲賬戶

    ?

    在當前窗口打開項目

    ?

    ?

    ?

    ?

    ?

    本案例中的示例代碼:

    using System; using System.IO; using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs.Host; using Microsoft.Extensions.Logging; using Microsoft.Azure.ServiceBus; using System.Text; using Newtonsoft.Json; ? namespace Company.Function {public static class BlobTriggerCSharp{[FunctionName("BlobTriggerCSharp")]public static void Run([BlobTrigger("samples-workitems/{name}", Connection = "beifustoratgetest_STORAGE")]Stream myBlob, string name, ILogger log){log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes"); ?StreamReader reader = new StreamReader(myBlob);string msg=string.Empty;while(!string.IsNullOrEmpty(msg=reader.ReadLine())){SendMsgToSbQueueAsync(new Msg(){dateTime=DateTime.Now,Msgstr=msg,DeviceId="001"});log.LogInformation($"oldContent:{msg}");} ? ?} ? ? ?public static async void SendMsgToSbQueueAsync(Msg msg){string ServiceBusConnectionString = "Endpoint=sb://seanyutest.servicebus.chinacloudapi.cn/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=rnVwTNyXWRDhi1scJ2ukW7al/5q0Y8sNY2H01dqSl3k=";string QueueName = "test";IQueueClient queueClient = new QueueClient(ServiceBusConnectionString, QueueName); ? ?string messageBody = JsonConvert.SerializeObject(msg);var message = new Message(Encoding.UTF8.GetBytes(messageBody)); await queueClient.SendAsync(message);} ? ?public class Msg{public DateTime dateTime{get;set;}public string Msgstr{get;set;} ?public string DeviceId{get;set;}}} }

    ?

    ?

    ?

    ?

    ?

    從本地發布到Azure

    Ctrl+shift+P

    ?

    將鏈接字符串配置到云端的Functions:

    其中名稱要與local.settings.json中保持一致:

    ?

    微軟Azure IoT, AI,Cloud 產品實戰視頻,請關注作者公眾號:

    總結

    以上是生活随笔為你收集整理的使用VS code 创建 Azure Functions,从blob触发,解析,发送至Service Bus的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。