使用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相关推荐
- 学习Azure Functions:在Visual Studio 2017中创建Azure Functions
目录 介绍 Azure Azure帐户设置 设置开发环境 案例分析 在Visual Studio 2017中创建Azure Functions 添加Azure Functions项目 添加HTTP触发 ...
- 微软云技术Windows Azure专题(一):如何利用Service Bus向Windows商店应用推送消息
本文介绍了如何使用Windows Azure的Service Bus通知中心发送推送通知Windows商店应用程序. 先来明确一下大体上要做哪些步骤: 1.申请一个Windows应用商店的应用.(每个 ...
- azure web应用部署_使用Visual Studio Code将Python应用程序部署到Azure Functions
azure web应用部署 In this article, we are going to build a small python application and deploy it to Azu ...
- 利用Azure Functions和k8s构建Serverless计算平台
题记:昨晚在一个技术社区直播分享了"利用Azure Functions和k8s构建Serverless计算平台"这一话题.整个分享分为4个部分:Serverless概念的介绍.Az ...
- azure服务器_如何使用Azure Functions和SendGrid构建无服务器报表服务器
azure服务器 It's 2018 and I just wrote a title that contains the words "Serverless server". L ...
- Azure Functions + Azure Batch实现MP3音频转码方案
客户需求 客户的环境是一个网络音乐播放系统,根据网络情况提供给手机用户收听各种码率的MP3歌曲,在客户没购买歌曲的情况下提供一个三十秒内的试听版本.这样一个系统非常明确地一个需求就是会定期需要将一批从 ...
- 微软宣布Azure Functions正式支持Java
微软宣布Azure Functions V2.0支持Java.开发人员现在可以用Java 8编写Function,并利用Visual Studio Code.IntelliJ.Eclipse和跨平台F ...
- 使用Azure Functions玩转Serverless
Serverless&Azure Functions 通过无服务器计算,开发者无需管理基础结构,从而可以更快构建应用程序.通过无服务器应用程序,将由云服务提供商自动预配.缩放和管理运行代码所需 ...
- 利用 Azure Functions 实现无服务器体系结构
从工具到机器再到计算机,我们一直在寻找能够自动执行重复工作并让我们所处理的上下文规范化的方法,以便我们可以将重心放在做出高价值的专业化贡献上,从而完成任务并解决问题. 与此同时,很显然,随着 IT 产 ...
最新文章
- ValueError: Bin labels must be one fewer than the number of bin edges
- SqlServer 索引
- 使用 Bochs 调试操作系统
- Java程序员从笨鸟到菜鸟之(一百零四)java操作office和pdf文件(二)利用POI实现数据导出excel报表...
- 使用winform来递归实现资源管理器
- node.js中对 redis 的安装和基本操作
- 自学python买什么教材-最好的Python入门教材是哪本?
- andoid-sdk 安装时出现 Stopping ADB server failed(code -1) 错
- iStack与CSS配置实例
- 图片在mysql中的储存_如何在MySQL中直接储存图片
- python之条件-循环和其他语句
- 离散数学 --- 特殊关系 --- 等价关系与集合的划分
- python花瓣长度和花瓣宽度散点图鸢尾花_鸢尾花
- 国内怎么开通苹果Arcade订阅
- vue-seamless-scroll 无缝滚动 使用方法
- 2014年元旦放假安排,又一个坑爹的假日
- 初级Java学习笔记总结
- 企业架构之道(四)企业架构Zachman方法
- 易语言注册机sign加密解决方法
- 用cxf发布和调用web service
热门文章
- phpMyAdmin 配置
- 导入安全证书到jdk
- sql的case when用法
- hdoj-3342-Legal or Not(拓扑排序)
- Asp.net--DropDownList控件绑定数据库数据
- Java06动手动脑
- 关于C#程序调用AMFPHP服务的问题!!
- 自动化测试框架:没有Surprise的原因
- r语言error in match.fun(fun) :_Go语言200行写区块链源代码分析
- python语言format用法_详解Python中的format格式化函数的使用方法