[英]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
属性中的绑定语句来引用这些的方法,但是当将Singleton
与ServiceBusTrigger
结合使用时,这似乎是一个非常常见的用例
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.