Michael Lundberg · Mar 23, 2021

Time in queue


I need to know how long time a message has been in a possible queue before our business service starts handling the message. Is it possible to read with objectscript or another way?

The business service is an EnsLib.SOAP.Service

Grateful for answers

Greetings Michael


Product version: IRIS 2020.1
$ZV: 2020.1 (Build 215U)
1 0 4 84
Log in or sign up to continue


Messages for a Business Service would be queued in an external system if the service is unable to process them faster than they're being generated.

Are you referring to the time-in-queue for messages received by the service before they're acted upon by a Business Process or Operation?

Hi and thanks for your reply.

It is not possible to queue up the requests from the external systems themselves, but they will be sent to our HC- integration regardless of how many we already have in our queue. The answer (response) may take a maximum of 15 seconds, otherwise the response must be saved in the database and delivered at a later request.

The problem is knowing how long a message has waited (in a queue) before it is sent to the business process, if the queue exceeds what our business service can process at the time. Our allowed time to process the request will then be 15 seconds minus the waiting time in the queue.

I hope I am clear enough with what I mean.

Regards Michael

This might get you closer to what you want, perhaps called from OnProcessMessage() in the service:

ClassMethod QueueGetOldest(pQueueName As %String, Output pStatus As %Status) As %String
    If ##class(Ens.Queue).GetCount(pQueueName) > 0
        Set tStmt = ##class(%SQL.Statement).%New()                                          
        set qSC = tStmt.%PrepareClassQuery("Ens.Queue","EnumerateItem")
        Set tRS = tStmt.%Execute(pQueueName,"")                        
        Do tRS.%Next()                                                
        Set tHdrid = tRS.%Get("MessageId")
        Set tMsghdr = ##class(Ens.MessageHeader).%OpenId(tHdrid)
        Set pStatus = $$$OK
        Return tMsghdr.TimeCreated
    Set pStatus = $$$ERROR($$$GeneralError,"Not found")
    Return ""

It returns the time created of the oldest entry in the queue, or the empty string if the queue is empty or doesn't exist.

You could create a variant that would accept a duration argument and return true/false if the duration between the current time and the time of the oldest entry exceeds that.

Thanks for your reply! It can be very helpful and we will try your suggestion and hope we can get something done.

Regards Michael