ENTERPRISE

BizTalk 2006 : Managing Exceptions in Orchestrations (part 4) - Processing and Retrieving Messages and Exceptions from the Fault Message

8/7/2012 4:08:58 PM

Processing and Retrieving Messages and Exceptions from the Fault Message

Having published the Fault message with the two persisted messages (ApprovedRequest and DeniedRequest) and a persisted Exception object from the EAIProcess orchestration, we'll move forward and demonstrate how to extract the messages and the Exception objects in secondary orchestration schedules.

There is really only one method for extracting an Exception object: the GetException() API. However, there are two methods for extracting messages. One provides a typeless method to retrieve all messages persisted to the Fault message. The other provides a strongly-typed approach.

Typeless Message Retrieval

The typeless approach is useful if you have a general logging need, or you don't have access to the schema assembly used in the originating orchestration that persisted the messages. In this case, a collection of messages can be returned using MoveNext() to enumerate through them.

This allows developers to inspect the message context properties and do whatever they want with them, e.g., process them, send them out to a SharePoint site, etc. For example, a generic orchestration exception process may do the following:

  • Retrieve array of messages from Fault message.

  • Inspect context properties to determine message type or retrieve other context values.

  • Based on message type or other criteria, look up processing instructions via Business Rule Engine.

  • Process individual messages per business rule evaluation.

This makes for an extremely decoupled exception processing solution. The EAIGenericHandler orchestration, located in the BootCamp.Orchestration.Exception. FaultHandler project, is a good example demonstrating the typeless approach and is shown in Figure 6-23. In this example, the orchestration is configured as follows:

  1. The Receive shape is configured with a filter expression: ("Msft.Samples.BizTalk. Exception.Schemas.FaultCode" == "1001"). This effectively subscribes the orchestration to any Fault messages published where the FaultCode equals 1001.

  2. The Receive shape is bound to a direct bound receive port.

  3. The Expression shape directly below the Receive shape has the following code snippet that calls the GetMessages() API:

    msgs = Msft.Samples.BizTalk.Exception.ExceptionMgmt.GetMessages(FaultMsg);

    The msgs variable is declared of type MessageCollection. This returns an array of messages, including their original context properties, from the Fault message.

  4. A Loop shape is configured to call

    msgs.MoveNext()

  5. Within the Loop shape, an Expression shape is configured to retrieve the current message in the collection by calling

    TmpMsg = msgs.Current;
    TmpMsg is a message variable declared as a System.Xml.XmlDocument.

  6. Each message in the collection is then published to a direct bound port.

  7. A physical send port is configured to serialize each message to a folder.

NOTE

Message Construct shapes are not necessary within the example. The API for the exception handler takes care of constructing new messages within the BizTalk runtime.

When this orchestration executes, it will retrieve all the messages from the Fault message (i.e., ApprovedRequest and DeniedRequest) and serialize them to disk via the send port subscription.

Figure 11. EAIGenericHandler orchestration demonstrating typeless message retreival and handling using the Failed Orchestration Routing API

Strongly-Typed Message Retrieval

Another effective approach is retrieving the messages from the Fault message as stronglytyped messages. This is done by referencing the schema assemblies used by the originating orchestration.

The EAIProcessHandler orchestration, located in the BootCamp.Orchestration. Exception.FaultHandler project, is a good example demonstrating the strongly-typed approach. The orchestration flow is shown in Figure 12.

Figure 12. EAIProcessHandler orchestration demonstrating strongly-typed message retreival and handling using the Failed Orchestration Routing API

In this example, the orchestration is configured as follows:

  1. The Receive shape is configured with a filter expression: ("Msft.Samples.BizTalk. Exception.Schemas.FaultCode" == "1001"). This effectively subscribes the orchestration to any Fault messages published where the FaultCode equals 1001.

  2. The Receive shape is bound to a direct bound receive port.

  3. The Expression shape directly below the Receive shape has the following code snippet, which calls the GetMessage() and GetException() APIs:

    //Retrieve the two original messages from the Fault message
    RequestMsg = Msft.Samples.BizTalk.Exception.ExceptionMgmt.GetMessage(FaultMsg,
    "ApprovedRequest");
    DeniedMsg = Msft.Samples.BizTalk.Exception.ExceptionMgmt.GetMessage(FaultMsg,
    "DeniedRequest");
    
    					  

    //Retrieve the System.Exception from the original service
    newExc = Msft.Samples.BizTalk.Exception.ExceptionMgmt.GetException(FaultMsg);
    
    // Write the error value to event log (need admin rights)
    System.Diagnostics.EventLog.WriteEntry _
    ("EAIProcessHandler",newExc.Message.ToString());
    
    					  

    Both RequestMsg and DeniedMsg are strongly typed using the schemas in the originating orchestration.

    newExc is declared as a variable of type System.Exception.

  4. If repair is needed:

    1. RequestMsg is sent to the folder drop via a port.

    2. An InfoPath processing instruction is added to it to facilitate editing as shown in Figure 13.

      Figure 13. RepairReSubmitForm.xsn Infopath form
    3. The InfoPath form is designed to submit repaired data to a BizTalk HTTP receive location configured under the receive port for the EAIProcess orchestration.

    4. DeniedMsg is published to a direct bound port.

    5. A physical send port is configured to serialize the message to a folder.

  5. If repair is not needed:

    1. Each message is then published to a direct bound port.

    2. A physical send port is configured to serialize each message to a folder.

NOTE

Message Construct shapes are not necessary within the example. The API for the exception handler takes care of constructing new messages within the BizTalk runtime.

The form in Figure 13 is configured to use a BizTalk HTTP receive location URL as its submit data source. Once submitted, it will activate a new instance of the EAIProcess orchestration.

When this orchestration executes, it will retrieve all the messages from the Fault message (i.e., ApprovedRequest and DeniedRequest) and set them into strongly-typed message variables. In fact, if you stop the send port subscriptions and run the orchestration, you can see the original context property values on the messages; the context properties were set from the originating orchestration (see Figure 14).

Figure 14. Message Details dialog box displaying the properties of the ApprovedRequest message retreived from the Fault message using the GetMessage() API

NOTE

In Figure 14, the ReceivedFileName property that was set before the originating orchestration processed the message and threw the exception. Also, the API persists all custom Promoted properties as noted by the Qty property. This is an incredibly handy feature to have.

Beyond the Next Horizon

As can be seen from the previous sections, the Failed Orchestration Routing API is powerful enough to allow developers to handle orchestration-generated exceptions. With a little work and a good design, you can handle orchestration exceptions the same way you would handle messaging subsystem exceptions using the Failed Message Routing feature of BizTalk Server 2006.

The samples provided online,[] specifically the EAIGenericHandler and EAIProcessHandler orchestrations, demonstrate simple patterns for accessing both the exception messages as well as the state from the original processing orchestration. This state, in the form of the original messages, can be accessed as strongly-typed or typeless XLANG messages.

[] Samples and compiled API to be provided for download at www.apress.com.

  • Standardize how application exceptions are detected and caught in the BizTalk environment, i.e., messaging and orchestration subsystems.

  • Provide common patterns that allow automated processes to react and manage application exceptions.

  • Provide a loosely coupled exception management pattern that facilitates reuse.

If you take this pattern a step further and extend the API, you could provide another method that creates canonical Fault messages generated either by the Failed Message Routing feature of BizTalk Server 2006 or the Failed Orchestration Routing API. A generic, BizTalk Group—wide send port could be configured to subscribe to all Fault messages, regardless of source, call the method, and then post all canonical Fault messages to a central web-based portal. That would satisfy the last design goal:

  • Develop a common reporting paradigm of application exceptions and their available message state that applies to any BizTalk subsystem.

The final step would be to dynamically generate business intelligence data from the Fault messages going through the BizTalk environment. That's right; you call that BAM in BizTalk Server 2006.

Remember the following scenario we described earlier and the solution walkthrough we proposed:

A user submits an invoice to the system. During the course of processing the invoice within an orchestration, the Business Rule Engine throws an application exception because some piece of the data is incorrect. The business process should catch the exception, send the offending message to another person or system that can correct the message, and resubmit the message for processing.

To implement the use case, we envisioned a sequence of events would need to happen, as presented earlier in the subsection "BizTalk Server 2006 Failed Message Routing As a Blueprint" and repeated here for your convenience:

  1. A developer is assigned responsibility for the recently deployed Financial Reporting BizTalk application.

  2. A new exception message arrives in the SharePoint-based exception management portal indicating a data integrity issue with an orchestration in the Financial Reporting BizTalk application.

  3. The developer is notified of the new exception either through his subscription to the SharePoint application list or because the exception exceeded a threshold predefined in BAM.

  4. The developer navigates to the SharePoint-based exception management portal and examines the Fault message posted as well as the individual orchestration messages and their context properties that were persisted.

  5. The developer determines that this will be a common error that will require manual intervention and correction by the Finance team and resubmission to the system.

  6. The developer creates and deploys an independent BizTalk orchestration project that subscribes to the specific exception and application information.

  7. The project is designed to retrieve the invalid message from the Fault message, send the message to the Finance team for correction, and correlate the corrected message back to orchestration and resubmit.

  8. A week later the developer navigates to the SharePoint-based exception management portal to view that the application exception trends for invalid messages have decreased dramatically since the deployment of his solution.

If you extend the Failed Orchestration Routing API, you could make the solution walkthrough a reality with very little effort. This need is not unique to a specific BizTalk application; it tends to be ubiquitous in BizTalk environments to provide operational visibility into the health of the applications deployed. This becomes a vital function in Enterprise Service Bus (ESB)[] type deployments.

[] http://en.wikipedia.org/wiki/Enterprise_Service_Bus

In the upcoming release of the Microsoft ESB Toolkit, this API will be extended to accommodate the scenarios we described previously. This should prove invaluable for anyone deploying applications in the future.

Other  
  •  D-Link DHP-1565 Wireless N Powerline Router
  •  Application Patterns and Tips : Localize a Windows Forms Application, Localize an ASP.NET Application
  •  Application Patterns and Tips : Use Model-View-ViewModel in WPF
  •  Liquid-Metal
  •  Vigor 2850n
  •  Visual Studio 2010 : Introducing the Visual Studio Extensibility - Extending the Code Editor
  •  Visual Studio 2010 : Managing Extensions with the Extension Manager, Managing Add-Ins with the Add-In Manager
  •  Intel Xeon Phi: Coprocessor speeding at 1 teraflops in a PCIe Card
  •  Visual Studio Team System 2008 : Working with Test Results (part 2) - Build report and test result
  •  Visual Studio Team System 2008 : Working with Test Results (part 1) - Test as part of Team Foundation Server build
  •  Finance - Apple Versus Google
  •  Oracle Coherence 3.5 : Testing and debugging Coherence applications
  •  Oracle Coherence 3.5 : Accessing the data grid (part 6) - Using the Coherence API - Implementing CoherenceTarget, Testing the Cache loader
  •  Oracle Coherence 3.5 : Accessing the data grid (part 5) - Using the Coherence API - Loader design, Implementing CsvSource
  •  Oracle Coherence 3.5 : Accessing the data grid (part 4) - Using the Coherence API - The basics: NamedCache and CacheFactory
  •  Oracle Coherence 3.5 : Accessing the data grid (part 3) - Configuring Coherence
  •  Oracle Coherence 3.5 : Accessing the data grid (part 2) - Configuring the development environment
  •  Oracle Coherence 3.5 : Accessing the data grid (part 1) - Coherence console
  •  Oracle Coherence 3.5 : Installing Coherence, Starting up the Coherence cluster
  •  The Go-To Reference Design Map For The Cloud?
  •  
    Top 10
    Nikon 1 J2 With Stylish Design And Dependable Image And Video Quality
    Canon Powershot D20 - Super-Durable Waterproof Camera
    Fujifilm Finepix F800EXR – Another Excellent EXR
    Sony NEX-6 – The Best Compact Camera
    Teufel Cubycon 2 – An Excellent All-In-One For Films
    Dell S2740L - A Beautifully Crafted 27-inch IPS Monitor
    Philips 55PFL6007T With Fantastic Picture Quality
    Philips Gioco 278G4 – An Excellent 27-inch Screen
    Sony VPL-HW50ES – Sony’s Best Home Cinema Projector
    Windows Vista : Installing and Running Applications - Launching Applications
    Most View
    Bamboo Splash - Powerful Specs And Friendly Interface
    Powered By Windows (Part 2) - Toshiba Satellite U840 Series, Philips E248C3 MODA Lightframe Monitor & HP Envy Spectre 14
    MSI X79A-GD65 8D - Power without the Cost
    Canon EOS M With Wonderful Touchscreen Interface (Part 1)
    Windows Server 2003 : Building an Active Directory Structure (part 1) - The First Domain
    Personalize Your iPhone Case
    Speed ​​up browsing with a faster DNS
    Using and Configuring Public Folder Sharing
    Extending the Real-Time Communications Functionality of Exchange Server 2007 : Installing OCS 2007 (part 1)
    Google, privacy & you (Part 1)
    iPhone Application Development : Making Multivalue Choices with Pickers - Understanding Pickers
    Microsoft Surface With Windows RT - Truly A Unique Tablet
    Network Configuration & Troubleshooting (Part 1)
    Panasonic Lumix GH3 – The Fastest Touchscreen-Camera (Part 2)
    Programming Microsoft SQL Server 2005 : FOR XML Commands (part 3) - OPENXML Enhancements in SQL Server 2005
    Exchange Server 2010 : Track Exchange Performance (part 2) - Test the Performance Limitations in a Lab
    Extra Network Hardware Round-Up (Part 2) - NAS Drives, Media Center Extenders & Games Consoles
    Windows Server 2003 : Planning a Host Name Resolution Strategy - Understanding Name Resolution Requirements
    Google’s Data Liberation Front (Part 2)
    Datacolor SpyderLensCal (Part 1)