More interested in the public numbers: to learn cloud computing
Scenes:
The scheduled around 23:00 a day to day running log .devicelogtxt uploaded to Azure Blob, looking after the Blob file upload, automatically written to the Service Bus Service Bus by Azure Functions parse the file and the contents of the file in the queue.
Upload file format:
step:
-
Download and install the VS Code;
-
Extended download VS Code: Azure Account / Funxtions / Nuget;
-
Adjusted to the VS Code Azure Azure-China;
-
Log Azure China accounts on the VS Code;
-
Download and install Azure Functions Core Tools for local debugging;
-
Preparation Functions / Blob / Service Bus environment on Azrue Portal;
-
Functions created in VS Code;
-
Debugging Functions locally;
-
Use VS Code immediate release Functions;
Full video of this combat:
https://v.qq.com/x/page/m3037qoso1i.html
We need to install three extensions:
Azure Account
Azure Functions
NuGet Package Manager
Functions created in step VS Code:
Select a folder
Select the C # language
Select a trigger Blob
Function names, you can keep the default
Namespace name, you can keep the default
Create a new local profile
Select Create a good storage account
Fill the container to be monitored
Select the storage account
Open the project in the current window
The sample code in this case:
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中保持一致: