简体   繁体   English

在 Webjobs SDK 3.x 中使用 ServiceBusTrigger,Singleton 属性可以使用 UserProperty 作为作用域吗?

[英]Using ServiceBusTrigger in the Webjobs SDK 3.x, can the Singleton attribute use a UserProperty as the scope?

I am using a ServiceBusTrigger to execute code when receiving a message.我在接收消息时使用ServiceBusTrigger来执行代码。 I would like to use the Singleton attribute to limit which messages can be executed in parallel.我想使用Singleton 属性来限制可以并行执行的消息。 This attribute allows specifying a scope bound to properties on the incoming message, such that messages with different values can be executed in parallel but ones with the same value must be done serially.此属性允许指定绑定到传入消息的属性的范围,以便可以并行执行具有不同值的消息,但必须串行执行具有相同值的消息。

This works when using top level properties on the incoming message object like CorrelationId.这在对传入消息对象(如 CorrelationId)使用顶级属性时有效。

Example例子

[Singleton("{CorrelationId}", SingletonScope.Function, Mode = SingletonMode.Function)]
public async Task HandleMessage(
    [ServiceBusTrigger("my-topic-name", "my-subscription-name"), ServiceBusAccount("my-account-name")]
    Message message,
    CancellationToken cancellationToken
)
{
    await Task.Yield();
}

What I am struggling to figure out is how to achieve the same behavior with user properties on the message.我正在努力弄清楚如何使用消息上的用户属性实现相同的行为。 These are stored in the UserProperties dictionary on the Message object.它们存储在Message对象的UserProperties字典中。 I'm not seeing a way to refer to these with the binding statement in the Singleton attribute, but it seems like this would be a very common use case when combining Singleton with ServiceBusTrigger我没有看到使用Singleton属性中的绑定语句来引用这些的方法,但是当将SingletonServiceBusTrigger结合使用时,这似乎是一个非常常见的用例

The Service Bus Bindings exposes Message Metadata in binding expressions.服务总线绑定在绑定表达式中公开消息元数据 So, userProperties.<key> should do the trick.因此, userProperties.<key>应该可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法将ServiceBusTrigger BrokeredMessage成员绑定到Azure WebJobs SDK中的Blob blobpath - Unable to bind ServiceBusTrigger BrokeredMessage members to Blob blobpath in Azure WebJobs SDK 在Azure Webjobs SDK v3中处理ServiceBusTrigger函数中的Webjob关闭 - Handling Webjob Shutdown in ServiceBusTrigger Function in Azure Webjobs SDK v3 如何在WebJobs SDK 3.x中向新的HostBuilder注册自定义NameResolver? - How do I register a custom NameResolver with the new HostBuilder in WebJobs SDK 3.x? Azure WebJobs和ServiceBusTrigger - Azure WebJobs and ServiceBusTrigger Azure WebJobs (3.x) 连续作业未在仪表板中显示函数 - Azure WebJobs (3.x) Continuous job not showing Functions in Dashboard C# Azure 在本地开发中使用 Azurite 的 WebJobs 3.x - C# Azure WebJobs 3.x with Azurite in local development 使用 Azure WebJobs SDK 进行依赖注入? - Dependency injection using Azure WebJobs SDK? 如何在 Azure Webjobs 中为非触发方法应用单例属性 - How to apply Singleton Attribute for NonTriggered method in Azure Webjobs Azure webjobs-计划和单例 - Azure webjobs - Scheduling and singleton Azure WebJobs 3.x 不会通过 Azure 应用程序设置中的 CRON 表达式触发 - Azure WebJobs 3.x does not trigger with CRON expression in Azure Application Settings
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM