Hi, Everybody...
I have an "internal" API that tracks packages (plural). This "internal" API accepts a collection of tracking numbers, iterates through the collection and invokes the "external" (i.e., third-party vendor) track package (singular) API. This effectively "blasts" a number of requests at the "external" (i.e., third-party vendor) track package (singular) API. Apparently, the vendor API cannot handle multiple concurrent requests. I need to somehow "throttle" the requests one at a time (i.e., invoke the "external" (i.e., third-party vendor) track package (singular) API, wait for the response, process it and then invoke the same "external" (i.e., third-party vendor) track package (singular) API with the next tracking number, until there are no more tracking numbers).
I imagine instantiating a singleton and have it instantiate a queue upon starting the webservice. The singleton and the queue will persist until the webservice is shutdown. The "internal" API that tracks packages (plural) will simply enqueue the tracking numbers. A worker thread would dequeue a tracking number, invoke the "external" (i.e., third-party vendor) track package (singular) API, wait for the response, process it and repeat until all the tracking numbers have been dequeued.
Also, is it possible to make a queue "eventful" (i.e., raise an event when the queue count becomes non-zero and another event when the queue count becomes zero)? Thus, the former event would create a worker thread and the latter event would release/dispose the worker thread.
Also, will I need to perform some housekeeping when the webservice is shutdown?
Is this a viable approach?... Or is there a better way?
Note: I viewed the following. None were applicable specifically to my situation.