Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Azure函数EventGrid触发器_C#_Azure_Azure Functions_Azure Blob Storage_Azure Eventgrid - Fatal编程技术网

C# Azure函数EventGrid触发器

C# Azure函数EventGrid触发器,c#,azure,azure-functions,azure-blob-storage,azure-eventgrid,C#,Azure,Azure Functions,Azure Blob Storage,Azure Eventgrid,我已经实现了一个EventGrid触发器来响应Blob存储事件,其逻辑简化如下: public static async void Run( JObject eventGridEvent, TraceWriter log, ExecutionContext context) { string eventContent = ParseEvent(eventGridEvent); HttpClient client = GetProxyClient();

我已经实现了一个EventGrid触发器来响应Blob存储事件,其逻辑简化如下:

public static async void Run(
    JObject eventGridEvent,
    TraceWriter log,
    ExecutionContext context)
{
    string eventContent = ParseEvent(eventGridEvent);

    HttpClient client = GetProxyClient();
    HttpResponseMessage response = await client.GetAsync("blabla/" + eventContent);
    string responseContent = await response.Content.ReadAsStringAsync();
    log.Info("Here is the response :" + responseContent);
}
外部API响应时间不长(1秒或更短),主机的配置设置为默认值(因此允许无限数量的并发调用)

当同时添加多个blob(从2个blob开始)时,我在日志中得到了很多重复的事件(脚本正在一个接一个地快速上载blob,其间没有等待时间)

我觉得这可能是因为我从未确认接收到事件,我不知道我是否应该在代码中这样做,或者EventGrid触发器是否自动这样做

确认事件处理的逻辑应该在EventGrid触发器(Http 200响应)中实现,还是自动处理

如果不是,我是否仍应获得重复的事件?通常,当上传单个blob时,我会收到它的事件3-4次

我问这个问题的原因是,当使用Http触发器并返回400响应时,我也会得到重复的事件,这是有意义的,因为我没有确认正确处理了事件。但是,当我返回200响应时,我不会收到重复的事件


谢谢

您不需要做任何特殊的事情来向事件网格表示成功。如果函数执行成功(未引发异常),触发器将自动响应成功状态代码。

您可以尝试使用
数据的EventGrid
高级过滤器。
api字符串以FlushWithClose
结尾。blob上载时my Azure函数多次执行的原因是,为blob上载执行的每个
AppendFile
操作都创建了一条EventGrid消息

我发现(通过反复试验)Azure Data Factory使用一系列API调用将单个blob写入blob存储

最后看起来像这样:

  • CreateFilePath
  • LeaseFile
  • AppendFile
  • AppendFile
  • AppendFile
    (每次追加都会放入blob的一块,直到blob完成)
  • FlushFile
    (这是文件已完成的实际指示;因此上面显示了高级过滤器)
  • LeaseFile
下面是一个示例查询,您可以自己查看此上传流:

  • 注意:您需要上传到blob容器的示例文件的
    Uri
//==================================================//
//作者:埃里克
//创建日期:2021-05-260900
//查询:ADF到Blob存储参考流
//目的:
//为Blob存储提供ADF的参考流
//文件上传
//==================================================//
//分配变量
//==================================================//
让varStart=ago(10d);
设varEnd=now();
让varStorageAccount='';
让varStatus=‘成功’;
让varSampleUrihttps://.dfs.core.windows.net//%2F%2F'
//==================================================//
//过滤表
//==================================================//
StorageBlog
|其中TimeGenerated介于(varStart..varEnd)之间
和AccountName==varStorageAccount
和StatusText==varStatus
和split(Uri,“?”)[0]==varSampleUri
//==================================================//
//分组和分析结果
//==================================================//
|总结
按OperationName计数(),
关联ID,
时间生成,
UserAgent=tostring(拆分(UserAgentHeader),[0]),
请求者应用程序ID,
帐户名,
ContainerName=tostring(拆分(tostring(解析url(url解码(Uri))['Path'],'/')[1]),
FileName=tostring(拆分(tostring(解析url(url解码(Uri))['Path']),'/')[-1]),
ChunkSize=格式化字节(RequestBodySize,2,'MB'),
状态码,
状态文本
|按时间生成的订单asc
上传来自不同来源(Azure数据工厂、Azure存储资源管理器、Python/C#SDK、Azure门户等)的示例并查看它们使用的不同API方法非常有趣。事实上,您可能需要执行此操作才能拨入日志和警报

遗憾的是,这些方法没有跨工具标准化,因为这个特殊问题是一个很难自己发现的问题


同样,在这种情况下,EventGrid
高级过滤器是您的朋友。

我也看到Azure函数事件网格触发器存在同样的问题。单个blob插入会触发Azure函数3-4次。我们有什么最新消息吗?我看到了完全相同的行为。对于运行时间较长的函数,我们如何解决此问题?请澄清,如果我的函数需要3分钟才能执行,但EventGrid重试策略设置为30秒,EventGrid将继续重试,直到函数完成,是否正确?是否有方法在代码前面确认EventGrid消息以防止这种重试行为?这是正确的。我认为您不能更早地确认,因此您应该保持您的函数简短(例如,将繁重的工作转移到基于队列的函数)。有没有办法将EventGrid重试时间调整为等待?奇怪的是,在我的DEV函数中根本没有出现这种行为。仅产品。两者都在移动大文件/运行相同的持续时间。
//==================================================//
// Author: Eric
// Created: 2021-05-26 0900 
// Query: ADF-to-Blob Storage reference flow
// Purpose: 
// To provide a reference flow of ADF-to-Blob Storage
// file uploads
//==================================================//
// Assign variables
//==================================================//
let varStart = ago(10d);
let varEnd = now();
let varStorageAccount = '<storageaccountname>';
let varStatus = 'Success';
let varSampleUri = 'https://<storageaccountname>.dfs.core.windows.net/<containername>/<parentfolder1>%2F<parentfolder2>%2F<samplefilename.extension>'
//==================================================//
// Filter table
//==================================================//
StorageBlobLogs
| where TimeGenerated between (varStart .. varEnd)
  and AccountName == varStorageAccount
  and StatusText == varStatus
  and split(Uri, '?')[0] == varSampleUri
//==================================================//
// Group and parse results
//==================================================//
| summarize 
  count() by OperationName,
  CorrelationId,
  TimeGenerated,
  UserAgent = tostring(split(UserAgentHeader, ' ')[0]),
  RequesterAppId,
  AccountName, 
  ContainerName = tostring(split(tostring(parse_url(url_decode(Uri))['Path']), '/')[1]),
  FileName = tostring(split(tostring(parse_url(url_decode(Uri))['Path']), '/')[-1]),
  ChunkSize = format_bytes(RequestBodySize, 2, 'MB'),
  StatusCode,
  StatusText
| order by TimeGenerated asc