Transcription of JCN from ESQL Perspective - mqtechconference.com
1 MQ Technical Conference Java Compute Node API From ESQL Perspective Babu Purushothaman MQ Technical Conference Agenda Overview Configuration and Deployment Processing messages Working with Databases Debugging JCN Code MQ Technical Conference Disclaimer The java statements given here are not 100% direct statements of ESQL. They are either equivalent or serve similar purpose. MQ Technical Conference Why Java Compute Node? Popular language Ready availability of Java resources Rich third party API support Full IDE support of Eclipse Support for both JDBC and ODBC Xpath support Global Cache support Flexible to create User Defined Node Integration API support for custom solutions MQ Technical Conference Message Assembly (Input/Output) Message LocalEnvironment (Global)Environment ExceptionList Input/Output Message LocalEnvironment (Global)
2 Environment ExceptionList } MbMessage Objects MQ Technical Conference ESQL to Java Correlation Name Mapping Mapping Sample Java code ESQL correlation name Java accessor from MbMessageAssembly InputRoot getMessage().getRootElement() InputBody getMessage().getRootElement().getLastChi ld() InputLocalEnvironment getLocalEnvironment().getRootElement() Environment getGlobalEnvironment().getRootElement() InputExceptionList getExceptionList().getRootElement() MbMessage inMessage = (); MbElement inputRoot = (); MbElement inputbody = ().getLastChild(); MbElement inputLocalEnvironment = ().getRootElement(); MbElement environment = ().
3 GetRootElement(); MbElement inputExceptionList = ().getRootElement(); MQ Technical Conference Each element in the tree is represented by MbElement object Java MbElement object = ESQL Reference Variable ESQL DECLARE ipRef REFERENCE TO ; Java MbElement ipRef = ().getRootElement().getFirstElementByPat h("XMLNSC/Invoice"); MQ Technical Conference Traversing Message tree using MbElement MbElement getParent() getPreviousSibling() getNextSibling() getFirstChild() getLastChild() ESQL MOVE ipRef NEXTSIBLING; MOVE ipRef PREVIOUSSIBLING; Java ipRef = (); ipRef = (); MQ Technical Conference Steps from JavaCompute Node to Code Open Java Select Java Project Name Class Choose Template Code Class MQ Technical Conference Sample Auto generated code MQ Technical Conference Deployment JAR files (including external third party jar files) are added automatically to the BAR file; No explicit selection is required.
4 JAR files are searched from the following path while deployment Java project Workspace Local File system If JAR file is too large and is creating concerns in deployment, move those jar files to shared classes directory. MQ Technical Conference ESQL Module Vs Java Node Every node class must extend MbJavaComputeNode class Must implement evaluate() method Names are case sensitive ESQL CREATE COMPUTE MODULE JSONMockService_Compute1 CREATE FUNCTION Main() RETURNS BOOLEAN BEGIN RETURN TRUE; END; END MODULE; Java public class JSONMockService_Compute1 extends MbJavaComputeNode { public void evaluate(MbMessageAssembly inAssembly) throws MbException { } } MQ Technical Conference Variable Declaration and Assignment Declaration Assignment ESQL DECLARE I INTEGER 1; DECLARE status CHARACTER; DECLARE isFound BOOLEAN; Java int i = 1; String status.
5 Boolean isFound; ESQL SET I = 10; SET status = 'Success'; SET isFound = FALSE; Java i = 10; status = "Success"; isFound = false; MQ Technical Conference External Variable aka UDP No Declaration required in Java Use method getUserDefinedAttribute() directly to get the value Pass UDP name as parameter to getUserDefinedAttribute() method Cast the values as per the definition ESQL DECLARE WaitTime EXTERNAL INTEGER -1; DECLARE SchemaName EXTERNAL CHARACTER NULL; DECLARE SendEmail EXTERNAL BOOLEAN FALSE; Java int waitTime = (Integer) getUserDefinedAttribute("WaitTime"); String schemaName = (String) getUserDefinedAttribute("SchemaName"); boolean sendEmail = (Boolean) getUserDefinedAttribute("SendEmail"); MQ Technical Conference Shared variables No shared variables in JCN ; Use Globalcache instead Need additional configuration to setup and enable GlobalCache Use appropriate method to insert, update, select and remove values from Global Cache Ideal for sharing data across multiple integration servers or nodes Lifetime of the cache data is configurable using MbSessionPolicy Java MbGlobalMap globalMap = ("MyMap"); MbGlobalMapSessionPolicy policy = new MbGlobalMapSessionPolicy(3600); MbGlobalMap globalMap1 = ("MyMapWithSessionPolicy",policy); if(!)
6 ("Key1")) { ("key1", "value1"); } if( ("Key1")) { ("key1"); } if( ("Key1")) { ("Key1", "25000"); } if ( ("Key1")) { ("Key1"); } MQ Technical Conference Operators Arithmetic Operators Relational Operators ESQL Java + (Addition) + (Addition) - (Subtraction) - (Subtraction) * (Multiplication) * (Multiplication) / (Division) / (Division) MOD (Modulus) % (Modulus) ESQL Java = (equal to) == (equal to) <> (not equal to) != (not equal to) MQ Technical Conference Logical Operators Assignment Operators Concatenation Operators ESQL Java AND (logical and) && (logical and) OR (logical or) || (logical or) NOT (logical not) !
7 (logical not) ESQL Java = = SET I = I + 10; i = i + 10; i += 1; ESQL Java || + MQ Technical Conference Conditional Statements ESQL Java IF I = 10 THEN END IF; if (i == 10) { } IF I = 10 THEN ELSE END IF; if (i == 10) { }else { } IF I = 10 THEN ELSEIF I > 10 THEN ELSE END IF; if (i == 10) { }else if (i > 10) { } else { } MQ Technical Conference Only simple case is supported ESQL Java CASE UPPER(FIELDVALUE(ipRef)) WHEN 'A' THEN WHEN 'B' THEN ELSE END CASE; switch ( ().toUpperCase()) { case "A": break; case "B": break; default: break; } MQ Technical Conference Looping Statements Loop ESQL Java while Loop WHILE LASTMOVE(ipRef) DO MOVE ipRef NEXTSIBLING; DELETE PREVIOUSSIBLING OF ipRef; END WHILE; while (ipRef !)
8 = null) { ipRef = (); ().delete(); } REPEAT MOVE ipRef NEXTSIBLING; UNTIL FIELDNAME(ipRef) = 'REPEATING_ELEMENT' END REPEAT; do { ipRef = (); } while (ipRef != null && ! ().equals("REPEATING_ELEMENT")); For loop FOR payRef AS [] DO SET name = ||' ' || ; END FOR; for (MbElement payRef = ("Customer"); (payRef != null && payRef .getName().equals("Customer")); payRef = payRef .getNextSibling()) { name = ("FirstName") + " " + ("LastName"); } MQ Technical Conference Labelled Loop ESQL Java while Loop X:WHILE LASTMOVE(ipRef) DO IF = 100 THEN MOVE ipRef NEXTSIBLING; ITERATE X; ELSEIF = 200 THEN LEAVE X; END IF; MOVE ipRef NEXTSIBLING; END WHILE; X:while (ipRef !
9 = null) { if ((int) ("Id").getValue() == 100) { ipRef = (); continue X; } else if((int) ("Id").getValue() == 200) { break X; } ipRef = (); } Allowed Allowed. Similar to above For loop Not Allowed Allowed. Similar to above MQ Technical Conference Reading the input message Use MbElement to point to the parsed logical part of the tree Cast values to appropriate type Parser specific fields like , are retrieved using getSpecificType() method ESQL Java FIELDNAME(ipRef) () FIELDVALUE(ipRef) () FIELDNAMESPACE(ipRef) () FIELDTYPE(ipRef) () () () MQ Technical Conference Creating the output message ESQL CREATE LASTCHILD OF OutputRoot DOMAIN('XMLNSC') NAME 'XMLNSC'; CREATE FIELD ; DECLARE opRef REFERENCE TO ; DECLARE ipRef REFERENCE TO ; SET = || ' ' || ; Java MbMessage outMessage = new MbMessage().
10 MbElement outputRoot = (); MbElement inputRoot = ().getRootElement(); MbElement opRef = ( ).createElementAsFirstChild( , "InvoiceResponse", null); MbElement ipRef = ("XMLNSC/InvoiceRequest"); ("./?Customer/?Name[set-value('"+ ("FirstName")+" "+ ("LastName")+"')]"); outAssembly = new MbMessageAssembly(inAssembly, outMessage); MQ Technical Conference Examples ESQL Java SET = 'Hello World'; MbElement outRoot = (); MbElement outJsonRoot = outRoot .createElementAsLastChild( ); MbElement outJsonData = ( , , null); MbElement outJsonTest = ( , "Message", "Hello World"); CREATE FIELD IDENTITY ( )Data; CREATE LASTCHILD OF TYPE NameValue NAME 'Item' VALUE 'valueA'; CREATE LASTCHILD OF TYPE NameValue NAME 'Item' VALUE 'valueB'; MbElement outRoot = (); MbElement outJsonData = ( , "Data", null); ( , "Item", "valueA"); ( , "Item", "valueB"); MQ Technical Conference Examples ESQL Java SET OutputRoot = InputRoot; MbMessage outMessage = new MbMessage(inMessage); SET OutputLocalEnvironment = InputLocalEnvironment; MbMessage outLocalMessage = new MbMessage( ()); SET =.