Author |
Message
|
John |
Posted: Tue Oct 22, 2002 10:44 am Post subject: To output a message count |
|
|
Novice
Joined: 21 Apr 2002 Posts: 23
|
I need to output a message count in WMQI version 2.0.1 . Below is my message flow:
Input Node --> Filter --> Output Node
Need to produce the following output:
<?xml version="1.0" ?>
<Messages>
<Total>ouput the total count</Total>
</Messages>
Input Message (value 'E' in Field3 indicates the end of messages sent)
Field1
Field2
Field3
Created a database in DB2 called Total, table Name = number, column Name = count
Filter Node configuration:
SET OutputRoot.XML.(XML.XmlDecl) = '';
SET OutputRoot.XML.(XML.XmlDecl).(XML.Version) = '1.0';
DECLARE J INTEGER;
DECLARE K INTEGER;
SET K = 0;
SET J = InputRoot.MRM.Field3;
IF J = 'A' THEN
SET K = K + 1;
END IF;
SET J = InputRoot.MRM.Field3;
IF J = 'B' THEN
SET K = K + 1;
END IF;
SET OutputRoot.Total = THE(SELECT number.count FROM Database.Total);
Result:
messages being sent to the failure queue of the compute node.
Your input is greatly appreciated. Thank you. |
|
Back to top |
|
 |
kirani |
Posted: Wed Oct 23, 2002 9:15 pm Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
John,
In a filter node check for last message by checking Field3.
Code: |
InputBody.Field3 = 'E'
|
In a database node increment your counter. Connect this node to the false terminal of your Filter node.
Attach a compute node to the true terminal of Filter node, which will generate output message for you. First retrieve the total count from database table. You could use ESQL code similar to this to create output message.
Code: |
-- Your select statement goes here
DECLARE CNT INT;
SET CNT = THE (SELECT ITEM tbl.Count from Database.Total as tbl);
SET OutputRoot.XML.(XML.XmlDecl) = '';
SET OutputRoot.XML.(XML.XmlDecl).(XML.Version) = '1.0';
SET OutputRoot.XML.Messages.TotaL = CNT;
|
I hope this helps. Good luck! _________________ Kiran
IBM Cert. Solution Designer & System Administrator - WBIMB V5
IBM Cert. Solutions Expert - WMQI
IBM Cert. Specialist - WMQI, MQSeries
IBM Cert. Developer - MQSeries
|
|
Back to top |
|
 |
John |
Posted: Thu Oct 24, 2002 6:52 pm Post subject: |
|
|
Novice
Joined: 21 Apr 2002 Posts: 23
|
Thanks Kiran for your reply. I added a database node according to your suggestion.
Database node configuration:
Input (added)
Message Set: MSname
Output (added)
datasource name = Total
Table name = number
Any additional SQL configuration needed?
Would you provide the configuration of the database node? Thanks again. |
|
Back to top |
|
 |
kirani |
Posted: Thu Oct 24, 2002 9:11 pm Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
John,
First you will have to create an ODBC connection on broker machine to accesss your database tables from message flows. Make sure your dbuser have permissions to query/insert into number table. No additional configuration is required for database node.
You will find some sample code in Chapter 9 of following redbook:
http://www.redbooks.ibm.com/pubs/pdfs/redbooks/sg246579.pdf _________________ Kiran
IBM Cert. Solution Designer & System Administrator - WBIMB V5
IBM Cert. Solutions Expert - WMQI
IBM Cert. Specialist - WMQI, MQSeries
IBM Cert. Developer - MQSeries
|
|
Back to top |
|
 |
John |
Posted: Fri Oct 25, 2002 6:42 pm Post subject: |
|
|
Novice
Joined: 21 Apr 2002 Posts: 23
|
Hi Kiran,
This is what I have so far:
Input -> Filter (1)->(False) -> DatabaseNode
(2)->(True) -> ComputeNode -> Output
Filter Node ESQL:
InputBody.Field3 = 'E'
ComputeNode ESQL:
DECLARE CNT INT;
SET CNT = THE (SELECT ITEM tbl.Count from Database.Total as tbl);
SET OutputRoot.XML.(XML.XmlDecl) = '';
SET OutputRoot.XML.(XML.XmlDecl).(XML.Version) = '1.0';
SET OutputRoot.XML.Messages.TotaL = CNT;
I have also create an ODBC connection on broker machine.
When I sent a message with Field3 = 'A' (i.e. a non-E)
Nothing happen.
When I send a message with Field3 = 'E'
The error message is - compute node thrwoing exception. The follow error occured execution SQL statement &3 insert where &4'
Please help. Thank you. |
|
Back to top |
|
 |
kirani |
Posted: Sat Oct 26, 2002 8:05 pm Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
Hi John,
You will have to do something similar to following.
Let's say MRM.Field3 contains following domain values:
F - First message
L - Last message
D - Detail message
You message flow will look similar to this
MQInput(out)->Filter1(true)->Database1
Filter1(false)->Filter2(true)->Compute2
Filter2(false)->Compute1->MQOutput1
Filter1: Checks for first message using following ESQL
Code: |
RETURN(Body.Field3 = 'F');
|
Database1 : Inserts a record into this table.
Code: |
INSERT INTO Database.COUNTER(TCNT) VALUES (0);
|
Filter2: Checks for Last message & retrieves the counter value from database
Code: |
SET Environment.Variables.Counter = THE ( SELECT ITEM tbl.TCNT FROM Database.COUNTER as tbl);
RETURN(Body.Data.Field = 'L');
|
Compute1: Process Detail message and increment the counter by 1
Code: |
-- Process your Data Detail message here
UPDATE Database.COUNTER as tbl
SET TCNT = (Environment.Variables.Counter + 1);
|
Compute2: Process last message and create output XML message.
Code: |
SET OutputRoot.XML.(XML.XmlDecl).(XML.Version) = '1.0';
SET OutputRoot.XML.Messages.Total = Environment.Variables.Counter;
|
MQOutput1: Set output queue name here.
Hope this gives you some idea on how to output Total Count from your message flow. Don't forget to connect output nodes to your message flow. _________________ Kiran
IBM Cert. Solution Designer & System Administrator - WBIMB V5
IBM Cert. Solutions Expert - WMQI
IBM Cert. Specialist - WMQI, MQSeries
IBM Cert. Developer - MQSeries
|
|
Back to top |
|
 |
John |
Posted: Sun Oct 27, 2002 8:42 pm Post subject: |
|
|
Novice
Joined: 21 Apr 2002 Posts: 23
|
Hi Kiran,
Look like I am confuse . Could you please explain the entire logic of the flow?
Could you please elaborate on the ESQL codes(ver2.0.1) for Filter1 and Filter2. Also should MQOutput1 be connected to Compute2 or Compute1?
Is the Detail message(MRM field3) refers to any other message, except first and last?
Last but not least, thanks for your help and patience. |
|
Back to top |
|
 |
kirani |
Posted: Mon Oct 28, 2002 8:44 pm Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
John,
Your processing logic sounds like a batch processing requirement. In a typical batch processing there is an indicator that indicates the first record/message (header record) and there is an end of batch record (Trailer record). In your case, when you get trailer record (Field3='E') you are supposed to create XML Total Count message. Pl Correct me if my understanding is incorrect here.
In my example code, I tried to demonstrate batch processing. Your psudo code would be:
Code: |
Get message from the input queue:
If (first message) then
Insert a record into database table with totalcount = 0 for this batach.
else if (last message) then
Retrieve total count from database table and create Total count XML message.
else
-- Process the message
-- Update the database counter by 1.
end if;
end if;
|
I hope everything is clear till now!
In my message flow,
Filter1 is checking for First message (header record). If it is a header record, I am inserting a record into database with total count = 0. In real world you should have some primary key based on which you are going to refer to different row, for example, Batch number.
In Filter2 node we are first retrieving the counter from db and then checking whether it's last message or not. If it is a last message then the message will be propagated to the True terminal of the Filter node, which is connected to Compte 2 node.
In Compute1 node, process your detail message and then increment the database counter by 1.
In Compute2 node, we create Total count XML message.
This explains the main processing of above message flow. You will have to configure remaining part of this as per your requirement. If you want detail message to be written to some output queue then you will have to connect MQOutput node to Compute1 node.
This code is for WMQI 2.1. If you want to use it for MQSI 2.0.1 then you will have to use WKSPACE parser instead of Environment tree.
I hope this clears everything! _________________ Kiran
IBM Cert. Solution Designer & System Administrator - WBIMB V5
IBM Cert. Solutions Expert - WMQI
IBM Cert. Specialist - WMQI, MQSeries
IBM Cert. Developer - MQSeries
|
|
Back to top |
|
 |
John |
Posted: Mon Oct 28, 2002 10:32 pm Post subject: |
|
|
Novice
Joined: 21 Apr 2002 Posts: 23
|
Hi Kiran,
Yes this is a batch processing, except there is NO first record. The last record is indicated by field3='E'.
I am in a team with Sagwa99, and we were working backward from ver2.1 to 2.0.1 in vain. You had responded to our posts suggeted the use of WKSPACE parser. We sincerely hope that you could walk us thru the problem with WKSPACE parser.
Thanks again for you help and patience. |
|
Back to top |
|
 |
kirani |
Posted: Tue Oct 29, 2002 10:35 pm Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
well, you got to have some starting point from where you begin counting the number of messages. correct?!
Please download the supportpac IA0E (WKSPACE Parser) from following URL,
http://www-3.ibm.com/software/ts/mqseries/txppacs/ia0e.html
In one of the PDF file they have an example of how to use WKSPACE parser.
If using MQSI 2.0.1, you will have to use following code:
Filter1:
Code: |
(Body.Field3 = 'F')
|
Filter2:
Code: |
SET Root.WKSPACE.Variables.Counter = THE ( SELECT ITEM tbl.TCNT FROM Database.COUNTER as tbl);
(Body.Data.Field = 'L')
|
Replace Environment
Compute1:
Code: |
-- Process your Data Detail message here
UPDATE Database.COUNTER as tbl
SET TCNT = (InputRoot.WKSPACE.Variables.Counter + 1);
|
Compute2:
Code: |
SET OutputRoot.XML.(XML.XmlDecl).(XML.Version) = '1.0';
SET OutputRoot.XML.Messages.Total = InputRoot.WKSPACE.Variables.Counter;
|
Code in Database1 node remains same.
I have not used MQSI 2.0.1 for more than a year, so I don't know whether this code will work as-is, you might have to change this code a little bit. _________________ Kiran
IBM Cert. Solution Designer & System Administrator - WBIMB V5
IBM Cert. Solutions Expert - WMQI
IBM Cert. Specialist - WMQI, MQSeries
IBM Cert. Developer - MQSeries
|
|
Back to top |
|
 |
|