c# - 具有变量名称、QueueTriggerAttribute 限制的 Azure Functions QueueTrigger
问题描述
假设以下典型的队列触发函数:
public void Run([QueueTrigger("queue1")]object data, ILogger log)
{
// Do something with data
}
我的问题是它"queue1"
必须是一个常量字段,所以它必须在编译时定义。另外,我想要一个队列触发器的基类,它可以像这样工作:
public abstract class QueueBase<TModel>
{
public void Run([QueueTrigger("queueName")]TModel data, ILogger log)
{
// Do something with data, log something etc.
OnRunExecuted(data);
// Do something with data, log something etc.
}
public abstract void OnRunExecuted(TModel data);
}
有了这个,我可以编写自己的类,这些类继承自QueueBase
但甚至可以存在于没有Microsoft.Azure.WebJobs
依赖关系的库中:
public class MyQueueHandler : QueueBase<MyModel>
{
public void OnRunExecuted(MyModel data) => ...;
}
但是不可能传入队列名称......是吗?
解决方案
我记得属性QueueTrigger只接受 const 字符串,所以你可以尝试使用环境变量来做一些技巧,比如 post how to pass dynamic queue name
推荐阅读
- java - 当服务器启动时,如何只创建一次会话?
- python - 如何在javascript文件中执行scrapy python?
- javascript - 如何在 AJAX 请求中忽略/避免“自签名证书错误”?
- c# - C# 检查字符串长度是否为 188,如果不是
- docker - 挂载卷 .NET Core Docker
- javascript - 如何添加和删除
- c++ - ASAN 显示 heap-use-after-free 而 boost::asio 在套接字上调用纯 recv
- spring-boot - 如何启用 IP 查找 - Spring MVC 中的 enableLookups
- uwp - Prism 7 UWP 导航返回参数丢失
- c# - 获得系列中每个角色的最高价值