Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Using Microsoft .NET in WebSphere Message Broker V8: Part 4: Using the .NETCompute node for exception handling

Ben Thompson (bthomps@uk.ibm.com), Consulting IT Specialist, IBM
Author photo
Ben Thompson is a Consulting IT Specialist working on the WebSphere Message Broker development team at the IBM Hursley Software Lab in the UK. He is currently working on the design and implementation of .NET support in Message Broker. In the past, he has worked for IBM Software Services for WebSphere designing and implementing WebSphere solutions for IBM customers worldwide. You can contact Ben at bthomps@uk.ibm.com.
(An IBM developerWorks Contributing Author)
Matthew Golby-Kirk (mgk@uk.ibm.com), Software Developer, IBM
Matthew Golby-Kirk photo
Matthew Golby-Kirk is a software developer working on the WebSphere Message Broker development team at the IBM Hursley Software Lab in the UK. He works on the design and implementation of the HTTP and Web services support, along with the ESQL language run time in WebSphere Message Broker. You can contact Matthew at mgk@uk.ibm.com.

Summary:  This series of four tutorials demonstrates the new support for Microsoft .NET in WebSphere Message Broker V8. Part 4 shows you how to use the .NETCompute node for exception handling, using a scenario that builds in complexity as additional exception conditions are deliberately produced and then handled. Readers should be familiar with either Microsoft .NET or WebSphere Message Broker, but need not be familiar with both.

View more content in this series

Date:  22 Feb 2012
Level:  Intermediate

Comments:  

Catching a CLR exception in a .NETCompute node

  1. This section of the tutorial demonstrates that .NETCompute nodes can also throw standard CLR Exceptions. These exceptions can also be caught and navigated using .NETCompute nodes. Separate .NETCompute nodes can also exist in distinct application domains, and exceptions thrown by CLR code running in one application domain can then be caught by CLR code running in a different application domain (assuming that the class defining the exception is available to both application domains). You will modify the existing message flow to achieve these aims, but first write some more C# code in a new Microsoft Visual Studio project. If you have followed the previous examples, then Visual Studio should already be running. Save and close the existing open solution, and then create a new project by selecting File => New Project:

    New Project
  2. The New Project wizard offers you the three types of Message Broker Project templates. Select the one named Project to create a Message Broker message, specify the properties at the bottom of the window as follows, and then Click OK:

    Name = ExceptionsDotNetProject2
    Location = C:\student\DOTNET\lab_exceptions\visual studio 2010\Projects
    Solution Name = ExceptionsDotNetProject2

    New Project wizard
  3. After the project is created, the class CreateNode.cs will be open in Visual Studio. Locate the UserCode region and add the lines of C# shown in the listing beneath the image below:

    UserCode region of CreateNode.cs

    Listing 12. C# code to be used in the UserCode region of CreateNode.cs
    #region UserCode
    // Add user code in this region to create a new output message
    // Force a NullReferenceException 
    String test = null;
    int len = test.Length;
    #endregion UserCode
    

    The purpose of this code is to cause a common CLR exception to be thrown, which you will catch when it is rolled back to the previous .NETCompute node running in the message flow. The two .NETCompute nodes will run their code in different .NET application domains.
  4. Save CreateNode.cs by selecting File => Save All. Build the assembly: right-click the ExceptionsDotNetProject2 level in the hierarchy of Solution Explorer and click Build Solution:

    Build Solution

  5. Switch back to Message Broker Toolkit and edit the same message flow named MyFlow that you have been using throughout this tutorial. This time, delete the MQ Output node named NO QUEUE and in its place drag and drop a .NETCompute node from the Transformation drawer of the palette onto the message flow canvas. Wire the node into the flow as shown below:

    Redesigned message flow MyFlow
  6. Edit the Basic properties of the node .NETCompute2:

    Assembly name = C:\student\DOTNET\lab_exceptions\visual studio 2010\Projects\ExceptionsDotNetProject2\ ExceptionsDotNetProject2\bin\Debug\ExceptionsDotNetProject2.dll
    Class name = ExceptionsDotNetProject2.CreateNode

    Basic properties of node .NETCompute2
  7. Switch to the Advanced tab of .NETCompute2, and set the AppDomain name to NewAppDomain. When this property is left blank on a .NETCompute node, the Broker runs the code in an application domain with the same name as the execution group or the Message Broker application in which it is deployed (depending on whether it is deployed as a standalone flow, or within an application). However, when a value is specified for the AppDomain property, then this is the name of the application domain in which the node's CLR code will run:

    Advanced properties of node .NETCompute2
  8. Save the message flow, return to the open test client, right-click the Invoke Message Flow level in the hierarchy on the panel on the left, and click Re-run. The flow should be redeployed and the same Hello World! message will be sent to the input queue again.

    Result of Test 5
    This time the output message that is caught contains the CLR NullReferenceException, which was thrown from the node .NETCompute2. Here is the full output message:

    Output message generated displaying CLR exception
  9. The exception list used by the Message Broker to carry the information about the CLR exception when the flow rollback occurs contains all detailed information a flow developer might need to understand where the exception was thrown and what the problem was. For this tutorial, you don't need to record the contents of this exception list, but an extract is included below just to show that the information it contains also describes the CLR exception. The red box below shows that the application domain in which the code was executing is also included. In your example, the id will probably be a different number:
    Extract of the Broker exception list generated when a CLR exception causes a flow rollback
  10. You can also use the Message Broker command console to display information about the application domains that an execution group contains, by using the mqsireportproperties command:

    Listing 13. mqsireportproperties command to display application domain information
    
    mqsireportproperties MB8BROKER -e default -o ComIbmAppDomainDirector -r
    

    The output from the command lists the application domains supported by the Message Broker execution group. The image below has highlighted the output for the application domain named NewAppDomain using a red box. The second red box shows all the assemblies loaded in this application domain:

    Application domain information output from mqsireportproperties

This section of the tutorial showed you how to catch a CLR exception using a .NETCompute node, even if the .NETCompute node in which the exception is thrown is running in a different application domain from the .NETCompute node in which the exception is caught. The next section shows you how to use Message Broker to execute hot-swap deploys.

7 of 10 | Previous | Next

Comments



Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=WebSphere
ArticleID=795296
TutorialTitle=Using Microsoft .NET in WebSphere Message Broker V8: Part 4: Using the .NETCompute node for exception handling
publish-date=02222012
author1-email=bthomps@uk.ibm.com
author1-email-cc=
author2-email=mgk@uk.ibm.com
author2-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).