在最新的Microsoft.Azure.WebJobs.ServiceBus 包中,它使您能够从 eventhub接收批量消息。我想设置批量接收多少条消息。
核心 ServiceBus 库允许您重载函数Receive()并提供批量大小。
如何在EventHubs 接收器的初始配置中执行此操作,或者还需要其他操作?
我的 Azure Functions 需要功能密钥才能访问(不,这不会分发给客户端)。在我的测试中,如果我不提供密钥,我会收到 401:未授权(好)。Azure 是否会在请求到达我的函数之前就停止该请求?那么这是否意味着,如果有人尝试在没有密钥的情况下向我的函数 URL 发送垃圾邮件,我不会承担与“需求”突然激增相关的任何使用成本?我的想法是肯定的,但我想知道我是否错了,因为那样我需要在投入生产之前研究另一个解决方案。
我试图从 Azure Function 返回一个 JSON 对象,我的意思是,通过context.res执行响应创建根本不起作用的示例。
context.res = {
body: {"name": "JSON STATHAM"}, //No. No mistake.
contentType: 'application/json'
};
Run Code Online (Sandbox Code Playgroud)
为什么?
只有通过context.done作为第二个参数传递时它才起作用。
我有一个 Azure 函数(基于新的 C# 函数而不是旧的 .csx 函数),每当消息进入 Azure 服务总线队列时就会触发该函数。一旦该函数被触发,它就开始处理服务总线消息。它对消息进行解码、读取大量数据库、更新大量其他数据库等等……这有时可能需要 30 分钟以上。
由于这不是一个时间敏感的过程,30 分钟甚至 60 分钟都不是问题。问题是,与此同时,Azure Function 似乎再次启动并一次又一次地获取相同的消息并重新处理它。这是一个问题,会导致我们的业务逻辑出现问题。
那么,问题来了,我们能否强制Azure函数以单例模式运行呢?或者如果这是不可能的,我们如何更改轮询间隔?
在我的 V3 函数项目中,我试图连接实体框架并从环境变量传递连接字符串。
在我的 local.settings.json 文件中,我有:
{
"Values" : {
"SqlConnectionString" : "<localdb connection string here>"
}
}
Run Code Online (Sandbox Code Playgroud)
我按照这篇博文使用 IDesignTimeContextFactory 连接上下文:
public class ContextFactory : IDesignTimeDbContextFactory<Context>
{
public Context CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder<Context>();
var connectionString = Environment.GetEnvironmentVariable("SqlConnectionString", EnvironmentVariableTarget.Process);
optionsBuilder.UseSqlServer(connectionString);
return new Context(optionsBuilder.Options);
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试添加迁移时connectionString为空。
任何人都可以看到这里有什么问题吗?
编辑:
按照建议,我还尝试定义连接字符串并像这样注入 IConfiguration:
public class ContextFactory : IDesignTimeDbContextFactory<Context>
{
private readonly IConfiguration _configuration;
public ContextFactory(IConfiguration configuration)
{
_configuration = configuration;
}
public Context CreateDbContext(string[] args)
{ …Run Code Online (Sandbox Code Playgroud) 我试图设置简单的 Azure 函数来读取 XML 流并将其同步回数据库。我的计划是使用时间触发器每天执行一次该功能。
然而,事情看起来并不好。即使我不使用数据库,我也会收到以下错误:
[Error] Executed 'Functions.<func-name>' (Failed, Id=<func-id>, Duration=1ms)Value cannot be null. (Parameter 'connectionString')
Run Code Online (Sandbox Code Playgroud)
我目前正在尝试执行以下功能:
module.exports = async function(context, req) {
context.res = {
body: "Success!"
};
};
Run Code Online (Sandbox Code Playgroud)
结果一样。我不能运行它。
我已将连接字符串添加到配置 -> 连接字符串(根据消息,我以为我错过了)。
我的functions.json文件看起来像:
{
"bindings": [
{
"name": "myTimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 0 * * * *"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我也试过运行 C# 函数 - 结果相同。
那么,我错过了什么?
我正在本地构建 .NET Core 3.1 Azure Functions 应用程序,并尝试配置启动类。当我实现一个要继承的类时,FunctionsStartup我无法将 .net core 3.1 类库导入到我的项目中。如果我这样做并尝试运行该应用程序,我会在执行窗口中收到以下错误:
Microsoft.Azure.Functions.Extensions: Method not found: Microsoft.Extensions.Configuration.IConfigurationBuilder Microsoft.Azure.WebJobs.Hosting.IWebJobsConfigurationBuilder.get_ConfigurationBuilder()'. Value cannot be null. (Parameter 'provider')
当我将 Startup 基类切换到IWebJobsStartup应用程序时,启动正常。当我提出请求并尝试单步执行代码时,我遇到了问题。我可以单步执行代码的初始部分(所以我知道我的请求已成功接收),但我无法单步执行我的其中一个功能。我收到一个下载提示,并在 VS 工作区中打开一个页面,其中包含TaskMethodInvker.cs not found带有标记行的错误消息You need to find TaskMethodInvoker.cs to view the source for the current call stack frame。下面的代码显示了我的功能:
[FunctionName("HttpAuth")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ExecutionContext context,
ILogger log)
{
GetAzureADConfiguration(context);
var jwt = GetJwtFromHeader(req);
}
private JwtSecurityToken GetSecurityToken(string encodedToken) …Run Code Online (Sandbox Code Playgroud) azure visual-studio azure-functions azure-functions-runtime azure-functions-core-tools
较旧的 Azure 函数可以访问HttpRequest,这允许我们通过req.Form.Files等访问上传的文件。
HttpRequestData而是使用隔离的 .NET5 Azure 函数,它不提供对Form. 如何提取发布到该功能的上传文件?
我正在将一些功能从 netcore 3.1 迁移到 net5,以使用隔离模型。但是,我遇到了这种我尚未解决的不兼容问题;文档并没有让我找到解决方案。这是关于使用 Azure 函数在存储表中放置一行,此代码片段完美运行:
// netcoreapp3.1, works OK
[FunctionName("PlaceOrder")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post")]
OrderPlacement orderPlacement,
[Table("Orders")] IAsyncCollector<Order> orders)
{
await orders.AddAsync(new Order {
PartitionKey = "US",
RowKey = Guid.NewGuid().ToString(),
CustomerName = orderPlacement.CustomerName,
Product = orderPlacement.Product
});
return new OkResult();
}
Run Code Online (Sandbox Code Playgroud)
在 net5 中执行此操作的尝试与以下内容非常相似:
// net5.0 approach
[Function("PlaceOrder")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post")]
HttpRequestData req,
[Table("Orders")] IAsyncCollector<Order> orders)
{
var orderPlacement = await req.ReadFromJsonAsync<OrderPlacement>();
await orders.AddAsync(new Order {
PartitionKey = "US", …Run Code Online (Sandbox Code Playgroud) azure-functions ×10
azure ×7
c# ×6
javascript ×2
.net ×1
.net-5 ×1
.net-core ×1
node.js ×1
singleton ×1