我正在尝试按步骤创建由QueueTrigger处理的多步骤过程。如何在没有每状态队列的情况下过滤QueueMessage对象的'state'属性? Msg的类型为:
public partial class TaskType{
string BlobPathToProcess {get; set;}
int State {get; set;}
}
public static void Task(
[QueueTrigger(queueName: "taskq")] TaskType msg
TextWriter log,
IBinder binder)
{
//currently I use a switch statement on (TaskType.State == 1)
所以不是:
[QueueTrigger(queueName: "taskqstate1")] TaskType msg
[QueueTrigger(queueName: "taskqstate2")] TaskType msg
等
可能像@pranav-rastogi所说Singleton attribute
上的MSDN Ch9 cloud cover at min 24[Singleton(@"{Region}\{Zone}"]
public static void Task([QueueTrigger(singleto-test")] WorkItem workItem, ...
{Region}和{Zone}是'workItem'对象的属性。
更像是:
[PocoFilter(PocoProperty="{State}", PocoValue="1"]
public static void Task1([QueueTrigger(queueName: "taskq")] TaskType msg ...
[PocoFilter(PocoProperty="{State}", PocoValue="2"]
public static void Task2([QueueTrigger(queueName: "taskq")] TaskType msg ...
答案 0 :(得分:2)
据我所知,Azure Queue没有消息传递过滤功能。
如果您转到Azure Service Bus主题和订阅,您将能够根据邮件属性进行过滤。
要创建主题和订阅,您可以查看本文:
所以说,你已经创造了
名称为“MySubscription1”并且SqlFilter“状态= 1”的订阅
名称为“MySubscription2”且SqlFilter“Status = 2”的订阅
在你的webjob中,你可以拥有两个看起来像这样的功能:
public static void ProcessQueueMessage1(
[ServiceBusTrigger("MyTestTopic", "MySubscription1")] BrokeredMessage incomingMessage,
ServiceBus("MyTestTopic")] out BrokeredMessage outputMessage)
{
// Status should be 1
Console.Out.WriteLine(incomingMessage.Properties["Status"]);
// Get your poco
var myPoco = incomingMessage.GetBody<TaskType>();
//Process your message ...
....
// clone the message
outputMessage = incomingMessage.Clone();
// Set the status to 2
outputMessage.Properties["Status"] = 2
}
public static void ProcessQueueMessage2(
[ServiceBusTrigger("MyTestTopic", "MySubscription2")] BrokeredMessage incomingMessage)
{
// Status should be 2
Console.Out.WriteLine(incomingMessage.Properties["Status"]);
// Do what you need
}
在fisrt方法中,我们使用ServiceBusTriggerAttribute来侦听发送到订阅1的消息,并使用ServiceBusAttribute向主题发送消息。
如果您想发送消息,请不要忘记设置BrokeredMessage的“Status”属性。