函数工作流 FunctionGraph
函数工作流 FunctionGraph
- 最新动态
- 功能总览
- 产品介绍
- 计费说明
- 快速入门
- 用户指南
-
最佳实践
- FunctionGraph最佳实践汇总
-
数据处理类实践
- 使用FunctionGraph函数对OBS中的图片进行压缩
- 使用FunctionGraph函数为OBS中的图片打水印
- 使用FunctionGraph函数对DIS数据进行格式转换并存储到CloudTable
- 使用FunctionGraph函数实现通过API方式上传文件
- 使用FunctionGraph函数对IoTDA中的设备坐标数据进行转换
- 使用FunctionGraph函数对OBS中的文件进行加解密
- 使用FunctionGraph函数识别LTS中的异常业务日志并存储到OBS
- 使用FunctionGraph函数对LTS中的日志进行实时过滤
- 使用FunctionGraph函数流对OBS中的图片进行旋转
- 使用FunctionGraph函数流对图片进行压缩和打水印
- 功能应用类实践
- 函数构建类实践
- 开发指南
- API参考
- SDK参考
- 场景代码示例
-
常见问题
-
产品咨询
- 使用FunctionGraph是否需要开通计算、存储、网络等服务?
- 使用FunctionGraph开发程序之后是否需要部署?
- FunctionGraph为函数分配的磁盘空间有多少?
- 是否支持在函数中启动TCP的监听端口,通过EIP接收外部发送过来的TCP请求?
- 函数发起HTTP请求的源地址如何获取?
- FunctionGraph是否支持对上传的zip文件进行反编译?
- FunctionGraph的函数是否支持功能扩展?
- FunctionGraph中的代码是如何隔离的?
- 函数常规信息中的“应用”如何理解?
- 用户需要为函数的冷启动时间付费吗?
- 函数计费中的调用次数,是某一账号下在不同region的所有函数的调用次数总和吗?
- Python语言的函数从V1版本迁移到V2版本时需注意哪些兼容性问题?
- FunctionGraph函数支持哪些编程语言?
- 创建函数
-
配置函数
- 能否在函数环境变量中存储敏感信息?
- FunctionGraph的函数如何读写上传的文件?
- 为函数挂载文件系统时,报“failed to mount exist system path”
- FunctionGraph如何实现域名解析?
- FunctionGraph如何通过域名访问专享版APIG中注册的接口?
- FunctionGraph函数通过域名访问APIG中注册的接口时,报域名无法解析?
- 使用定制运行时语言的函数能操作哪些目录?
- FunctionGraph的函数支持哪些中文字体?
- 能否在函数代码中使用线程和进程?
- 函数如何访问MySQL数据库?
- 函数无法通过VPC连接对应的Redis?
- 如何读取函数的请求头?
- Python语言的函数中,中文注释报乱码错误
-
调用函数
- FunctionGraph的函数执行需要多长时间?
- FunctionGraph的函数执行包含了哪些过程?
- FunctionGraph函数长时间不执行时,相关的实例会如何处理?
- 如何获取函数运行过程中的内存使用量信息?
- 为什么首次调用函数时速度会比较慢?
- 为什么函数实际使用内存大于预估内存,甚至触发内存溢出OOM?
- 函数执行失败返回“runtime memory limit exceeded”时,如何查看内存占用大小?
- 自定义镜像函数执行失败报“CrashLoopBackOff”
- 同步调用函数时,未收到调用响应的可能原因?
- 函数中os.system("command &")命令的执行日志未采集,应如何处理?
- 函数执行超时的可能原因有哪些?
- 使用APIG触发器调用一个返回String的FunctionGraph函数时,报500错误
- Python2.7在执行reload(sys)后无法通过print打印日志
- 运行函数时报错error while loading shared libraries时如何处理?
- 配置触发器
- 配置依赖包
-
产品咨询
- 视频帮助
- 文档下载
- 通用参考
链接复制成功!
使用NET Core CLI
C#新增json序列化和反序列化接口,并提供HC.Serverless.Function.Common.JsonSerializer.dll 。
提供的接口如下:
T Deserialize<T>(Stream ins):反序列化值传递到Function处理程序的对象中。
Stream Serialize<T>(T value):序列化值传递到返回的响应负载中。
本例以.NET Core2.1创建“test”工程为例说明,.NET Core3.1、C#(.NET Core 6.0,当前仅支持华北-乌兰察布二零二、华北-乌兰察布二零一、拉美-墨西哥城二)方法类似。执行环境已装有.NET SDK2.1。
新建项目
- 创建目录“/tmp/csharp/projects /tmp/csharp/release” ,执行命令如下:
mkdir -p /tmp/csharp/projects;mkdir -p /tmp/csharp/release
- 进入“/tmp/csharp/projects/”目录,执行命令如下:
cd /tmp/csharp/projects/
- 新建工程文件 “test.csproj”,文件内容如下:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp2.1</TargetFramework> <RootNamespace>test</RootNamespace> <AssemblyName>test</AssemblyName> </PropertyGroup> <ItemGroup> <Reference Include="HC.Serverless.Function.Common"> <HintPath>HC.Serverless.Function.Common.dll</HintPath> </Reference> <Reference Include="HC.Serverless.Function.Common.JsonSerializer"> <HintPath> HC.Serverless.Function.Common.JsonSerializer.dll</HintPath> </Reference> </ItemGroup> </Project>
生成代码库
- 下载dll文件并上传。
将HC.Serverless.Function.Common.dll、HC.Serverless.Function.Common.JsonSerializer.dll、Newtonsoft.Json.dll文件上传至目录“/tmp/csharp/projects/”。
- 在“/tmp/csharp/projects/”路径下,新建“Class1.cs”文件,代码内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
using HC.Serverless.Function.Common; using System; using System.IO; namespace test { public class Class1 { public Stream ContextHandlerSerializer(Stream input, IFunctionContext context) { var logger = context.Logger; logger.Logf("CSharp runtime test(v1.0.2)"); JsonSerializer test = new JsonSerializer(); TestJson Testjson = test.Deserialize<TestJson>(input); if (Testjson != null) { logger.Logf("json Deserialize KetTest={0}", Testjson.KetTest); } else { return null; } return test.Serialize<TestJson>(Testjson); } public class TestJson { public string KetTest { get; set; }//定义序列化的类中的属性为KetTest } } }
- 执行以下命令,生成代码库:
/home/tools/dotnetcore-sdk/dotnet-sdk-2.1.302-linux-x64/dotnet build /tmp/csharp/projects/test.csproj -c Release -o /tmp/csharp/release
说明:
dotnet的路径:/home/tools/dotnetcore-sdk/dotnet-sdk-2.1.302-linux-x64/dotnet。
- 执行以下命令,进入“/tmp/csharp/release”路径。
cd /tmp/csharp/release
- 在路径“/tmp/csharp/release”下查看编译生成的dll文件,如下所示:
-rw-r--r-- 1 root root 468480 Jan 21 16:40 Newtonsoft.Json.dll -rw-r--r-- 1 root root 5120 Jan 21 16:40 HC.Serverless.Function.Common.JsonSerializer.dll -rw-r--r-- 1 root root 5120 Jan 21 16:40 HC.Serverless.Function.Common.dll -rw-r--r-- 1 root root 232 Jan 21 17:10 test.pdb -rw-r--r-- 1 root root 3584 Jan 21 17:10 test.dll -rw-r--r-- 1 root root 1659 Jan 21 17:10 test.deps.json
- 在“/tmp/csharp/release”路径下,新建文件“test.runtimeconfig.json”文件,文件内容如下:
{ "runtimeOptions": { "framework": { "name": "Microsoft.NETCore.App", "version": "2.1.0" } } }
说明:
- *.runtimeconfig.json文件的名称为程序集的名称。
- 文件内容中的version:项目属性中的目标框架的版本号,2.0则为2.0.0 ,2.1则为2.1.0。
- 当目标框架为.NET Core2.0时,要注意生成*.deps.json文件中是否已引入Newtonsoft.Json。如果没有引入,则需要自己手动引入,如下所示:
- 需要在“targets”中引入以下内容:
"Newtonsoft.Json/9.0.0.0": { "runtime": { "Newtonsoft.Json.dll": { "assemblyVersion": "9.0.0.0", "fileVersion": "9.0.1.19813" } } }
- 在“libraries”引入以下内容:
"Newtonsoft.Json/9.0.0.0": { "type": "reference", "serviceable": false, "sha512": "" }
- 需要在“targets”中引入以下内容:
- 在“/tmp/csharp/release”路径下,执行如下命令,打包test.zip代码库压缩包。
zip -r test.zip ./*
父主题: 函数支持json序列化和反序列化