Auditing And Logging Messages Using Events in IBM Integration Bus \ WebSphere Message Broker - Middleware News
In IBM Integration Bus \WebSphere Message Broker Message Flows , you
can Audit and Log data using database procedures or SQL statements and
calling them in ESQL Scripts or in Java Compute Nodes, but this Time in
this tutorial you can Audit and log the data using Events.
We have two types of events:
- Transaction Events : Transaction start, Transaction end and Transaction Rollback and they can omitted by Input Nodes [ex. HTTPInput, SOAPInput, MQInput,...etc].
- Terminal Events : and It is available for All Nodes in the Message Flow.
Before We start we must Know that Events are Published to Topic With String Format :
"$SYS/Broker//Monitoring//" ,
so we well create MQ Object to listen on this topic with "Subscription object".
Agenda :
-
Create Application with MonitoringService_MsgFlow.
-
Create Message Set and Event Message definition file.
-
Create Message Flow SubscribeAuditData to Fetch published Events From Queue.
-
Create Local Queues for the Sample Using WebSphere MQ Explorer.
-
Create Subscription to Subscribe the events publish in Topic used in Event process.
-
Test And Send The Data.
- Open IBM Integration Bus Toolkit , and Choose Integration Development prespective.
-
Right Click on Application Development workspace New-> Application or from File -> New - Application.
- In Application Name : "monitoring-sample", "monitoring-sample" Application is created.
-
Right Click on "monitoring-sample" Application -> New -> Message Flow.
-
In Message Flow Name : "MonitoringService_MsgFlow" and check on Broker Schema and type in Schema TextBox "provider", then Click "Finish".
-
From The Toolbar, File -> New ->other, then Expand "Integration Bus Message Set Development"->Message Set, Then Click Next.
- In Message Set Name , And Project Name Give them "MonitoringSample_MsgSet", Then Click "Finish".
-
Right Click on the Application and Choose "Project References" tab.
- Check on "MonitoringSample_MsgSet" Project To make it Part for the Application.
-
Expand "Message Sets" of the Application and Right Click on "MonitoringSample_MsgSet" ->New->Message Definition File From ->IBM Supplied Message.
-
From the Menu Choose "IBM Integration Bus Monitoring Event" then Click "Finish".
-
Open The Message Flow "MonitoringService_MsgFlow" Then put : The Nodes :
Node Type: Properties Wire MQ Input - Queue Name : TEST_QUEUE.IN
- Message Domain : XMLNSC
- Node Name :TEST_QUEUE.IN
- Out Terminal -> In Process Message Compute
- Failure + catch Terminal To Error Handler Compute Node.
Compute Node - Module Name : ProcessMessage_Compute
- Node Name : Process Message
- Out Termainl -> In MQ Output Node
MQ Output - Queue Name : TEST_QUEUE.OUT
- Node Name : TEST _QUEUE.OUT
MQ Error - Queue Name : QUEUE_ERROR.OUT
- Node Name : QUEUE_ERROR.OUT
Compute Node - Module Name : HandleErrorCompute
- Node Name : Error Handler Compute
- Out Terminal MQ Error Node.
- Right Click on "Process Message" Compute Node Then Click on "Properties".
- Go To "monitoring-sample" , right click -> New -> ESQL File.
-
Type File Name : "ErrorHandler.ESQL"
-
Type The Code Below in the File :
BROKER SCHEMA utilCREATE COMPUTE MODULE ErrorHandler_ComputeCREATE FUNCTION Main() RETURNS BOOLEANBEGINSET OutputRoot.XMLNC.result.result = InputExceptionList;RETURN TRUE;END;END MODULE;
- Add it To Error Handler Compute Node.
- Create Anther ESQL File With Name ProcessMessage.ESQL
-
Add This Code to it :
CREATE COMPUTE MODULE MonitoringService_MsgFlow_ComputeCREATE FUNCTION Main() RETURNS BOOLEANBEGINCALL CopyMessageHeaders();CALL CopyEntireMessage();SET Environment.employee = InputRoot.XMLNSC.employee;RETURN TRUE;END;CREATE PROCEDURE CopyMessageHeaders() BEGINDECLARE I INTEGER 1;DECLARE J INTEGER;SET J = CARDINALITY(InputRoot.*[]);WHILE I < J DOSET OutputRoot.*[I] = InputRoot.*[I];SET I = I + 1;END WHILE;END;CREATE PROCEDURE CopyEntireMessage() BEGINSET OutputRoot = InputRoot;END;END MODULE;
- Use This ESQL Compute in Proccess Message Node.
-
From "Monitoring" Tab -> Click it to view Event Tables.
- Click "Add" To add new Event.
- Select Event Source "Terminal In".
- In Data Location Click on "Add", Then "Edit".
- In XPath Editor : Type : $Environment/employee, then Press "Finish" , then Press Ok.
- Check on "Include biststream data in payload" and set the Content ->All and Encoding to base64binary.
-
Then Press Ok.
- Create New Message Flow in Broker Schema "util" and Name it with "SubscribeAuditData_MsgFlow".
-
Put the Nodes Like the Following table :
Node Type Properties Wire MQ Input - Node Name : QUEUE_EVENT_SUB
- Queue Name : QUEUE_EVENT_SUB
- Out Terminal -> Input Process Message.
- Failure+Catch Terminals ->Error Handler Compute Node
Compute Node - Node Name : Process Message.
- Module Name : ProcessAuditData_Compute
- Out Terminal : EVENT_QUEUE.OUT
Compute Node - Node Name : Error Handler.
- Module Name : ErrorHandler_Compute
- Out Terminal : QUEUE_ERROR.OUT.
MQ Output - Node Name : EVENT_QUEUE.OUT.
MQ Output - QueueName : QUEUE_ERROR.OUT
- Node Name : QUEUE_ERROR.OUT
- Create New ESQL File And Call it FetchEvent.ESQL.
-
Put this Code Inside.
BROKER SCHEMA utilDECLARE wmb NAMESPACE 'http://www.ibm.com/xmlns/prod/websphere/messagebroker/6.1.0/monitoring/event';CREATE COMPUTE MODULE AuditDataCREATE FUNCTION Main() RETURNS BOOLEANBEGINCALL CopyMessageHeaders();CALL CopyEntireMessage();SET OutputRoot.XMLNSC.ReplyData.wmb:event = OutputRoot.XMLNSC.wmb:event;DECLARE BodyMessageAsBlob BLOB ASBITSTREAM(OutputRoot.XMLNSC.ReplyData CCSID 1208);DECLARE BodyMessageASCHAR CHARACTER CAST(BodyMessageAsBlob AS CHARACTER CCSID 1208);-- You can put any code here if you like to store event in database
DELETE FIELD OutputRoot.XMLNSC.wmb:event;DELETE FIELD OutputRoot.XMLNSC.ReplyData;SET OutputRoot.XMLNSC.Result.MessageData = BodyMessageASCHAR;RETURN TRUE;END;CREATE PROCEDURE CopyMessageHeaders() BEGINDECLARE I INTEGER 1;DECLARE J INTEGER;SET J = CARDINALITY(InputRoot.*[]);WHILE I < J DOSET OutputRoot.*[I] = InputRoot.*[I];SET I = I + 1;END WHILE;END;CREATE PROCEDURE CopyEntireMessage() BEGINSET OutputRoot = InputRoot;END;END MODULE;
- Then , Set This Module to ProcessMessage Compute Node in the Flow.
-
For Error Handler compute Node Set the Moudle the previous Error Handler Compute Module we created before.
- From File ->New->Bar File Then Give it name MontiorSampleBar.bar.
- In Prepare window Choose "monitoring-sample" Application.
- In Build options , check all options and uncheck "Add workspace project source files".
- Click Build and Save.
- Deploy the bar to the Execution group.
-
Open "terminal" or the cmd in IBM Integration Console. then type the command "
mqsichangeflowmonitoring-e -k monitoring-sample -f provider.MonitoringService_MsgFlow -c active
- Open WebSphere MQ Explorer and Open Your Queue Manager, Then Expand Queues
- Right Click on Queues -> New -> Local Queue.
-
In The Name Set : "TEST_QUEUE.IN", Then Next, Then Set "persistent" to "Default presistent". Then Click Finsh.
Do The Similar Step with Queues :
- TEST_QUEUE.OUT. - QUEUE_ERROR.OUT.
- EVENT_QUEUE.OUT. - QEUEU_EVENT_SUB.
-
In WebSphere MQ, Righ Click on "Subscriptions" -> New->Subscription.
Note :
Events are published to the topic with string Format
"$SYS/Broker//Monitoring/ / ",
so we need Subscription object as listener on this topic to subscribed the published events.
- In The Subscription Name : "MONITORING_SUBSCRIPTION".
- Set Topic Name : SYSTEM.BROKER.MB.TOPIC.
-
Set the Topic String : As Format "$SYS/Broker/
/Monitoring/ In Our case:/ "
$SYS/Broker/IB9NODE/Monitoring/default/provider.MonitoringService_MsgFlow.
- Set Destination Queue Manager .
-
Set Destination Name : QUEUE_EVENT_SUB we created above, Then Click Finish.
-
Open "MonitoringService_MsgFlow", right click and "Test", change Body to "Edit as Text", then Copy this Message and paste it:
101 HAmdoon ahmad@taha.com 2014-12-12 AD_VP
very nice,...............
ReplyDeletewww.shayarihishayari.com
www.funmazalo.com
wwwshayarixyz.com
www.everyindia.com