英文:
Can Azure Event Grid run a logic before responding back to its callers?
问题
Azure事件网格能在向调用方返回响应之前运行逻辑吗?
寻找类似于Web API管道中的委托者的解决方案。
例如,我们在某处有一个标志(在app.config或keyvault中),然后事件网格查看该标志,并根据标志发送其响应。
标志可能是 'on' 或 '审计模式' 或 '已关闭'
当标志为 'on' 时,事件网格返回200 ok,
当 '审计模式' 时返回不同的HTTP状态码
或者当 '已关闭' 时返回404
我的问题不是关于状态码,而是事件网格能否在向调用方同步返回响应之前运行逻辑。
非常感谢
调查了Azure文档但找不到解决方案。
英文:
Can Azure Event Grid run a logic before it returns a response back to its callers?
Looking for something similar to the delegator in the web.api pipeline.
For example, we have a flag somewhere (in app.config or keyvault), and then Event Grid looks at the flag and send its response back based on the flag.
The flag might be 'on' or 'Audit mode' or 'turned off'
when the flag is on, Event grid returns 200 ok,
When 'audit mode' return a different http status code
Or when 'turned off' returns 404
My question is not about the status code but if Event grid can run a logic before it returns a response back to the caller synchronously.
Thank you so much
Investigated Azure documentation but couldn't find a solution.
答案1
得分: 0
正如 @Skin 和 @Roman Kiss 在评论中提到的,事件网格不提供此功能。相反,您应该设置一个可以执行您的自定义逻辑,然后根据需要将事件转发到事件网格的 API。
由于您的逻辑很简单,您有几个选项
1. 使用 APIM 策略
这将是最简单的方法,特别是如果您已经在某个地方使用了 APIM,如果您的自定义逻辑没有变得更加复杂,那么这应该足够了。
2. 使用 Azure Function
这只是充当代理的方式,运行您的自定义逻辑,然后将请求转发给事件网格。
3. 包含在您的 Web API 中
如果可能的话,您可以将这个功能直接添加到您的 Web API 中,让所有调用者直接调用您自己的端点,而不是直接调用事件网格。
英文:
As @Skin and @Roman Kiss mentioned in the comments, Event Grid does not provide such a functionality. You should instead set up an API that can perform your custom logic and then forward the event to Event Grid as required.
You have a couple of options here since your logic is simple
1. Use APIM Polices
This would be the simplest, especially if you already are using APIM somewhere, and if your custom logic doesn't get any more complex than that, this should do.
2. Use an Azure Function
This would simply serve as a proxy of sorts that runs your custom logic before forwarding the request to Event Grid.
3. Include in your Web API
If possible, you could simply just add this right into your Web API and have all callers just call your own endpoint instead of Event Grid directly.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论