Author |
Message
|
armolina |
Posted: Thu Aug 11, 2011 11:45 pm Post subject: Reuse ESQL function in multiple flowProjects |
|
|
Newbie
Joined: 11 Aug 2011 Posts: 3
|
Hi!
I need to use one ESQL function into multiple projects.
I know the "good" way is to create two projects:
#1 is a subflow with the declaration of the function to reuse
#2 the main flow who contains the #1 flow and calls the function
The problem of this way is when I change the #1 flow (who has the common code), then I need to redeploy all the main flows who contains the #1 subflow.
The idea and what I've tried is to create two projects:
#1 with the declaration of the function to reuse
#2 have a reference to #1 project and the instantiation to this function
But it doesn´t work.
Could you help me to find a way to do this, please? Thank you in advance.
Regards. |
|
Back to top |
|
 |
mapa |
Posted: Fri Aug 12, 2011 12:22 am Post subject: |
|
|
 Master
Joined: 09 Aug 2001 Posts: 257 Location: Malmö, Sweden
|
This is a excellent article that gives you some tips:
http://www.ibm.com/developerworks/websphere/library/techarticles/0803_shen/0803_shen.html
A couple of years old but I think most still holds true.
Some points of my own:
Make sure your #2 flow uses by your versioning software tagged version of the Message Flow project containing the ESQL, (no subflows are needed).
I also put a version in the broker schema of my common ESQL. (something like com.company.wmb.common.v1)
Not sure if this is best practice or not, but I do it so that it can be seen in my ESQL that resuses the code which version of the common ESQL code it is depandant upon.
Don't know what the rest of you say about this. _________________ Brgds, Magnus Palmér
Enfo Zystems |
|
Back to top |
|
 |
marko.pitkanen |
Posted: Fri Aug 12, 2011 12:32 am Post subject: |
|
|
 Chevalier
Joined: 23 Jul 2008 Posts: 440 Location: Jamsa, Finland
|
Hi,
Used sub flows and referenced procedures, functions and methods will be compiled into compiled message flow file inside the BAR. So you have to build and deploy all the flows using our common functionality after you have changed it.
I can see 2 possible solutions to achieve what you want:
1. build our functionality as external function / procedure / method for example with java and put your jar to shared_class directory. So by updating your jar and restarting the broker will refresh functionality for all your flows.
2. build your functionality as external service which you can invoke and use from you flows. So by updating you service will update functionality for all your flows.
--
marko |
|
Back to top |
|
 |
armolina |
Posted: Fri Aug 12, 2011 2:47 am Post subject: |
|
|
Newbie
Joined: 11 Aug 2011 Posts: 3
|
Hi @mapa,
The idea is the point 3.2 of linked document in your post but I need to do this:
Code: |
CREATE FUNCTION encodeInBASE64(IN data BLOB)
RETURNS CHARACTER
LANGUAGE JAVA
EXTERNAL NAME "com.ibm.broker.util.base64.encode";
|
with ESQL like this:
Code: |
CREATE FUNCTION encodeInBASE64(IN data BLOB)
RETURNS CHARACTER
LANGUAGE ESQL
EXTERNAL NAME "com.ibm.broker.util.base64.encode"; |
Also I don´t know how to set the EXTERNAL NAME statement.
Hi @marko.pitkanen,
I need do it with ESQL code because is a requirement.
Thanks and regards. |
|
Back to top |
|
 |
mapa |
Posted: Fri Aug 12, 2011 3:16 am Post subject: |
|
|
 Master
Joined: 09 Aug 2001 Posts: 257 Location: Malmö, Sweden
|
OK, I'll give you a more practical example:
Will not use real names and schema structure since it is how it looks like at current customer.
Anyway.
I have a MessageFlowProject that only contains one ESQL file.
The file is declared in a broker schema (think Java package declaration) and that contains reused functions and procedures.
Code: |
BROKER SCHEMA org.example.wmb.common.stuff.v1
/* Translate language code from Acme ERP to ISO code
* Parameters:
* IN: CHARACTER ACME_LANG
* RETURN: CHARACTER ISO code or ACME_LANG if not found.
*/
CREATE FUNCTION translateAcmeLanguageToIso(IN ACME_LANG CHARACTER) RETURNS CHARACTER
BEGIN
"some ESQL code is here"
END;
|
Then in my Message Flow Project where I need to use this translation I add a dependency to my Common project where the translation function is.
Then in my ESQL in my message flow I enter PATH <ctrl+space> and I see the "org.example.wmb.common.stuff.v1" and chose that.
(This is before I declare the module, similar to importing a package in Java).
Code: |
PATH org.example.wmb.common.stuff.v1; |
Then I can use <ctrl+space> and see the translateAcmeLanguageToIso(IN "ACME_LANG" CHARACTER) when I need it in my code.
Code: |
SET someRef.isoCode = translateAcmeLanguageToIso(someOtherRef.lang); |
Note Markos comment that this is embedded into your compiled flow when you build the barfile. So if you update the common code you will need to rebuild the flows that is using it if they are to see the changes.
I do not want to update this in an uncontrolled way where the flows dynamically is updated, I want this controlled and dependant upon a known tagged working version. _________________ Brgds, Magnus Palmér
Enfo Zystems |
|
Back to top |
|
 |
smdavies99 |
Posted: Fri Aug 12, 2011 3:47 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
encodeBase64 and decodeBase64 are included in the ESQL in V7.0.0.2. _________________ 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 |
|
 |
armolina |
Posted: Fri Aug 12, 2011 3:55 am Post subject: |
|
|
Newbie
Joined: 11 Aug 2011 Posts: 3
|
Works!
Thanks for the code and description! |
|
Back to top |
|
 |
inMo |
Posted: Fri Aug 12, 2011 9:15 am Post subject: |
|
|
 Master
Joined: 27 Jun 2009 Posts: 216 Location: NY
|
I just wanted to comment on the general idea of re-using ESQL without re-building bar files. In simplest terms, through WMB v7, you can't. In more complex terms, you can't unless you create it as a service and allow yourself the option of build/deploy on a single bar file.
You can wrap your ESQL code in a service, choosing whatever protocol you desire, and have 1 to n flows call this service. When you change the ESQL, you will need to re-deploy your service. So instead of building & deploying 'n' flows, you build and deploy 1 flow. |
|
Back to top |
|
 |
|