WebSphere Message Brokers
File: ar25251_9_
Writer: Cerys Giddings

Task topic

This build: July 31, 2007 21:36:26

Develop a message flow using a user-defined ESQL function

Before you start
This is the ninth stage of the scenario to perform simple message enrichment. This topic demonstrates how to develop a message flow using a user-defined ESQL function. It also involves developing corresponding message models and instance documents.
  1. In the COMPLEX message definition, in namespace www.complex.net, create messages called addev5in and addev5out, which have the following structures:
    addev5in
       value1                    (xsd:decimal) local element
       operator                 (xsd:string) local element
       value2                    (xsd:decimal) local element
       rate                        (xsd:decimal) local element
    addev5out
       grossvalue               (xsd:decimal) local element
       netvalue                   (xsd:decimal) local element
  2. Create a message flow called addev5, which contains the following mapping: MQInput> Mapping> MQOutput.
  3. Open the map and select addev5in as the source and addev5out as the target.
  4. In the MAPPING3_COMPLEX_flows project, create an ESQL file called addev5 and put these functions in it:
    CREATE FUNCTION calcGrossvalue(IN value1 DECIMAL, IN operator CHAR,
     IN value2 DECIMAL) RETURNS DECIMAL
              BEGIN
                  DECLARE outval DECIMAL;
                  CASE operator
                  WHEN 'PLUS' THEN
                      SET outval = value1 + value2;
                  WHEN 'MINUS' THEN
                      SET outval = value1 - value2;
                  WHEN 'MULTIPLY' THEN
                      SET outval = value1 * value2;
                  WHEN 'DIVIDE' THEN
                      SET outval = value1 / value2;
                  ELSE
                      THROW USER EXCEPTION MESSAGE 2949 VALUES('Invalid Operator', operator);
                      SET outval = -999999;
                  END CASE;
                RETURN outval;
              END;
    CREATE FUNCTION calcNetvalue(IN value1 DECIMAL, IN operator CHAR, IN value2 DECIMAL,
     IN rate DECIMAL) RETURNS DECIMAL
        BEGIN
            DECLARE grossvalue DECIMAL;
            SET grossvalue=calcGrossvalue(value1, operator, value2);
            RETURN (grossvalue * rate );
        END;
  5. In the Message Mapping editor Spreadsheet pane, expand the message and select grossvalue.
  6. In the Expression pane, enter the expression:
    esql:calcGrossvalue($source/comp:addev5in/value1, 
    $source/comp:addev5in/operator, 
    $source/comp:addev5in/value2)
  7. Select the target netvalue, and in the Expression pane, enter the following expression:
    esql:calcNetvalue($source/comp:addev5in/value1, 
    $source/comp:addev5in/operator, 
    $source/comp:addev5in/value2, 
    $source/comp:addev5in/rate)
  8. Expand the Properties tree and set the following values:
    MessageType      |       'addev5out'
  9. Create the following instance messages, with appropriate RFH2 headers:
    <comp:addev5in xmlns:comp="http://www.complex.net">
    <value1>125.32</value1>
    <operator>PLUS</operator>
    <value2>25.86</value2>
    <rate>0.60</rate>
    </comp:addev5in>
    <comp:addev5in xmlns:comp="http://www.complex.net">
    <value1>118.00</value1>
    <operator>MINUS</operator>
    <value2>245.01</value2>
    <rate>0.30</rate>
    </comp:addev5in>
    <comp:addev5in xmlns:comp="http://www.complex.net">
    <value1>254.02</value1>
    <operator>MULTIPLY</operator>
    <value2>3.21</value2>
    <rate>0.75</rate>
    </comp:addev5in>
    <comp:addev5in xmlns:comp="http://www.complex.net">
    <value1>1456.33</value1>
    <operator>DIVIDE</operator>
    <value2>18.58</value2>
    <rate>0.92</rate>
    </comp:addev5in>
    <comp:addev5in xmlns:comp="http://www.complex.net">
    <value1>254.02</value1>
    <operator>MOD</operator>
    <value2>3.21</value2>
    <rate>0.75</rate>
    </comp:addev5in>
You have created the following resources:
Now deploy the message set and message flow.

Deploy the message set and message flow

This is the tenth stage of the scenario to perform simple message enrichment. This topic demonstrates how to deploy the message set and message flow and run the instance messages through the broker.
  1. Create a bar file called addev5.
  2. Add the message set MAPPING3_COMPLEX_messages and the message flow addev5 to the bar file.
  3. Deploy the bar file to the broker.
  4. Put the instance documents on the input queue.
The output messages look like this:
<comp:addev5out xmlns:comp="http://www.complex.net">
<grossvalue>151.18</grossvalue>
<netvalue>90.708</netvalue>
</comp:addev5out>
<comp:addev5out xmlns:comp="http://www.complex.net">
<grossvalue>-127.01</grossvalue>
<netvalue>-38.103</netvalue>
</comp:addev5out>
<comp:addev5out xmlns:comp="http://www.complex.net">
<grossvalue>815.4042</grossvalue>
<netvalue>611.55315</netvalue>
</comp:addev5out>
<comp:addev5out xmlns:comp="http://www.complex.net">
<grossvalue>78.38159311087190527448869752421959</grossvalue>
<netvalue>72.11106566200215285252960172228202</netvalue>
</comp:addev5out>
If there is no message output look for an entry in the event log like this:
BIP2949 ( BRK.default ) A user generated ESQL exception has been thrown. The additional 
information provided with this exception is: ''Invalid Operator'' ''MOD'' 
'addev5.Mapping.ComIbmCompute' '%5' '%6' '%7' '%8' '%9' '%10' '%11' 
This exception was thrown by a THROW EXCEPTION statement. This is the normal behavior of the THROW statement; this is a user-generated exception, so the user action is determined by the message flow and the type of exception that is thrown.
Notices | Trademarks | Downloads | Library | Support | Feedback

Copyright IBM Corporation 1999, 2007Copyright IBM Corporation 1999, 2007. All Rights Reserved.
This build: July 31, 2007 21:36:26

ar25251_9_ This topic's URL is: