If you have ever worked with the integration server (part of webMethods Product Suite) you have probably come in contact with flow. This is what this article is about.
Sometimes you´re in need of a way to limit the concurrent work for a specific service or subsystem. Basically, there are two ways to achieve this:
1) Implementing a custom queue in java using e.g. a hash table, which hold the information about current executions (threads)
2) Using publish/subscribe and the built in trigger functions for controlling concurrent executing threads and queue size.
In order to decide which way to go I would first decide how important the response time of you particular service or flow is. If you are running some really time critical real time service (e.g. web service for transfering money or some other important stuff) were you must keep the response times to a minimum, I would probably go for the hash table. But if it´s not that critical and you have some tens of a seconds to spare, and it´s ok with an occasional delay of a few seconds every now and then – I would in 9 times out of ten go for the publish/subscribe solution.
This article describes the latter one – using the built in publish/response mechanism.
Local or Broker
First, decide if you should use local publishing (not outside the IS) or publish to the broker. If you can keep the work to a single IS, you should use local publishing (at least that´s what I prefer).
Setting our limits
To control the number of current active threads executing a service (configured i the trigger) you first have to decide a limit appropriate for you system. Lets decide that 10 concurrent threads are enough for us. Begin by setting the concurrent threads to 10 on your trigger, continue with max queue size and set this to 10 as well. The queue shows queued documents + the current executing threads, which means if the concurrent thread limit is equal to the queue size, the curreny queue size (persisted documents, we’ll come to this later) is allways equal to the number of executing threads.

Now, you might think were done – cause it sure seems so – but no!
The Integration Server actually ignores the maximum queue size, making it add more documents to the queue even though the configured limit is hit. To avoid this we have two choices.
Controlling the concurrent work
The first (and ugly one) is to set the watt.server.publish.local.rejectOOS property to true in extended settings.
This makes all local publish’s fail with the status message “Capacity exceeded” if the queue is full. After a publish you can check for this status message to see of the publish were successfull or not. Since this affect all other services doing local publishing you have to be very carefull you´re not breaking anything. Another dawback with this approach is that it generates an error in the error log, which may or may not be usefull depending on your solution. To avoid this (and the local publish issue), consider the second approach:
The other option, also the one I usually prefer is not to publish at all if the queue is full. There are some services in the WmRoot package which you can use to retrieve alot of information about a specific trigger. To see the WmRoot package in the Developer, set the watt.server.ns.hideWmRoot to false. To get the current processing status of a specific trigger, call wm.server.triggers:getProcessingStatus. This gives you (among other things) the Persisted Queue Count, which is the number of currently executing threads + any other documents in queue. If this magic little number is equal to or exceeds (god forbidden) your configured limit, you should not publish the document at all.
What now?
So, what are we gonna do with the request we could not complete? Since the system probably is overloaded, you either skip this particular step if it´s possible and continue – or you gracefully return an error code with a message saying the particular system is unavailable.
Summary
This is just one of many many ways to limit the concurrent work withing the integration server. It may or may not work (or fit) for your particular system (or implementation). However, it’s really easy to implement, it does not require alot of code (you can do it 100% in flow) and it´s easy to configure (keep you limit configured in a TPA or some other configuration file). So, think twice before ruling out this solution as an option – it might be exactly what you need :)
I will add a sample packege for download as soon as I have some spare time to put one together.
aeac7be4-fef2-4df6-b5eb-b46bf8f2717a|0|.0