メッセージのツリー表記は通常、入力ビット・ストリームより大きくなります。 大規模なメッセージ・ツリーの操作には多くのストレージが必要ですが、ブローカーのストレージ・ロードを削減するために役立つ Java™ メソッドをコーディングできます。
大規模なメッセージ・ツリーの操作には多くのストレージが必要です。 繰り返し構造からなる大規模メッセージを扱うメッセージ・フローを設計する場合、ブローカーのストレージ・ロードを削減するための Java メソッドをコーディングできます。このメソッドはメッセージへのランダム・アクセスと順次アクセスの両方をサポートしますが、一度にメッセージ全体にアクセスする必要がないことを想定します。
このような Java メソッドによって、 ブローカーはメッセージに限定的な構文解析を実行して、単一レコードを表すメッセージ・ツリーのその部分だけを一度にストレージ内に保持します。 処理で 1 つのレコードから次のレコードに移るときに情報を保持しなければならない場合 (例えば、注文に含まれる各品目の繰り返し構造から合計価格を計算する場合)、いくつかの Java 変数を宣言し、初期化して保持することができます。あるいは、メッセージ・ツリー内の他の場所 (例えばローカル環境内) に値を保存する方法もあります。
この技法によって、ブローカーによるメモリーの使用量が減少し、入出力ビット・ストリームの全体と、ただ 1 つのレコードのメッセージ・ツリーを保持するために必要な容量だけが必要になります。 この技法を使えば、メッセージ内での繰り返し回数が少ない場合でもメモリーが節約されます。 ブローカーは限定的に構文解析するだけでよく、 メッセージ・ツリー内の指定された部分だけをビット・ストリームの対応する部分との間で解析します。
MbOutputTerminal.propagate(MbMessageAssembly, true)
このプロセスによって、メッセージ・ツリー・リソースとパーサーは、次の出力メッセージ反復でリカバリーと再利用ができます。実際のメッセージ処理の必要に合わせて、 上記の手法を独自に変えることもできます。
次のサンプル Java コードに、多数の反復レコードを持つ大規模入力メッセージを構文解析する方法を示します。ここで、各レコードは個別の出力メッセージとして伝搬されるものとします。
<TestCase>
<Record><Field1>A</Field1><Field2>B</Field2><Field3>C</Field3><Field4>D</Field4><Field5>EA</Field5></Record>
<Record><Field1>A</Field1><Field2>B</Field2><Field3>C</Field3><Field4>D</Field4><Field5>EA</Field5></Record>
<Record><Field1>A</Field1><Field2>B</Field2><Field3>C</Field3><Field4>D</Field4><Field5>EA</Field5></Record>
<Record><Field1>A</Field1><Field2>B</Field2><Field3>C</Field3><Field4>D</Field4><Field5>EA</Field5></Record>
....
</TestCase>
//Make a modifiable MbMessage based on the input message passed in on the inAssembly.
MbMessage clonedInMessage = new MbMessage(inAssembly.getMessage());
//Now partially parse the cloned input message one record at a time.
MbElement inputRootElement = clonedInMessage.getRootElement();
MbElement inputPropertiesElement = inputRootElement.getFirstElementByPath("Properties");
MbElement inputMQMDElement = inputRootElement.getFirstElementByPath("MQMD");
MbElement inputXMLNSCElement = inputRootElement.getFirstElementByPath("XMLNSC");
MbElement inputXMLNSCRootTagElement = inputXMLNSCElement.getFirstChild(); //Move to the TestCase tag
MbElement currentInputRecord = inputXMLNSCRootTagElement.getFirstChild(); //Move to the Record tag
while(currentInputRecord != null)
{
// Create a new output message for the record that we are going to be propagate.
MbMessage outputMessage = new MbMessage();
MbMessageAssembly outAssembly = new MbMessageAssembly(inAssembly, outputMessage);
//Create new parsers folders in the output message.
MbElement outputRootElement = outputMessage.getRootElement();
MbElement outputPropertiesElement = outputRootElement.createElementAsLastChild(inputPropertiesElement.getParserClassName());
MbElement outputMQMDElement = outputRootElement.createElementAsLastChild(inputMQMDElement.getParserClassName());
MbElement outputXMLNSCElement = outputRootElement.createElementAsLastChild(inputXMLNSCElement.getParserClassName());
//Create the root tag in the output XMLNSC folder that will be used for this output record.
MbElement outputXMLNSCRootTag = outputXMLNSCElement.createElementAsLastChild(MbElement.TYPE_NAME, "TestCase", null);
//Create the record tag for this output message instance.
MbElement currentOutputRecord = outputXMLNSCRootTag.createElementAsLastChild(MbElement.TYPE_NAME, "Record", null);
//Copy the Properties Folder, MQMD header, and the current record.
outputPropertiesElement.copyElementTree(inputPropertiesElement);
outputMQMDElement.copyElementTree(inputMQMDElement);
currentOutputRecord.copyElementTree(currentInputRecord);
//Propagate this message, requesting that the output message assembly be cleared after propagation.
out.propagate(outAssembly, true);
//Note: You do not need to call clearMessage on outputMessage because it was cleared after the propagation.
//Take a reference to the current record so that it can be deleted.
MbElement previousInputRecord = currentInputRecord;
//Now move to the next input record ready for processing.
currentInputRecord = currentInputRecord.getNextSibling();
//Now that we have moved to the next sibling, delete the input record that has already been processed.
previousInputRecord.delete();
}
<Record>
<Field1>A</Field1>
<Field2>B</Field2>
<Field3>C</Field3>
<Field4>D</Field4>
<Field5>E</Field5>
</Record>