WebSphere Message Broker, Version 8.0.0.7
Operating Systems: AIX, HP-Itanium, Linux, Solaris, Windows, z/OS
See information about the latest product version
See information about the latest product version
Recording and replaying data with a CMP application
You can create CMP applications to examine and replay the data that you have recorded and stored by using record and replay.
Before you start:
Read the concept topic Record and replay.
The DataCaptureProxy class programmatically
represents the recorded data. For more information
about where the DataCaptureProxy is located in the CMP class hierarchy,
see Navigating brokers and broker resources in a CMP application. Retrieved
data is contained in DataCaptureEntry objects.
For further information about these objects and how to use them, see the CMP API.
The following example
shows how to retrieve data from an execution group by using the DataCaptureProxy
API.
BrokerProxy bp = null;
try {
BrokerProxy.enableAdministrationAPITracing("C:\\AdminTrace.txt");
bp = BrokerProxy.getLocalInstance("WEB");
ExecutionGroupProxy eg = bp.getExecutionGroupByName("default");
Properties newFilterProps = new Properties();
newFilterProps.setProperty(DataCaptureEntry.PROPERTY_BROKER_NAME, "WEB");
DataCaptureEntry filterMessage = new DataCaptureEntry(newFilterProps);
DataCaptureProxy dcp = eg.getDataCapture("MYDATA", filterMessage);
String output = dcp.getDataCaptureEntryAsXml(1);
System.out.println("XML output: "+output);
int messNo = 0;
Enumeration <DataCaptureEntry> dceE = dcp.elements();
while (dceE.hasMoreElements()) {
DataCaptureEntry dce = dceE.nextElement();
System.out.print("\nMessage: "+messNo++);
Properties props = dce.getAllProperties();
String[] columns = dce.getPropertyNames();
for (int i = 0; i < columns.length; i++) {
System.out.print("\nProperty: "+columns[i]+ " Value: "+props.getProperty(columns[i]));
}
}
} catch (ConfigManagerProxyLoggedException e) {
e.printStackTrace();
} catch (ConfigManagerProxyPropertyNotInitializedException e) {
e.printStackTrace();
} finally {
if(bp != null) {
bp.disconnect();
}
}
The following example shows how to replay data.
BrokerProxy brokerProxy = null;
try {
// DataCaptureStore containing message to replay
String dataCaptureStore = "MyStore";
// ID of message to replay
String replayMsgId = "0123456789ABCDEF";
// DataDestination to replay message to
String dataDestination = "ReplayDestination";
// EG to replay
String replayEG = "MyExecutionGroupName";
Properties dataCaptureProps = new Properties();
// Set the message to replay
dataCaptureProps.setProperty(DataCaptureEntry.PROPERTY_WMBMSG_KEY, replayMsgId);
// Set the destination to replay to
dataCaptureProps.setProperty(AttributeConstants.DATACAPTURE_REPLAY, dataDestination);
DataCaptureEntry dataCaptureEntry = new DataCaptureEntry(dataCaptureProps );
brokerProxy = WebAdminBrokerProxy.getLocalInstance("MB8BROKER");
ExecutionGroupProxy egProxy = brokerProxy.getExecutionGroupByName(replayEG);
// Submit request to EG to actually do replay
DataCaptureProxy dataCaptureProxy = egProxy.getDataCapture(dataCaptureStore, dataCaptureEntry);
dataCaptureProxy.hasBeenPopulatedByBroker(true);
String responseBody = dataCaptureProxy.getDataCaptureEntryAsXml(1);
} catch (Exception e) {
// TODO: Handle Exception
} finally {
if (brokerProxy != null) {
brokerProxy.disconnect();
}
}