You can modify the Message Routing sample ESQL so that you can use it in other message flows.
The ESQL file, Routing_using_database_and_memory_cache, contains all of the ESQL that is used in the cached version of the sample. Open this file and find the following section (marked as Section 1 in the ESQL):
You must change the three highlighted parts (sections 1, 2, and 3) based on the message that is going to be routed by the ESQL:
When you reuse the ESQL to provide routing capability in another message flow, you can leave the rest of the ESQL. The database table must be updated with any new entries that the new flow requires. See the setupRoutingDatabase database script that is supplied with the sample in the Integration project.
When you are using the ESQL, you must make sure that the Compute Mode on the Compute node properties is set to one of the following values, otherwise the routing information is lost:
The database ODBC source name, Data Source, must also be added to the Compute node properties.
The BEGIN ATOMIC ... END; statement is used in the Routing_using_memory_cache message flow to ensure that one thread only uses the memory cache at a time. The single thread restriction on this part of the ESQL is important only if the cache is going to be refreshed dynamically. If it is decided that the cache does not require refreshing during the life of the message flow, you can reduce the atomic block scope to just cover the initialization of the cache. The following diagram shows the current ESQL (marked as Section 4 in the ESQL):
After this modification is done, the look-up of the queue name in the cache is no longer single-threaded. Several different messages can read from the cache at the same time.
External variables allow hard coded values in message flows to be promoted to the message flow level so that they can be modified at deploy time. The message flow can be customized at deployment time to the environment to which it is being deployed without having to modify the message flow ESQL.
The Routing_using_database_and_memory_cache message flow has a variable called Variable1, which is used to do the database lookup; it is hard-coded to the value SAMPLE_QUEUES. This variable must be externalized at deployment time so that its value can be modified depending on the system to which it is being deployed. This externalization allows you to use a different set of queues and queue managers for each system, but still allows the same database table to be used.
To make Variable1 an external variable:
DECLARE Variable1 CHAR 'SAMPLE_QUEUES'to
DECLARE Variable1 EXTERNAL CHAR 'SAMPLE_QUEUES'The ESQL must look like the following example:
-- Section 1
DECLARE Variable1 EXTERNAL CHAR 'SAMPLES_QUEUES';
DECLARE Variable2 CHAR;
DECLARE Variable3 CHAR;
To use this external variable, you must make new entries in the ROUTING database ROUTING_TABLE table which has different Variable1 parameters. If the flow is deployed without changing the value of Variable1, then it works as before. (Variable1 defaults to SAMPLE_QUEUES).
The current refresh criteria for the Message Routing sample cache of the database table is:
It is useful if other criteria can be used to decide when to refresh the cache. Possible criteria can be:
The sample can be changed to make use of any of these criteria. The critical place in the ESQL for refreshing the cache is:
To change the refresh criteria to use a time period of 60 seconds:
IF CacheQueueTable.LastUpDate is null or (CURRENT_TIMESTAMP - CacheQueueTable.LastUpDate) second > INTERVAL '60' SECOND THEN
SET CacheQueueTable.valid = true;to
SET CacheQueueTable.LastUpDate = CURRENT_TIMESTAMP;
To change the refresh criteria to be true after 100 messages:
IF CacheQueueTable.MessageCount is null or CacheQueueTable.MessageCount > 100 SECOND THEN
SET CacheQueueTable.valid = true;to
SET CacheQueueTable.MessageCount = 0;
SET CacheQueueTable.MessageCount = CacheQueueTable.MessageCount +1;