- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发微服务(使用 Azure Function Apps),其中包含基于 ServiceBusTrigger
的 Azure Functions,当消息插入服务总线队列时会触发服务总线队列。
我正在尝试确定将输出值绑定(bind)到多个目标(例如 CosmosDB 和 IoT 中心)的最佳方式。该方法是否被标记为异步将决定我应该如何解决这个问题。
据我所知,通常使用异步函数处理输出绑定(bind)的方式是使用 [return: ...]
注释;但是,在我的用例中,我需要将两个不同的值返回到两个单独的目标(例如 CosmosDb 和 IoT 中心)。我不认为这是我可以通过返回值绑定(bind)或输出变量绑定(bind)实现的目标,因为您不能使用异步方法使用 out
参数,并且可以使用以下方法定义多个返回值[return: ...]
方法。
我唯一的选择(如果我采用异步路线)似乎是手动调用 Azure Function 中的 SDK 方法来调用独立于任何输出值的服务。我试图避免这样做,因为输出绑定(bind)是首选方法。
我在创建基于 ServiceBusTrigger
的全新 Azure Function 时观察到,生成的方法签名未标记为 async
默认情况下。
这与 HttpTrigger
不同,后者标记为开箱即用的async
。
有人可以帮我理解其中的原因吗?其中一种与另一种相关的扩展影响是什么?
我从传统意义上理解为什么通常将 HttpTrigger
标记为异步;但是,我不明白为什么 ServiceBusTrigger
不是异步的
我需要先理解这一点,然后才能继续巩固我的输出方法。
最佳答案
我不认为带有/不带有async
函数的模板有任何理由。根据您的代码,您的函数可能会更有效。
阅读 this thread有关函数中async/await
的更多详细信息。
至于您的主要问题,您只需为 CosmosDB 和 IoT 中心输出绑定(bind)绑定(bind)到不同的对象。
IAsyncCollector
相反,如文档中所示using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
namespace CosmosDBSamplesV2
{
public static class WriteDocsIAsyncCollector
{
[FunctionName("WriteDocsIAsyncCollector")]
public static async Task Run(
[QueueTrigger("todoqueueforwritemulti")] ToDoItem[] toDoItemsIn,
[CosmosDB(
databaseName: "ToDoItems",
collectionName: "Items",
ConnectionStringSetting = "CosmosDBConnection")]
IAsyncCollector<ToDoItem> toDoItemsOut,
ILogger log)
{
log.LogInformation($"C# Queue trigger function processed {toDoItemsIn?.Length} items");
foreach (ToDoItem toDoItem in toDoItemsIn)
{
log.LogInformation($"Description={toDoItem.Description}");
await toDoItemsOut.AddAsync(toDoItem);
}
}
}
}
IAsyncCollector
相反,如文档中所示[FunctionName("EH2EH")]
public static async Task Run(
[EventHubTrigger("source", Connection = "EventHubConnectionAppSetting")] EventData[] events,
[EventHub("dest", Connection = "EventHubConnectionAppSetting")]IAsyncCollector<string> outputEvents,
ILogger log)
{
foreach (EventData eventData in events)
{
// do some processing:
var myProcessedEvent = DoSomething(eventData);
// then send the message
await outputEvents.AddAsync(JsonConvert.SerializeObject(myProcessedEvent));
}
}
关于c# - 异步 ServiceBusTrigger 的优点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56012456/
下面我有一段代码可以在我的大多数简单程序中运行.. . 我想知道它是好是坏……以及利弊。 . win32头文件:win32.h // example of a not realated code to
了解到我们可以使用双括号初始化在 java 中初始化集合。并对其进行了一些搜索,发现由于其性能问题,不建议使用它。 private static final Set VALID_CODES = new
在 Java 中使枚举类似于类,而不是像 C/C++ 中的常量集合,有哪些优点? 最佳答案 您可以免费在编译时检查有效值。使用 public static int OPTION_ONE = 0; pu
我目前正在研究ruleML,我想知道是否有人可以给我列出一些优缺点? 谢谢 最佳答案 RuleML是语义网现有本体语言和查询系统的概括,例如OWL-DL,围绕RDF的工具集以及基于一阶逻辑的类似于Pr
每次我写某种形式的东西 let scorePopulation f population = Array.map (fun i -> f i) population 我最后问自己,我是否会写得更好
我总是从SQL专家那里听到,在SELECT语句中使用'*'符号效率不高,最好列出所有字段名称。 但是,对于将新字段添加到表然后相应地更新所有存储过程的情况下,我个人觉得效率不高。 那么使用'*'的优缺
我想知道通过将业务逻辑和数据与 Web 表单分离来分层 Web 应用程序的长期优势(如果有)。 (即表单、业务逻辑、数据不在同一个文件中,但每个都在另一个文件夹中的自己的类中,或者与其他类似的类组合)
我目前正在从事一个项目,其中分支和合并从一开始就运行得不太好。为了改变这一点,我们一直在讨论多种不同的方法。我想每个人对于如何做这类事情都有自己的哲学,所以它似乎也在这里。 我们一直在讨论的一件事是按
是 StyleCop好用,有什么优缺点? 我还下载了 StyleCop,Resharper StyleCop。 我正在使用 resharper,它有自己的编码标准,而 StyleCop 也有自己的,我
我刚刚开始学习C#,并使用Tutorials Point来完成此操作。在数组部分,我一直看到声明为 string[] sarray = { "Hello", "From", "Tutorials",
使 Java 中的枚举类似于类,而不是像 C/C++ 中那样只是常量的集合有哪些优势? 最佳答案 您可以获得有效值的免费编译时检查。使用 public static int OPTION_ONE =
您会在什么情况下使用 volatile 关键字?更重要的是:该计划如何从中受益? 根据我已经阅读和了解的内容:volatile 应该用于被不同线程访问的变量,因为它们比非 volatile 变量读取起
至少有三种众所周知的创建并发应用程序的方法: 通过锁定(.NET、Java)实现多线程和内存同步。软件事务内存 (link text) 是另一种同步方法。 异步消息传递(Erlang)。 我想了解是否
在对JCR or RDBMS进行了一些研究并阅读了其他posts之后,我仍然不确定是否将JCR over JPA用于文档管理系统,该系统必须处理不同的文档类型,非常大的文件和并发访问很多来自许多用户。
X 来自 http://drupal.org/node/953016 的帖子 Drupal 7 AJAX 系统很棒,它对表单甚至链接都非常流畅。 我无法以理智的方式解决方法是从 javascript
我的 .htaccess 中有一堆规则(子域、文件夹、用户特定的文件夹等...) 我现在正在使用这个正则表达式: ([a-z0-9A-Z]) 我正在寻找一个特定的规则,我找到了多种构建它的方法,我想知
好吧,我想这很清楚我试图对此进行推理的方向。 这些天有很多关于不变性(constness)的优点的讨论。 Java 中的并发编程一书也对此进行了很多讨论。 然而,这一切只是我所读到的。我个人没有用函数
我正在开发一个 Android 应用程序,但我遇到了一个无法以某种方式做出决定的决定。我希望有人能够阐明常见的做法以及支持它们的任何理论。 问题是这样的: 我想要一个包含图像和文本(例如表格)的项目列
是否可以使用 ≠ 而不是 !=。我知道这是一个额外的 alt 代码,我从未在项目中使用过它,但我已经对其进行了测试并且可以正常工作。除了必须 Alt +8800 之外还有什么优点/缺点吗? 编辑:我不
Visual Studio (sqlmetal) 生成的 dbml 文件带有映射到数据库表的实体。在您看来,这些类适合用作领域模型类吗?还是应该避免它们,只将它们隔离到数据访问层? 谢谢 最佳答案 在
我是一名优秀的程序员,十分优秀!