About the .NETCompute Node sample

The .NETCompute Node sample filters, modifies and transforms messages using code that has been written in C#. You can use the .NETCompute node on Windows brokers to construct output messages and interact with Microsoft .NET Framework (.NET) or Component Object Model (COM) applications.

The sample uses .NETCompute nodes whose code has been written in C# and then built into an assembly (with extension .dll) using Microsoft Visual Studio 2010. WebSphere Message Broker installs Templates into Microsoft Visual Studio which provide a basic Evaluate method structure to which a flow developer can then add their own code. This is a similar concept to the Compute node, JavaCompute node and PHPCompute node. Readers of this sample may not have access to a Microsoft Visual Studio installation, so a prebuilt assembly file is provided. This means that even without Microsoft Visual Studio you can still deploy and run the sample. The topic Preparing for the deployment of the .NETCompute node sample describes where the assembly file is located and how it can be used. The sample also provides the C# source code which you can read about here.

Scenario:

A retail company has several stores at separate locations within a city. The stores complete sale transactions throughout the day. Each transaction results in an XML message being routed to an input queue at a central IT office. The stores are also rolling out a customer loyalty program. For every customer registration on the loyalty program, an XML message in a different format (containing the customer's personal details) is sent to the same input queue. The company has decided to use WebSphere Message Broker to process the messages. The routing and transformations used in the solution demonstrate the capabilities of the .NETCompute node.

The message flow used is:

The messages pass through the message flow as follows:

  1. The XML SaleEnvelope messages, and the XML LoyaltyProgram messages, enter the message flow through the ReadMessages node.
  2. The Filter .NETCompute node routes SaleEnvelope messages out of its Alternate terminal (which is wired to the Create .NETCompute node), and along the bottom branch of the message flow. LoyaltyProgram messages are routed out of the Out terminal of the Filter node (which is wired to the Modify .NETCompute node) and along the top branch of the message flow.
  3. The Modify .NETCompute node modifies the LoyaltyProgram message so that it includes a full address that corresponds to the store location where the customer registered for the program. The modified XML message is then written to the queue DOTNET.OUT by the WriteLoyaltyProgramMessage MQOutput node.
  4. The Create .NETCompute node iterates over the data contained in the SaleEnvelope message and for each Item element (which itself is inside the repeating Invoice structure), a Record is created in the output message. The output message is created using the DFDL message domain and represents a Comma Separated Value format. The output message, which is created by the WriteStoreTransactionMessage MQOutput node, contains a separate line representing each Item. The comma separated fields on each line hold values for each Item's properties. The store transaction records are written as a single message containing all the data at the same time.

The sections below include examples of the two different kinds of input test XML messages (SaleEnvelope and LoyaltyProgram). The output messages are included in the Running the sample section.

Input SaleEnvelope test message

<SaleEnvelope>
  <Header>
    <SaleListCount>1</SaleListCount>
  </Header>
  <SaleList>
    <Invoice><Initial>K</Initial>
      <Initial>A</Initial>
      <Surname>Braithwaite</Surname>
      <Item><Code>00</Code>
        <Code>01</Code>
        <Code>02</Code>
        <Description>Twister</Description>
        <Category>Games</Category>
        <Price>00.30</Price>
        <Quantity>01</Quantity>
      </Item>
      <Item>
        <Code>02</Code>
        <Code>03</Code>
        <Code>01</Code>
        <Description>The Times Newspaper</Description>
        <Category>Books and Media</Category>
        <Price>00.20</Price>
        <Quantity>01</Quantity>
      </Item>
      <Balance>00.50</Balance>
      <Currency>Sterling</Currency>
    </Invoice>
    <Invoice>
      <Initial>T</Initial>
      <Initial>J</Initial>
      <Surname>Dunnwin</Surname>
      <Item>
        <Code>04</Code>
        <Code>05</Code>
        <Code>01</Code>
        <Description>The Origin of Species</Description>
        <Category>Books and Media</Category>
        <Price>22.34</Price>
        <Quantity>02</Quantity>
      </Item>
      <Item>
        <Code>06</Code>
        <Code>07</Code>
        <Code>01</Code>
        <Description>Microscope</Description>
        <Category>Miscellaneous</Category>
        <Price>36.20</Price>
        <Quantity>01</Quantity>
      </Item>
      <Balance>81.84</Balance>
      <Currency>Euros</Currency>
    </Invoice>
  </SaleList>
  <Trailer>
    <CompletionTime>12.00.00</CompletionTime>
  </Trailer>
</SaleEnvelope>

Input LoyaltyProgram test message

<LoyaltyProgram
      xmlns:applicant="http://www.example.org/applicant"
      xmlns:store="http://www.example.org/store">
  <applicant:ApplicantDetails>
    <applicant:FirstName>Ben</applicant:FirstName>
    <applicant:LastName>Thompson</applicant:LastName>
    <applicant:HouseNo>1</applicant:HouseNo>
    <applicant:Street>Happiness Avenue</applicant:Street>
    <applicant:Town>Grumpyville</applicant:Town>
  </applicant:ApplicantDetails>
  <store:StoreDetails>
    <store:StoreID>001</store:StoreID>
  </store:StoreDetails>
</LoyaltyProgram>

Running the .NETCompute Node sample

After you have imported and deployed the sample, you can run it by following the instructions in the Running the sample section.

Back to sample home