Extending the Business Rules sample

The Business Rules sample can be extended in two ways, both showing how you can update your business rules to match changing business conditions.

To update the rules, double-click the decision service file, BookOrder_DecisionService.rules, to open it in the Decision Service editor.

  1. Expand Rule 2 and change the value of the definition "minimum for free postage and packaging" to 10.00.
  2. Redeploy the application so that the change to the rule takes effect.
  3. Double-click BookOrderApplication2.mbtest to open it in the Test Client.
  4. In the Test Client, click Enqueue.
  5. Click Send Message to place a WebSphere MQ message on the input queue of the book order message flow.
  6. In the Test Client, click Dequeue.
  7. Ensure that the port that is set in the Test Client matches the port that your queue manager is using.
  8. Click Get Message to get a message from the queue. and so will go to queue BOOKORDER_OUT_FREEPOSTAGE. Change the queue name in the field Queue to BOOKORDER_OUT_FREEPOSTAGE.
  9. Scroll to the end of the message and observe that the postandPackaging field has changed to 0. The order value is 12.98; therefore, since the business rule was changed, the order now qualifies for free postage and packaging.

Try adding a new rule to the decision service. Create a rule that gives loyalty card customers a $2.00 discount on orders over 20.00.

  1. Double-click the decision service file, BookOrder_DecisionService.rules, to open it in the Decision Service editor.
  2. On the Rule sequence page, click Add Rule to add a new rule.
  3. Press CTRL+Space to open Content Assist, then start the rule with a definition for the discount.

    Input parameter

  4. Add an "if" statement to check if the order is from a loyalty card holder.

    Input parameter

  5. The loyalty card element will not contain "00000000" if the order is from a loyalty card customer.

    Input parameter

  6. Complete the rule by checking the amount in the order total, setting the discount to the discount type "loyalty discount", and subtracting the loyaltyDiscountValue value from the order total.

    Input parameter

  7. Save the rule.
  8. Rebuild the bar file. Under the BARs folder double click on the bar file BusinessRules.bar. Click on the icon to rebuild and save the broker archive.
  9. Deploy the updated bar file by dragging the bar file onto the integration server BusinessRules in the Integration Nodes view.

Now test the new rule:

  1. Double-click BookOrderApplication2.mbtest to open it in the Test Client.
  2. In the Test Client, right click Enqueue and select Duplicate from the menu.
  3. In the input message change the orderTotal to 35.00 and the loyaltyCard to 12345678
  4. Click Send Message to place a WebSphere MQ message on the input queue of the book order message flow.
  5. In the Test Client, right click Dequeue and select Duplicate from the menu.
  6. As the order is now over 25.00 the output message will go to the queue BOOKORDER_OUT_FREEPOSTAGE. Change the value in the Queue field in Dequeue to BOOKORDER_OUT_FREEPOSTAGE
  7. Ensure that the port that is set in the Test Client matches the port that your queue manager is using.
  8. Click Get Message to get a message from the queue.
  9. Scroll to the end of the message and observe that the discounts field is set to "Loyalty card discount" and the orderTotal is reduced by $2.00.

Back to sample home