1

I'm using IBM Integration Bus Version 10.0.0.15 and I'm looking for an option to intialize shared variables during the startup of a message flow, for example uing the command mqsistartmsgflow. Is there a special procedure or function one can implement with ESQL which is guranteed to be excuted during start up?

In the ESQL documentation it is stated that shared variables are intialized when the first message is routed through the flow which means you have to wait for the first message.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Klaus Rohe
  • 21
  • 1
  • 3
  • What's your use-case for wanting them initialised beforehand? – simonalexander2005 Sep 24 '19 at 14:57
  • I don't understand what you try to achieve. If you provide your use-case, I'm sure we could help you more efficiently. E.g :loading things at startup will greatly increse the time needed for the IIB restart, so it might create side effect you don't want for something you don't even need – jdel Oct 31 '19 at 08:31

3 Answers3

0

Actually you need to initialise them this typically looks something like.

-- Shared row variable for caching config data. Declared at Global scope.
DECLARE S_ConfigSharedRow SHARED ROW;

CREATE COMPUTE MODULE TheFirstComputeNode
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
    CFGDATA_CACHE_LOCK: BEGIN ATOMIC
        -- If the configuration data is not available in the cache then load it from the CONFIG table
        DECLARE CfgDataRef REFERENCE TO S_ConfigSharedRow.CfgDataCache;
        IF NOT LASTMOVE(CfgDataRef) THEN
            -- Select all the relevant content from the actual database in one go.
            DECLARE DBResults ROW;
            DECLARE RetryCount INTEGER 5;
            SET DBResults.Row[] = PASSTHRU('SELECT * FROM CONFIG');

            -- Typically you would post process the content from the DB into a more amenable 
            -- structure but the following will get the data into the shared variable
            CREATE LASTCHILD OF S_ConfigSharedRow.CfgDataCache FROM DBResults;
        END IF;
    END CFGDATA_CACHE_LOCK;

    -- Config data is now available for use

    RETURN TRUE;
END;
END MODULE;
TJA
  • 2,969
  • 2
  • 25
  • 32
0

I think the best way is to have a dedicated flow for initializing shared variables. That flow should have an input queue separate from the normal input queue, just for sending in messages to trigger the initialization. Then you should make a startup script, which sends a message to this init flow after starting up the main processing flow. And use only that script for startup.

Attila Repasi
  • 1,803
  • 10
  • 11
0

If you want another option, you could include a JavaCompute node and add some once-only initialisation into its class using a static initialization block. You would only be able to initialize Java data structures this way, though.

kimbert
  • 2,376
  • 1
  • 10
  • 20