触发后,生成3个XML文件,一旦完成,将其ftp到站点.
我有一个HTTP Trigger Azure功能,在运行时将构造3个XML文件并将它们保存到Azure存储Blob容器中.由于多个输出,以及需要控制输出路径/文件名,我使用
命令式绑定方法并使用IBinder outputBinder
我的函数.这一切都很好.blob存储中输出路径的一个示例是export/2017-03-22/file-2017-03-22T12.03.02.54.xml
.该文件位于包含日期的文件夹中,每个文件名都有时间戳以确保唯一性.
当生成所有3个文件时,我想触发另一个将这些文件sFTP到站点的功能.现在我最初认为我应该使用blob触发器,但我无法想象如何触发其文件名和路径是动态的输入.我不能在blob触发器文档中找到这样的例子.
那么我想我可以将HTTP触发器输出到声明性绑定,并将XML文件输出到outgoing
我的blob触发器中可以查看的blob存储器中的容器中.这也有效,因为我的功能是消费计划,处理新blob可能有最多10分钟的一天.
因此,记录的备选方案是使用队列触发器.我可以输出到我的队列并让队列触发器正常,但是我如何将3个XML流传递给我的QueueTrigger函数?
我想作为后退,我可以发布一个可以包含构建的XML的Azure存储路径的对象,然后使用存储SDK获取流并使用它发布到FTP,但是它也会更高效将那些Storage Blob流作为输入传递给我的QueueTrigger?
我正在尝试创建一个Azure函数,我在其中使用AutoMapper的一些代码.我是C#,Azure和AutoMapper的新手,我在找到初始化AutoMapper配置的正确方法时遇到了一些麻烦.
MapInitializer.cs:
public static class MapInitializer
{
public static void Activate()
{
Mapper.Initialize(cfg =>
{
// initialize mappings here
});
}
}
Run Code Online (Sandbox Code Playgroud)
然后在我的函数中,我尝试执行以下操作:
Function.cs:
public static class ProcessQueueForIntercom
{
[FunctionName("ProcessQueue")]
public static void Run([QueueTrigger("messages")]string myQueueItem, TraceWriter log)
{
MapInitializer.Activate();
// rest of the code
}
}
Run Code Online (Sandbox Code Playgroud)
现在问题是,我第一次使用此函数处理消息时,一切顺利,代码按预期运行.但是,从第二次开始,我收到一条错误,说我的配置已经初始化.但我真的不知道如何使用Azure函数正确地执行此操作,因为通常您会在App Startup中初始化它,但我不认为Azure Functions(CMIW)有这样的东西,并且我找不到有关如何做到这一点的更多信息.我正在考虑用try catch围绕Activate()调用,并且只记录配置已经加载的警告,但这看起来不是很干净......
我正在构建一个 HTTPTriggered Azure 函数,目标是运行 GraphQL .NET 服务器的 netcoreapp3.0。GraphQL .NET 要求将AllowSynchronousIO
其设置为true
,但我不知道如何为 Azure 函数执行此操作。我尝试实现我自己的Startup
类,该类扩展FunctionsStartup
并在Configure
方法中添加了以下代码,但没有成功。
builder.Services
.AddOptions<KestrelServerOptions>()
.Configure<IConfiguration>((settings, configuration) =>
{
settings.AllowSynchronousIO = true;
configuration.Bind(settings);
});
Run Code Online (Sandbox Code Playgroud)
我得到的错误信息是:
发生了未处理的主机错误。
Microsoft.AspNetCore.Server.Kestrel.Core:不允许同步操作。调用 WriteAsync 或将 AllowSynchronousIO 设置为 true。
任何帮助将不胜感激!
我已经在全新的笔记本电脑上安装了 Visual Studio 2019 社区版本 16.4.4
操作系统:- Windows 10 家庭版单一语言
命令 dotnet --info 给了我以下详细信息
我用 V3 模板创建了一个 Azure 函数
项目设置如下
当我尝试调试时,出现以下错误
发生了致命错误,需要终止调试。调试器被配置为使用桌面 CLR (.NETFramework) 托管调试器,但目标进程加载了 CoreCLR (.Net Core) 运行时。要调试此项目,请将其配置为使用“托管 (CoreCLR)”调试器。”
我们正在使用 Azure 函数通过 Azure NotificationHubClient 发送推送通知。这个函数在实时环境的高峰时间被调用很多,因此我们从 NotificationHubClient.SendNotificationAsync() 方法中抛出了很多 SocketExceptions。
异常详情:
Microsoft.Azure.NotificationHubs.Messaging.MessagingException: Unexpected exception encountered TimeStamp:2020-03-27T04:14:35.4655705Z ---> System.Net.Http.HttpRequestException: Cannot assign requested address ---> System.Net.Sockets.SocketException: Cannot assign requested address
at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask`1 creationTask)
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.DiagnosticsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) …
Run Code Online (Sandbox Code Playgroud) 我正在通过 VS 发布窗口向我的 Function 应用程序部署更新。我设置了一个启用自动交换的部署槽。我通过 VS 的更新将进入插槽。问题是,在发布成功之后,当我测试我的 API 端点时,我短暂地收到了 503 错误。我的印象是自动交换是无缝的,最终用户不会遇到这种中断。我错过了什么吗?如何让我的部署不被用户注意到?
我正在运行一个 python azure 函数,它通过nbconvert
API运行一个 jupyter 笔记本。这已经工作了一段时间,尽管没有部署新代码我开始收到以下错误:
在以下路径中找不到名为“lab”的模板子目录:\n\t/home/.local/share/jupyter\n\t/usr/local/share/jupyter\n\t/usr/share/ jupyter
我用来实现这一目标的代码是:
from nbconvert.preprocessors import ExecutePreprocessor
from nbconvert import HTMLExporter
...
dl = DictLoader({'footer':
"""
{%- extends 'full.tpl' -%}
{% block input_group %}
{%- if cell.metadata.get('nbconvert', {}).get('show_code', False) -%}
((( super() )))
{%- endif -%}
{% endblock input_group %}
{% block output_group %}
<style> .output_prompt{visibility:hidden;}</style>
{{ super() }}
{% endblock output_group %}
"""})
...
html_exporter = HTMLExporter(extra_loaders=[dl], template_file='footer')
html_exporter.template_name = 'classic'
with open(JUPYTER_DIR + NOTEBOOK_NAME) as f:
nb = nbformat.read(f, as_version=4) …
Run Code Online (Sandbox Code Playgroud) 在我的 azure 函数应用项目中,我收到一个程序集未找到运行时错误 Microsoft.Extensions.DependencyInjection.Abstractions, Version=5.0.0.0。但是,该程序集包含在我从 NuGet 安装的多个包中。
Visual Studio:2019 目标框架:netcoreapp3.1 Azure Functions 版本:v3
包含 Microsoft.Extensions.DependencyInjection.Abstractions (5.0.0) 的已安装包:
错误: 启动操作期间发生主机错误...无法加载文件或程序集“Microsoft.Extensions.DependencyInjection.Abstractions,Version=5.0.0.0,Culture=neutral,PublicKeyToken=adb9793829ddae60”。该系统找不到指定的文件。
无效的修复尝试: 从 NuGet 安装了 Microsoft.Extensions.DependencyInjection.Abstractions (5.0.0),但错误仍然存在。
在类似的问题Microsoft.Extensions #2931和StackOverflow question 之后,我在项目文件中添加了以下内容。
<PropertyGroup> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType> </PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
我也跟着一篇文章的建议。安装 Microsoft.Azure.Functions.Extensions 后,错误仍然存在。
我还遵循了另一个建议,并将以下内容添加到我的项目文件中。但是,错误仍然存在。
<runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions"
publicKeyToken="adb9793829ddae60" culture="neutral" /> <bindingRedirect oldVersion="5.0.0.0"
newVersion="5.0.0" /> </dependentAssembly> </assemblyBinding> </runtime>
Run Code Online (Sandbox Code Playgroud)
我尝试了ASP.NET Core 公告的问题#401 中建议的解决方法:引用未能在我的应用程序中显式加载的程序集的包。但是,错误仍然存在。
使用 ILSpy,我发现我从 NuGet 安装的 Microsoft.Azure.Functions.Extensions …
我正在尝试使用 SpecFlow 和 MSTest 测试(集成测试)我的 Azure Durable Function v3。
函数用 DI 和 Startup 类初始化:
[assembly: FunctionsStartup(typeof(Startup))]
namespace MyNamespace.Functions
{
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
ConfigureServices(builder.Services);
}
...
Run Code Online (Sandbox Code Playgroud)
Orchestrator 入口点由 HTTP 端点触发:
public class Function1
{
[FunctionName(nameof(Function1))]
public async Task<IActionResult> DoYourJob(
[HttpTrigger(AuthorizationLevel.Anonymous, methods: "post", Route = "api/routes/function1")] HttpRequestMessage httpRequest,
[DurableClient] IDurableOrchestrationClient starter)
{
...
Run Code Online (Sandbox Code Playgroud)
我的 IntegrationTest 构造函数初始化 Az 函数HostBuilder
(感谢这篇文章):
[Binding]
public sealed class Function1StepDefinitions
{
private readonly IHost _host;
private …
Run Code Online (Sandbox Code Playgroud) integration-testing azure .net-core azure-functions azure-durable-functions
将我的 Azure Functions 项目迁移到 .NET 5 后,它开始将我的响应包装在一个奇怪的包装类中。
例如,考虑以下端点:
public record Response(string SomeValue);
[Function("Get")]
public async Task<IActionResult> Get(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "get-something")]
HttpRequestData request)
{
return new OkObjectResult(new Response("hello world"));
}
Run Code Online (Sandbox Code Playgroud)
之前,它会返回:
{
"someValue": "hello world"
}
Run Code Online (Sandbox Code Playgroud)
但现在,它返回:
{
"Value": {
"SomeValue": "hello world"
},
"Formatters": [],
"ContentTypes": [],
"DeclaredType": null,
"StatusCode": 200
}
Run Code Online (Sandbox Code Playgroud)
我知道这一定是因为它只是尝试序列化对象结果,但我找不到任何关于它在 .NET 5 中应该如何工作的文档。
我的主要功能目前看起来像这样:
public static async Task Main()
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults(x =>
x.UseDefaultWorkerMiddleware())
.ConfigureAppConfiguration((_, builder) => builder
.AddJsonFile("local.settings.json", true)
.Build()) …
Run Code Online (Sandbox Code Playgroud) azure-functions ×10
azure ×6
.net-core ×4
c# ×4
asp.net-core ×1
automapper ×1
azure-hub ×1
debugging ×1
jupyter ×1
nbconvert ×1
python ×1