WebSphere Message Brokers
File: ac16755_
Writer: Bill Oppenheimer

Task topic

This build: July 31, 2007 21:18:38

Calculating a time interval

This ESQL example calculates the time interval between an input WebSphere MQ message being put on the input queue, and the time that it is processed in the current Compute node.

(When you make a call to a CURRENT_ datetime function, the value that is returned is identical to the value returned to another call in the same node. This ensures that you can use the function consistently within a single node.)

 CALL CopyMessageHeaders();
 Declare PutTime INTERVAL;

 SET PutTime = (CURRENT_GMTTIME - InputRoot.MQMD.PutTime) MINUTE TO SECOND;
 
 SET OutputRoot.XMLNS.Test.PutTime = PutTime;

The output message has the format (although actual values vary):

<Test>
 <PutTime>INTERVAL &apos;1:21.862&apos; MINUTE TO SECOND</PutTime>
</Test>

The following code snippet sets a timer, to be triggered after a specified interval from the start of processing, in order to check that processing has completed. If processing has not completed within the elapsed time, the firing of the timer might, for example, trigger some recovery processing.

The StartTime field of the timeout request message is set to the current time plus the allowed delay period, which is defined by a user-defined property on the flow. (The user-defined property has been set to a string of the form "HH:MM:SS" by the administrator.)

DECLARE StartDelyIntervalStr EXTERNAL CHARACTER '01:15:05';

	CREATE PROCEDURE ValidateTimeoutRequest() BEGIN

		-- Set the timeout period
		DECLARE timeoutStartTimeRef REFERENCE TO 
          OutputRoot.XMLNSC.Envelope.Header.TimeoutRequest.StartTime;
		IF LASTMOVE(timeoutStartTimeRef)
			THEN
			-- Already set
		ELSE
			-- Set it from the UDP StartDelyIntervalStr 
			DECLARE startAtTime TIME CURRENT_TIME 
          + CAST(StartDelyIntervalStr AS INTERVAL HOUR TO SECOND);
						
			-- Convert "TIME 'hh.mm.ss.fff'" to hh.mm.ss format 
       -- needed in StartTime field
			DECLARE startAtTimeStr CHAR;
			SET startAtTimeStr = startAtTime;
			SET startAtTimeStr = SUBSTRING(startAtTimeStr FROM 7 FOR  8);
			SET OutputRoot.XMLNSC.Envelope.Header.TimeoutRequest.StartTime 
                            = startAtTimeStr;
		END IF;
	END;
Related concepts
Message flows overview
Message mappings overview
Related tasks
Developing message flows
Developing ESQL
Using numeric operators with datetime values
Related reference
Built-in nodes
ESQL reference
ESQL INTERVAL data type
ESQL numeric operators
Rules for ESQL operator precedence
CAST function
Notices | Trademarks | Downloads | Library | Support | Feedback

Copyright IBM Corporation 1999, 2007Copyright IBM Corporation 1999, 2007. All Rights Reserved.
This build: July 31, 2007 21:18:38

ac16755_ This topic's URL is: