0

According to this WebJobs documentation page, for POCO output queue messages, "A queue message is always created, even if the object is null."

In my scenario, I only want to conditionally output queue messages from my WebJob. Currently I am getting a ton of null messages to my downstream WebJob using the "out" queue:

[Queue("myoutqueue")] out myPOCO outputQueueMessage

Is the only way to do this to not use the WebJobs Queue attribute and to queue the message myself using the client library?

Bryan Lewis
  • 5,629
  • 4
  • 39
  • 45

1 Answers1

5

You can conditionally enqueue an output message by using the ICollector<T> binding. For example:

[Queue("myoutqueue")] ICollector<MyPoco> outMessages

Then, only messages added to the collector via outMessages.Add(message) will be sent (one or more). More on ICollector<T> and other Queue bindings can be found here.

mathewc
  • 13,312
  • 2
  • 45
  • 53
  • Thanks. I should have thought of that. I have used the ICollector option in another WebJob. This job was just different because it will always be 0 or 1 message instead of many like my other job. – Bryan Lewis Jan 13 '16 at 00:22