How to Terminate Suspended (not resumable) Routing Failure Report Instances with PowerShell

One of the annoying thing with working with Direct Bound Ports in Orchestrations, in especially, MessageBox direct bound ports that allow us to easily implement decouple publish-subscribe design patterns, is that you may get a situation in which you get a lot of Routing Failure Report Instances in the state Suspended (not resumable).

Terminate Suspended (not resumable): BizTalk Group by Service name Routing Failure Report

The error-handling properties facility allows us to automated handling of messaging failures as an alternative to the traditional (now default) behavior of placing failed messages in the Suspended queue. This automated handling routes an error message to any subscribing routing destination, such as a send port or orchestration. The error message is a clone of the original message with all previously promoted properties now demoted and with selected properties related to the specific messaging failure promoted to the message context.

Normally the easy way to implement this is to create a Send Port with the following filter:

  • ErrorReport.ErrorType = “FailedMessage”

Nevertheless, because we are using an orchestration with Direct Bound Ports, the orchestration will receive a PersistenceException that you can handle inside our business flow, however, is also create a Routing Failure Report Instance in the state Suspended (not resumable) without any ErrorReport property promoted

Terminate Suspended (not resumable): BizTalk Routing Failure Report Property Promotions

So, we cannot easily automate this kind of instances.

An alternative solution to automate this task is, inside the Error Handler, invoke a helper class library that deletes all these instances once they occur in a controlled fashion way:

...
using (PowerShell PowerShellInstance = PowerShell.Create())
{
    StringBuilder pscript = new StringBuilder();
    pscript.AppendLine(@"[STRING]$SQLInstance = get-wmiobject MSBTS_GroupSetting -namespace root\MicrosoftBizTalkServer | select-object -expand MgmtDbServerName");
    pscript.AppendLine(@"[STRING]$BizTalkManagementDb = get-wmiobject MSBTS_GroupSetting -namespace root\MicrosoftBizTalkServer | select-object -expand MgmtDbName");
    pscript.AppendLine(@"[STRING]$BizTalkGroup = ""$SQLInstance"" + "":"" + ""$BizTalkManagementDb""");
    pscript.AppendLine(@"[ARRAY]$suspendedMessages = get-wmiobject MSBTS_ServiceInstance -namespace 'root\MicrosoftBizTalkServer' -filter '(ServiceStatus=32 and ServiceClass=64 and ServiceName like ""<name_of_our_orchestration>"")'");
    pscript.AppendLine(@"foreach ($msgSuspended in $suspendedMessages){");
    pscript.AppendLine(@"$msgSuspended.InvokeMethod(""Terminate"",$null)}");

    PowerShellInstance.AddScript(pscript.ToString());
    PowerShellInstance.Invoke();
}
...

How to check terminate Suspended (not resumable) Routing Failure Report Instances with PowerShell

Using PowerShell is a good option to delete all of these kinds of messages, you can send a report and delete or just simply delete it. Windows PowerShell is a Windows command-line shell designed especially for system administrators and can be used by BizTalk administrators to help them in automating repetitive tasks or tasks that are time-consuming to perform manually.

Because was controlling the error inside the main orchestration I don’t have the need for an additional report, so this is a simple script that will allow you to delete all Routing Failure Report Instances suspended with the state Suspended (not resumable) from your BizTalk Server environment:

#Get all Suspended (not resumable) Routing Failure Report Instances
[ARRAY]$suspendedMessages = get-wmiobject MSBTS_ServiceInstance -namespace 'root\MicrosoftBizTalkServer' -filter '(ServiceStatus=32 and ServiceClass=64)'

foreach ($msgSuspended in $suspendedMessages)
{
    $msgSuspended.InvokeMethod("Terminate",$null)
}

Download

THIS POWERSHELL IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND.

You can download Terminate Suspended (not resumable) Routing Failure Report Instances PowerShell from GitHub here:

Author: Sandro Pereira

Sandro Pereira lives in Portugal and works as a consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc. He is a regular blogger, international speaker, and technical reviewer of several BizTalk books all focused on Integration. He is also the author of the book “BizTalk Mapping Patterns & Best Practices”. He has been awarded MVP since 2011 for his contributions to the integration community.

6 thoughts on “How to Terminate Suspended (not resumable) Routing Failure Report Instances with PowerShell”

  1. With the given code i got below error:
    Login failed for user ‘NT AUTHORITY\ANONYMOUS LOGON’

    In my case, the errors appear when BizTalk and SQL Server are on separate servers, when run in a “multi-server” environment.

    Could you please help us

  2. Exception calling “TerminateInstance” with “1” argument(s): “Object reference not set to an instance of an object.”

    + $TerminateOperation.TerminateInstance($msgid) | Out-null
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : NullReferenceException

  3. Hi,

    I have a question. In the script the instances are saved into variable $suspendedMessages. If I want to further filter based on the context of the message will it everytime connect to Biztalk or will it retrieve from variable.

  4. Hello;

    It’s possible to terminate the instances running some queries in Sql server ? different from exec bts_CleanupMsgbox , which is not recommended by Microsoft in production environments.

    Or the best (secure) option is by PowerShell?

    thanks

    1. Maybe it is possible but for me, the best way will be using PowerShell or BizTalk Server Management API

Leave a Reply

Your email address will not be published. Required fields are marked *

turbo360

Back to Top