Monday, April 15, 2013

QT009: Using Shared Variables in CIOS

Quick Tip #009: Using Shared Variables in CIOS

What is a Shared Variable?

In CIOS a shared variable is a variable that is "Shared" across all jobs for a given orchestration.  By assigning a value to a shared variable in the right side of a map, that value will be accessible by all other jobs of that orchestration.  Like all variables in CIOS shared variables are persisted in the event of power loss.  Shared variables are only cleared when an orchestration is stopped via the WMC.

Run Orchestration Jobs Sequentially

When using a shared variable in an Orchestration, the option to run all jobs in a single instance is automatically checked.  (In prior versions this option was called Run Orchestration Jobs Sequentially)   It is not possible to read and write a variable simultaneously, therefore running jobs in a single instance will ensure the consistency of your shared variables because there is no simultaneous access.

Why Use Shared Variables?

Shared variables are a powerful concept and enable numerous use cases, we'll highlight a few of the most common:

Sequence Numbers

You can use shared variables to generate sequence numbers for files, database records, etc.  By simply creating a shared variable and incrementing it each time you need a new value you can easily generate sequence numbers.
Tip: It is important to make sure that you have a way to initialize your sequence number by reading the highest existing value, using a configuration property or by some other means because you may need to reset the sequence or advance it.

Last Updated Date

If you are polling for changes in a resource and for any reason are not using one of the polling connectors, you may need to keep track of the last record that was successfully processed.  A shared variable is a good way to keep track of such values.  Again, you will want to make sure that you have a way to manually set this date on startup or change the data in order to reprocess records.


Shared variables can also be used to cache values such as a session key for a web api.  You can cache any xml document so its possible to cache complex structures such as a lookup table.  Note that jobs will run sequentially for performance reasons you should be careful when to use this option vs caching values in a database or external system.

No comments:

Post a Comment