Logo
HOW TO
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
 
 
Windows Server

BizTalk 2006 : Creating More Complex Pipeline Components (part 4) - Custom Disassemblers

8/3/2014 9:36:37 PM

Custom Disassemblers

It's important to call special attention to Disassembler components, as they are often what most developers end up writing. Disassemblers were intended to allow the pipeline to exam- ine the incoming document and break it up into smaller, more manageable documents. The classic example of this is an envelope file. The large document is received that contains an envelope with multiple smaller documents inside it. The envelope is removed, and each of the contained documents is validated against its schema and ends up being a distinct and unique message within BizTalk. This is shown in Figure 5. The Disassembler component has one key interface, IDisassemblerComponent.

Logical view of a Disassembler

IDisassemblerComponent has two methods, Disassemble and GetNext, which are listed in Table 3. What happens is the BizTalk runtime calls the Disassemble method first and passes the original message and the pipeline context. It then calls the GetNext method after the Disassemble method. The GetNext method returns new messages of type IBaseMessage until the component decides that all messages are created and then it returns Null. Returning Null from GetNext signals the end of the component's execution and signals the runtime that all messages have been properly created.

Table 3. Public Methods of IDisassemblerComponent
MethodDescription
DisassemblePerforms the disassembling of incoming document
GetNextGets the next message from the message set resulting from the Disassembler execution

A couple of design patterns exist that you can use when creating Disassemblers. One pattern is to use the Disassemble method to prime any instance variables, setup, and data, and then return and essentially create no messages. The messages will be created in the GetNext method, and new messages will be created each time the method is called. Another pattern is to create all messages in the Disassemble stage, enqueue them to a queue structure, and then dequeue the messages from the queue each time GetNext is called. Either strategy will work; the second strategy can be more efficient especially if expensive resources need to be instantiated each time a message is created. Using the second method, you only need to create these once at the beginning of the Disassemble method, create all the messages, and then dispose of the resource. Using the first method, the resource will either need to be created for each GetNext() call or stored as an instance member of the class. An example of the second implementation follows.

'<summary>
'called by the messaging engine until returned null, after Disassemble has been
'called
'</summary>
'<param name="pc">the pipeline context</param>
'<returns>an IBaseMessage instance representing the message created</returns>
Public Function GetNext(ByVal pc As _
Microsoft.BizTalk.Component.Interop.IPipelineContext) As _
Microsoft.BizTalk.Message.Interop.IBaseMessage Implements _
Microsoft.BizTalk.Component.Interop.IDisassemblerComponent.GetNext
'get the next message from the Queue and return it
Dim msg As Microsoft.BizTalk.Message.Interop.IBaseMessage = Nothing
If (_msgs.Count > 0) Then
msg = CType(_msgs.Dequeue, _
Microsoft.BizTalk.Message.Interop.IBaseMessage)
End If
Return msg
End Function

'<summary>
'called by the messaging engine when a new message arrives
'</summary>
'<param name="pc">the pipeline context</param>
'<param name="inmsg">the actual message</param>
Public Sub Disassemble(ByVal pc As _
Microsoft.BizTalk.Component.Interop.IPipelineContext, ByVal inmsg As _
Microsoft.BizTalk.Message.Interop.IBaseMessage) Implements _
Microsoft.BizTalk.Component.Interop.IDisassemblerComponent.Disassemble

'This is an example class which gets a simple list of strings. Each of
'these numbers will be
'a unique key in the new messages that we create.
Dim myArrayList As New ArrayList = myHelper.GetArrayofValues
Dim UniqueCode As String




For Each UniqueCode In myArrayList

_msgs.Enqueue(BuildMessage(pc, inmsg.Context, GetDocument _
(InboundSchema.DocumentSpec,UniqueCode)))
Next
End If

End Sub


Note the following function. This is a general function that can be used in any pipeline component where a new message needs to be created. This function takes the pipeline context, the message context (which is available from the original message), and the content for the document as a string. A new message is returned with a cloned copy of the original message context, and a message type as specified by the SchemaWithNone property.

'<summary>
'Returns a new message by cloning the pipeline context and original message context.
'The data to be assigned to the message must be a string value.
'</summary>
'<param name="pContextt">Pipeline context</param>
'<param name="messageContext">Original Message context to be used in the new
'message</param>
'<param name="messageContent">Data to be put in the message</param>
'<returns>New message</returns>
'<remarks>
'Message Content is assigned to the MessageBody by creating a new MemoryStream
'object
'</remarks>
Private Function BuildMessage(ByVal pContext As IPipelineContext, ByVal _
messageContext As IBaseMessageContext, ByVal messageContent As String) As _
IBaseMessage

' Build the message with its context
Dim message As IBaseMessage
Dim bodyPart As IBaseMessagePart
Dim messageStream As MemoryStream
Dim messageBytes As Byte()
Dim messageType As String

' Prepare and fill the data stream
messageBytes = Encoding.UTF8.GetBytes(messageContent)
messageStream = New MemoryStream(messageBytes.Length)



messageStream.Write(messageBytes, 0, messageBytes.Length)
messageStream.Position = 0

bodyPart = pContext.GetMessageFactory().CreateMessagePart()
bodyPart.Data = messageStream

message = pContext.GetMessageFactory().CreateMessage()
message.Context = PipelineUtil.CloneMessageContext(messageContext)
messageType = "http://" + _InboundDocumentSpecification.DocSpecName + _
"#" + _FileRootNode

message.Context.Promote("MessageType", BTSSystemPropertiesNamespace,_
messageType)
message.AddPart("body", bodyPart, True)

Return message

End Function

Other -----------------
- BizTalk 2006 : Custom Components (part 2) - Key BizTalk API Objects
- BizTalk 2006 : Custom Components (part 1) - Component Categories, Component Interfaces
- Microsoft Exchange Server 2010 : Getting Started with Email Archiving - Enabling Archiving (part 2) - Using Exchange 2010 Discovery, Offline Access
- Microsoft Exchange Server 2010 : Getting Started with Email Archiving - Enabling Archiving (part 1) - Archive Quotas , Exchange 2010 Discovery Operation Considerations
- Microsoft Exchange Server 2010 : Getting Started with Email Archiving - Placing a Mailbox on Retention Hold, Litigation or Legal Hold
- Microsoft Exchange Server 2010 : Getting Started with Email Archiving - Exchange Server 2010 Email Archiving - Policies
- Microsoft Exchange Server 2010 : Getting Started with Email Archiving - Industry Best Practices
- Microsoft Exchange Server 2010 : Getting Started with Email Archiving - Archiving
- Microsoft Exchange Server 2007 : Implementing Client Access and Hub Transport Servers - Installing the Hub Transport Server
- Microsoft Exchange Server 2007 : Implementing Client Access and Hub Transport Servers - Transport Pipeline
 
 
REVIEW
- First look: Apple Watch

- 10 Amazing Tools You Should Be Using with Dropbox

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
 
VIDEO TUTORIAL
- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

- How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
 
Popular tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS
Popular keywords
HOW TO Swimlane in Visio Visio sort key Pen and Touch Creating groups in Windows Server Raid in Windows Server Exchange 2010 maintenance Exchange server mail enabled groups Debugging Tools Collaborating
Top 10
- Microsoft Excel : How to Use the VLookUp Function
- Fix and Tweak Graphics and Video (part 3) : How to Fix : My Screen Is Sluggish - Adjust Hardware Acceleration
- Fix and Tweak Graphics and Video (part 2) : How to Fix : Text on My Screen Is Too Small
- Fix and Tweak Graphics and Video (part 1) : How to Fix : Adjust the Resolution
- Windows Phone 8 Apps : Camera (part 4) - Adjusting Video Settings, Using the Video Light
- Windows Phone 8 Apps : Camera (part 3) - Using the Front Camera, Activating Video Mode
- Windows Phone 8 Apps : Camera (part 2) - Controlling the Camera’s Flash, Changing the Camera’s Behavior with Lenses
- Windows Phone 8 Apps : Camera (part 1) - Adjusting Photo Settings
- MDT's Client Wizard : Package Properties
- MDT's Client Wizard : Driver Properties
 
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro