使用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?

查看:95
本文介绍了使用Webjobs SDK 3.x中的ServiceBusTrigger,Singleton属性可以使用UserProperty作为范围吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ServiceBusTrigger 来接收消息时执行代码.我想使用Singleton属性,用于限制可以并行执行的消息.此属性允许指定绑定到传入消息的属性的范围,这样可以并行执行具有不同值的消息,但必须串行执行具有相同值的消息.

I am using a ServiceBusTrigger to execute code when receiving a message. I would like to use the Singleton attribute to limit which messages can be executed in parallel. 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.

在传入消息对象(如CorrelationId)上使用顶级属性时,此方法有效.

This works when using top level properties on the incoming message object like CorrelationId.

示例

[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();
}

我要弄清楚的是如何使用消息上的用户属性实现相同的行为.这些存储在 Message 对象上的 UserProperties 字典中.我没有看到在 Singleton 属性中使用绑定语句引用它们的方法,但是当将 Singleton ServiceBusTrigger

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. 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

推荐答案

服务总线绑定公开了

The Service Bus Bindings exposes Message Metadata in binding expressions. So, userProperties.<key> should do the trick.

这篇关于使用Webjobs SDK 3.x中的ServiceBusTrigger,Singleton属性可以使用UserProperty作为范围吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆