2

I understand Webjob is a back-end job and the Webapp can invoke it through Azure queue. My question is if the Webjob completes, how can the Webapp know the Webjob is finished and how can the Webapp retrieve the results generated by Webjob?

Is there any asyn method that can work in this scenario? Other methods are also welcomed.

Thanks

Derek

----------------Update ------------------------

Can "ListQueuesSegmentedAsync" method work? But I have no idea how to use it.

derek
  • 9,358
  • 11
  • 53
  • 94
  • ListQueuesSegmentedAsync: http://stackoverflow.com/q/31788798/4148708, but i don't see why you'd need that. Why do you need discovery if you create the queue names yourself? Look at Table Storage or Redis to keep state if this is getting too complex, although that's probably not going to behave as elegantly as a queue system. – evilSnobu Sep 24 '16 at 11:23
  • Redis can now do pub/sub, worth a look - http://redis.io/topics/pubsub – evilSnobu Sep 24 '16 at 11:32

1 Answers1

0

You already know the answer! A Message Queue!

If you need more than a few KB for a message (maybe you want to pass a JPEG file) drop that into Blob Storage and signal the Web App/WebJob with a queue message indicating the full path to the newly arrived blob.

For more on implementing a Queue-centric workflow, see my other answer here:
https://stackoverflow.com/a/38036911/4148708

Sometimes, if keeping state isn't your first concern, it may be easier to implement a system where the WebJob calls an authenticated REST endpoint in the WebApp to GET/POST data.

There's no silver bullet. Every scenario tends to be a little different and may benefit from simplicity rather than durability (REST vs durable message queue).

Oh, and since you did specifically ask for async, here's one way to do it for REST (Queues are async by nature):

  • Call the REST endpoint from your WebJob
  • Return 202 Accepted (as in I got you, but the TPS report isn't ready yet)
  • Return Location: https://webapp/{a-chunk-of-sha1-representing-a-unique-id} (The point of this header is to tell the WebJob Check this URL from time to time to grab the finished TPS report)
  • Follow the URL to get results, 200 OK means you have them, 417 Expectation Failed means not yet. Actually HTTP 417 is supposted to be used in response to 100 Continue, but you never get to use that so i'm slowing campaigning for 417 Expectation Failed to rival with buzzwords like elastic and disruptive. But i digress.
Community
  • 1
  • 1
evilSnobu
  • 24,582
  • 8
  • 41
  • 71
  • 1
    The key question is how to "signal the Web App/WebJob with a queue message"? Webapp puts message into a queue which then feeds the Webjobs. Can the Webjobs put message in the same queue? Thanks – derek Sep 22 '16 at 20:45
  • Of course it can, but it would make things hard to track. Use **Queue #1 for App -> Job** and **Queue #2 for Job -> App**. You'll then know what's what and more importantly, which component is down (as in no longer consumes messages). Otherwise you'll have to PeekLock each message to check "Hey is this for me or the WebJob?". – evilSnobu Sep 22 '16 at 20:49
  • If I have 10 webjobs running and if we are using a 2nd queue to pass back all the results from Webjob to Webapp, then Webjob will retrieve each message to check whether it is from the correct Webjob. During the checking process, the messages will be removed from queue, correct? – derek Sep 22 '16 at 21:00
  • If you have 10 DIFFERENT WebJobs then you need 20 distinct Queues (10 one way and 10 the other). If you have 10 instances of the same WebJob.. why do you care? Since that's now a cooperative-producer/competing-consumer model, whoever gets the message first processes it. – evilSnobu Sep 22 '16 at 21:11
  • Or you can use just one topic with 20 subscriptions – Thomas Sep 22 '16 at 21:12
  • Then consider a pub/sub model: https://azure.microsoft.com/en-us/documentation/articles/service-bus-dotnet-how-to-use-topics-subscriptions/ – evilSnobu Sep 22 '16 at 21:29
  • Probably best to take this to [chat](http://chat.stackoverflow.com/) - this has turned into a discussion, along with new questions, and solutions being proposed in comments. – David Makogon Sep 23 '16 at 01:52
  • Can "ListQueuesSegmentedAsync" method work? But I have no idea how to use it. – derek Sep 23 '16 at 17:11