Title: BizTalk
Failed Message Routing and Handling:
Author: Toraj
Khavari
Date: March.
25, 2015
Objective: BizTalk
Business Activity Monitoring BAM is a powerful tool. In addition, at times we
may have requirements to manage failed messages and respond to the error
properly and automatically, if possible. For example, if a purchase order fails
an orchestration / workflow, we may want to follow up and react to it.
Article Body: In
this article we examine how to configure BizTalk failed messages and have an orchestration
react to the error. To keep it simple the error handling orchestration log and
email messages. Being an Orchestration, it can do anything / workflow, we want.
1- Business
BizTalk utilizes send/s and receive/s ports with appropriate adaptors to communicate
messages. Edit the send and receive ports and check the "Enable routing
for failed messages" field. Henceforth, BizTalk will route the failed
messages. The “Enable routing for failed messages" will promote
ErrorReport’s objects. Thereafter, we can filter on the ErrorReport’s objects.
The "Enable routing for failed messages" field is displayed in the
Send Port’s Transport Advanced Options tab, and Receive Port’s General Tab.
2- Create a
new Send Port and configure its File Transport Properties.
3- Modify
the send port filters to key on the ErrorReport properties. In my case, I
selected the ports’ name. Because, I handle the business orchestration errors,
false positive, and exceptions in the orchestration’s work flow.
Henceforth,
all the failed errors will be processed and copied in ErrorReportSendPort’s
folder. In my case, it is “C:\EDIPortLocation\DropXmlFault\”.
4- Create a
new Error Handling orchestration. The orchestration can look for any file in
the ErrorReportSendPort’s folder and react to it. In my case,
Adec.VendorsEDI.POOrchErrorHandling, I serialize the file, email, and log it.
For more details please refer to the "Biztalk Send Email and Post Eventlogs" wiki article. http://torajkhavari.blogspot.com/2015/02/biztalk-send-email-and-post-event-logs.html
The
receive message is type System.Xml.XmlDocument. To serialize xml file fell free
to use the following code.
// Identify the email recipients. If
there are more than one, separate them with <;>.
// The best option is have email group.
tempString =
System.String.Format("mailto:{0}", "youremail@ycompany.com");
WHOrchestrationDynamicSend(Microsoft.XLANGs.BaseTypes.Address)=tempString;
// Copy message
Message_XMLOut = Message_XMLIn;
// Assign email subject.
tempString =
System.String.Format("Message from Vendors EDI Orchestration Server
{0}", System.Environment.MachineName);
Message_XMLOut (SMTP.Subject)=tempString;
// Assign email body text character set.
It is very critical. Make sure it is setup correctly.
// Will cause you a lot of issue, if it
is not right.
tempString =
System.String.Format("{0}", "utf-8");
Message_XMLOut
(SMTP.EmailBodyTextCharset)=tempString;
// Build the email body
emailMsgOut =
System.String.Format("VendorsEDI Solution - BizTalk error watcher detected
a source in the error port. Priority {0}\n", "2");
emailMsgOut = emailMsgOut +
System.String.Format(" Contact: {0}.\n" , "Dynamic AX Vendors
EDI SME");
emailMsgOut = emailMsgOut +
System.String.Format("Email generated, automatically. {0}.\n" ,
"Do not reply");
emailMsgOut = emailMsgOut +
System.String.Format("VenderEDI ErrorReport Watcher Sender. Message:
{0}.\n\n" , "As follows");
tempString = Message_XMLOut.OuterXml;
emailMsgOut = emailMsgOut + tempString;
// Set the email boddy
Message_XMLOut
(SMTP.EmailBodyText)=emailMsgOut;
// Eventlog error
System.Diagnostics.EventLog.WriteEntry("VendorsEDI",
emailMsgOut, System.Diagnostics.EventLogEntryType.Error, 1009);
// Build the msg body
tempString = System.String.Format("VendorsEDI
Sender -");
tempString = tempString +
System.String.Format(" VenderEDI ErrorReport Watcher Sender Emailed: {0}.
\n" , emailMsgOut);
// Eventlog information
System.Diagnostics.EventLog.WriteEntry("VendorsEDI",
tempString, System.Diagnostics.EventLogEntryType.Information, 1000);
We can construct orchestration and workflow to
react to failed messages.
Hints:
-
We
can have multiple Catch Exceptions. Not limited to one.
-
For
event log and sending emails refer to the “BizTalk Send Email and Post
Eventlogs” wiki article. http://torajkhavari.blogspot.com/2015/02/biztalk-send-email-and-post-event-logs.html
-
Keep
the email distribution list in Business Rule Engine. It is cached per server,
fast, and configurable. For more details refer to the “BizTalk using Business
Rule Engine Introduction” wiki article. http://torajkhavari.blogspot.com/2015/02/biztalk-using-business-rule-engine.html
Cheers
Toraj
References:
thank you for sharing Biztalk Online Training Hyderabad
ReplyDeleteThanks for writing such a good article
ReplyDeleteBiztalk Online Training Hyderabad