Author |
Message
|
Bharat_123 |
Posted: Sun Feb 15, 2009 10:06 am Post subject: Global/ Shared Variables in Msg Flow |
|
|
Acolyte
Joined: 15 Sep 2008 Posts: 58
|
Hello
Is there any way to store data in a variable for a particular period of time. In my scenario i have 4 ".msgFlow's" under 1 msg flow project. When i get the msg i am saving in a Environment varible. and some values in comp node i am declaring as shared depends of the usability.
Now i have a situation i wated to use the input environment varible data in my 3rd & 4th .msgFlow.
Is there a way to get that variable data? with out saving to a Queue or DB becuase in our design we dont have a requirement for that.
or is there a way get the data which is saved as a environment variable or shared variables in 1st .msgFlow to visible to all other .msgFlow under in MFP project?
Needed .............Thanks for your time |
|
Back to top |
|
 |
smdavies99 |
Posted: Sun Feb 15, 2009 1:50 pm Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
Look for ESQL Shared variables in the documentation.
These work!
They are ideal for doing things like
1) holding static data - so you don't have to read the same row for every message (really good. Reading Java properties files for every message is IMHO a really dumb idea) - removed read locks.
2) update counters - then a timed process can usdate the database on a periodic basis - Removes write locks
Rembember they are only EG wide not broker wide....
 _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
mgk |
Posted: Sun Feb 15, 2009 2:19 pm Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Quote: |
Rembember they are only EG wide not broker wide |
Actually ESQL SHARED variables are only Flow wide, not EG or Broker wide, but they do work
Regards, _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
mqjeff |
Posted: Sun Feb 15, 2009 3:04 pm Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
mgk wrote: |
Quote: |
Rembember they are only EG wide not broker wide |
Actually ESQL SHARED variables are only Flow wide, not EG or Broker wide, but they do work  |
I thought they were Schema wide? |
|
Back to top |
|
 |
mgk |
Posted: Sun Feb 15, 2009 3:32 pm Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
From the docs:
Quote: |
Use SHARED to define a shared variable. Shared variables are private to the flow (if declared within a schema) or node (if declared within a module), but are shared between instances of the flow (threads). No type of variable is visible beyond the flow level; for example, you cannot share variables across execution groups. |
What this means is that Aditional Instances of a Flow will see a SHARED variable in that Flow, but each Flow has its own shared variables which cannot be seen by other Flows. _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
Bharat_123 |
Posted: Mon Feb 16, 2009 7:58 am Post subject: |
|
|
Acolyte
Joined: 15 Sep 2008 Posts: 58
|
I see the shared variables are limited to flow level itself. I trired to call shared variable which i used in flow 1into flow 4. But that variable does not exist any more
Is there any other way to do it please.
Thanks |
|
Back to top |
|
 |
Tibor |
Posted: Mon Feb 16, 2009 9:50 am Post subject: |
|
|
 Grand Master
Joined: 20 May 2001 Posts: 1033 Location: Hungary
|
If these flows are coordinated / cohesive why do you use separated flows? |
|
Back to top |
|
 |
Bharat_123 |
Posted: Mon Feb 16, 2009 10:53 am Post subject: |
|
|
Acolyte
Joined: 15 Sep 2008 Posts: 58
|
to avoid multi threading / instances (if i am not wrong with my little practicle knowledge of WTX).
since the message has to undergo diff applications for validation and transformation its X12 msg. since we are not using wtx plugin. 1 flow put to tx and the other picks from tx and the other put to main frame and get from main from again process repeats last reply to consumer.
if the process fails in between i need to reply to consumer the message what ever i received on 1st input node that i need to send it back. thats the reason i am asking to get that msg back @ failure scenarios.
Thanks |
|
Back to top |
|
 |
mikepham |
Posted: Thu Feb 10, 2011 11:14 pm Post subject: |
|
|
 Novice
Joined: 17 Mar 2010 Posts: 20
|
Hi everyone
I have questions related to using Shared variables. I'm a little bit confused and really need your help
I'm using WMB 6.1
I have 2 msgflow named: Msgflow1 and Msgflow2 under same project
I declared a shared variable named MyVariable in esql file of Msgflow1 at top line, not in any module.When I declare this same shared variable in esql file of Msgflow2, WMB marked it as error and said I could not do that because MyVariable was declared.
As MGK said
Quote: |
What this means is that Aditional Instances of a Flow will see a SHARED variable in that Flow, but each Flow has its own shared variables which cannot be seen by other Flows. |
**Could you help me explain why WMB does not let me declare same shared variable in 2 different msgflow under same project?
I clear the declaration of MyVariable in esql file of Msgflow2, the error disappeared in WMB toolkit, I can use it in Msgflow2 without declaration.
As Bharat_123 said
Quote: |
I see the shared variables are limited to flow level itself. I trired to call shared variable which i used in flow 1into flow 4. But that variable does not exist any more |
I'm getting confused
** Could you help me clarify about that ? |
|
Back to top |
|
 |
mgk |
Posted: Fri Feb 11, 2011 1:52 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Quote: |
I clear the declaration of MyVariable in esql file of Msgflow2, the error disappeared in WMB toolkit, I can use it in Msgflow2 without declaration |
Effectively in this case each flow gets its own copy of the variable - so values are not shared between flows. _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Feb 11, 2011 2:43 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You can't declare two variables with the same name in the same scope.
If you declare a shared variable at the top of the file, outside the module, then it's in the schema scope, and thus defined in all flows that use the same schema.
So this is why you can't declare it twice in different flows - it's already declared in the second one.
Even though it's defined, as mgk says each flow gets it's own copy. |
|
Back to top |
|
 |
lancelotlinc |
Posted: Fri Feb 11, 2011 4:58 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
|
Back to top |
|
 |
mqjeff |
Posted: Fri Feb 11, 2011 5:18 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
lancelotlinc wrote: |
EG wide shared variables exist in Singletons. |
Yes, you can create Java static variables that are then in scope across the entire JVM portion of a single DataFlowEngine process.
You have to access and update it from the JVM, however. You can't natively access it from ESQL which runs in the C++ runtime. Some care with a Java procedure can make it accessible from ESQL, albeit indirectly.
Or you can use the Cache supportPack to handle that for you. Except, of course, at least some people have reported issues with it in production. So it's a design decision that needs to be tested and evaluated.
More particularly, you should reexamine any need to share state across multiple message flows, which are generally designed to be stateless and logically independent of each other.
So what are you trying to do by sharing variables? What's the business requirement? |
|
Back to top |
|
 |
mikepham |
Posted: Thu Feb 17, 2011 1:54 am Post subject: |
|
|
 Novice
Joined: 17 Mar 2010 Posts: 20
|
Thanks everyone for your explanation/clarification
mqjeff wrote: |
So what are you trying to do by sharing variables? |
Hi mqjeff, sorry for late reply on this because I'm kind of busy
I'm using sharing variables to share some values across multiple nodes in single msgflow
For example I have several compute nodes in a msgflow
I set some values to share variables at 1st compute node and 2nd compute node then I retrieve them at the last compute node to do my business
I know it could be strange since we can use LocalOutputEnvironment to store variables across multiple nodes in a msgflow. However, it looks safer for me to use shared variables on msgflows that are not developed by me. You know, that's kind of new enhancement, new requirement on these msgflows
Do you think I have any risk on using shared variables in this case ?
I only use single instance of msgflow in 1 execution group
I may use same msgflow in 2 different execution group
Each msgflow has only 1 input (MQInput or JMSInput)
MQInput: I use Transaction mode = Yes (default)
JMSInput: I use Transaction mode = None (default) |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Feb 17, 2011 3:08 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
If you're creating common code that is going to be used to do some particular task and reused in many message flows that you aren't writing, then yes using a shared variable is a 'safer' method than using LocalEnvironment or Environment.
You just have to pay attention to module vs schema scope issues, like you've seen, and you probably want to put your ESQL /flows into it's own schema (like a java pacakge) |
|
Back to top |
|
 |
|