Home Page › Forums › BizTalk 2004 – BizTalk 2010 › Receive Pipeline : Out of Memory exceptions
- This topic has 1 reply, 1 voice, and was last updated 9 years, 2 months ago by
community-content.
-
AuthorPosts
-
-
July 24, 2008 at 8:12 AM #20226
Hello, am trying to understand a bit of streaming in a Receive Pipeline. we have a requirement like a flat file comes in; for each Header record there may be 1 or more detail records. in the receive pipleine , first ,we need to archive the file;then every Header record needs to be prefixed with a certain character and detail with a certain character. then the file needs to be disassembled.
In our pipeline component, we have 2 custom stage components and the Biztalk Flat file disassembler; totally 3 stage components; the first stage component does the archiving; it reads the received file path and name from the context and uses the SYStem.IO.File.Copy method to copy the file to the archive folder. Is this the best way of doing this?
In the second component for adding the unique characters for Header and Detail, we do the following:
IBaseMessagePart bodyPart = InMsg.BodyPart;
Encoding encoding = Encoding.GetEncoding(1252);
Stream StreamObject = bodyPart.GetOriginalDataStream();
Stream mStrm = new MemoryStream();
StreamWriter strWriter = new StreamWriter(mStrm, encoding);
StreamReader streamReader = new StreamReader(StreamObject, encoding);
while (streamReader.EndOfStream == false)
{
line.Append(streamReader.ReadLine());
strWriter.Write(UniqueIdentifier.ToString() + line.ToString() + ”
“);.
.
}
strWriter.Flush();
//Creating new IBaseMessage
IBaseMessage PayLoadMsg =
null;
//The following code is to convert the string into IBaseMessage
PayLoadMsg = pContext.GetMessageFactory().CreateMessage();
PayLoadMsg.Context = InMsg.Context;
for (int
i = 0; i < InMsg.PartCount; i++)
{
//fetch part from original message:
string partname;
IBaseMessagePart part = InMsg.GetPartByIndex(i,
out partname);
//copy it to destination message:
if(partname != InMsg.BodyPartName)
{
PayLoadMsg.AddPart(partname, part,
false);
}
}
IBaseMessagePart body = pContext.GetMessageFactory().CreateMessagePart();
body.PartProperties = InMsg.BodyPart.PartProperties;
mStrm.Flush();
body.Data = mStrm;
mStrm.Position = 0;
PayLoadMsg.AddPart(InMsg.BodyPartName, body,
true);
return PayLoadMsg;
Is there any better way of doing this functionality? we are getting out of memory exceptions. Please assist
-
July 24, 2008 at 12:10 PM #20227
Anon,
For the archiving, can I suggest that you take a look at my pipeline archiving component (http://www.codeplex.com/btsmsgarchcomp) which is designed for this very purpose; from the project blurb:
The
component introduces a powerful concept of user defined ‘macros’ to
help build archive paths which are unique to the message being
archived. Macros are replaced with message context-property values as a
message passes through the component. In previous versions, these
macros were hard-coded into the component, however this release
introduces the concept of a ‘Macro Definitions’ Xml configuration file,
which can be amended by the user allowing any out-of-the-box or custom
context property to be referenced in a macro.Writing of the
archive file is accomplished during the read-event of the FOE stream,
essentially spooling the archive file to disk (or network share) as the
stream is read by downstream components or the Messaging Agent itself.As for the prefixing of characters onto the header and detail records, I would suggest that you investigate using the VirtualStream stream in your pipreline component rather than the standard MemoryStream. The VirtualStream caches data in the stream in a MemoryStream until it reaches a threshold, over which the
data is overflowed to a secure location on disk. After the stream is
closed the disk file is automatically deleted. For more information see:- http://blogs.neudesic.com/blogs/enterprise_integration/archive/2006/12/27/1366.aspx
- http://technet.microsoft.com/en-us/library/microsoft.biztalk.streaming.virtualstream.aspx
Nick.
-
-
AuthorPosts
- The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.