BizTalk Server General - Using MSMQ and its output

This is Interesting: Free IT Magazines  
Home > Archive > BizTalk Server General > October 2005 > Using MSMQ and its output





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Using MSMQ and its output
Namshub

2005-10-24, 10:37 am

I'm trying to figure out how to format the xml string sent through the
MSMQ adapter, which is received into the orcestration.

<?xml version="1.0"?>
<string>20051017*4778*PMIA*I*104620*SO1*
U999999***</string>

I need to convert this string into an XML schema, or figure out how
to retrieve all these values (as this is the basis of some logical
branching and enrichment features)

Can anyone help on what to do? I've set the message type to
system.xml.document, but not sure if this is going to work or where
to go from here.

I had originally been using files which contain this information, but
a preference to the abilities of the message queue in order to
maintain order as much as possible (the files used to be generated by
a socket app that has been adapted to send the message directly to a
queue)

Cheers

Scott Colestock

2005-10-24, 10:37 am

Who is putting the messages on the queue ? I'm guessing that you need to
use the ActiveXMessageFormatter when placing the messages on the queue, if
the <string> wrapper around your data is unexpected.

If the message arrives "unwrapped", you can use a standard flat file
disassembler to parse the content into an xml doc.
(You could do the unwrapping in a pipeline component, too, of course.)

Scott Colestock
www.traceofthought.net


"Namshub" <Richard.Pullen@southend.nhs-dot-uk.no-spam.invalid> wrote in
message news:V9OdnTm1h7-hT87eRVn_vA@giganews.com...
> I'm trying to figure out how to format the xml string sent through the
> MSMQ adapter, which is received into the orcestration.
>
> <?xml version="1.0"?>
> <string>20051017*4778*PMIA*I*104620*SO1*
> U999999***</string>
>
> I need to convert this string into an XML schema, or figure out how
> to retrieve all these values (as this is the basis of some logical
> branching and enrichment features)
>
> Can anyone help on what to do? I've set the message type to
> system.xml.document, but not sure if this is going to work or where
> to go from here.
>
> I had originally been using files which contain this information, but
> a preference to the abilities of the message queue in order to
> maintain order as much as possible (the files used to be generated by
> a socket app that has been adapted to send the message directly to a
> queue)
>
> Cheers
>



Namshub

2005-10-24, 10:37 am

Thnaks Scott,
Got some where towards that but it converts my String to Unicode. I'm now
looking to see if i can change my original schema i had built from a flat
file.

Complicated story but we wanted a process where we could control the
sequence from a pickup point (as the string is created via a sockets program
that used to write files into a folder) and the best solution was a MSMQ.
So I already have the schema and the orchestration, but it was the first use
of a MSMQ and the programming of one in Dot Net.

Ric

"Scott Colestock" <scolestock@community.nospam> wrote in message
news:Oy8tu7%230FHA.1168@TK2MSFTNGP10.phx.gbl...
> Who is putting the messages on the queue ? I'm guessing that you need to
> use the ActiveXMessageFormatter when placing the messages on the queue, if
> the <string> wrapper around your data is unexpected.
>
> If the message arrives "unwrapped", you can use a standard flat file
> disassembler to parse the content into an xml doc.
> (You could do the unwrapping in a pipeline component, too, of course.)
>
> Scott Colestock
> www.traceofthought.net
>
>
> "Namshub" <Richard.Pullen@southend.nhs-dot-uk.no-spam.invalid> wrote in
> message news:V9OdnTm1h7-hT87eRVn_vA@giganews.com...
>
>



teddennis

2005-10-24, 10:37 am

Ric,

Try loading your string into an xmldocument first and serialize it to
the message bodystream:

ex:

public static string QMessage(string messageToQueue, string qPath)
{
string outstring = "Success";
XmlDocument qDoc = new XmlDocument();
qDoc.LoadXml(messageToQueue);
//serialize & q message
System.Xml.Serialization.XmlSerializer x = new
System.Xml.Serialization.XmlSerializer(qDoc.GetType());
MessageQueue MQueue = new MessageQueue(qPath);
//MQueue.Path = queuePath;


// Create an MSMQ message and send it to receive port queue
System.Messaging.Message MsgOut = new System.Messaging.Message();

//MsgOut.ResponseQueue = responseQueue;
MsgOut.Priority = MessagePriority.Normal;
//MsgOut.UseJournalQueue = true;
MsgOut.Label = qDoc.GetType().ToString();

//MsgOut.CorrelationId = coID;
//MsgOut.Recoverable = true;


x.Serialize(MsgOut.BodyStream, qDoc);
try
{
MQueue.Send(MsgOut);
}
catch ( Exception e )
{
outstring = "Error";
log.Error("Failed to Q Referral to "+qPath, e);

}
// close the message queue
MQueue.Close();
return outstring;

Namshub

2005-10-24, 10:37 am

Sorry maybe i've missunderstood the code.

When I submit the string in the message queue it automatically defaults to
the XMLFormmater and puts the wrapper around the message.

What i'm trying to acheive is take a string and then trying to parse the the
receiving end with the Flatfile parser ( built upon a flat file schema) I
used when the program used a file. (which contained the string) so that I
can use XPath in the Orcestration as I have to test for certain values.

The only other solution I could come up with is that i leave the
XMLFormater, send it via the XMLReceivePipeline and then write a custom
function dll to split the values out of the string. I just thought that was
not really the solution of choice.

Has anyone sent a simple string to a msq and parsed it with a custom
pipeline as I'd be interested to know how you've done it.

Regards
Ric

"teddennis" <ted@brookvilletheatre-dot-com.no-spam.invalid> wrote in message
news:aOednRF2sp8keMveRVn_vQ@giganews.com...
> Ric,
>
> Try loading your string into an xmldocument first and serialize it to
> the message bodystream:
>
> ex:
>
> public static string QMessage(string messageToQueue, string qPath)
> {
> string outstring = "Success";
> XmlDocument qDoc = new XmlDocument();
> qDoc.LoadXml(messageToQueue);
> //serialize & q message
> System.Xml.Serialization.XmlSerializer x = new
> System.Xml.Serialization.XmlSerializer(qDoc.GetType());
> MessageQueue MQueue = new MessageQueue(qPath);
> //MQueue.Path = queuePath;
>
>
> // Create an MSMQ message and send it to receive port queue
> System.Messaging.Message MsgOut = new System.Messaging.Message();
>
> //MsgOut.ResponseQueue = responseQueue;
> MsgOut.Priority = MessagePriority.Normal;
> //MsgOut.UseJournalQueue = true;
> MsgOut.Label = qDoc.GetType().ToString();
>
> //MsgOut.CorrelationId = coID;
> //MsgOut.Recoverable = true;
>
>
> x.Serialize(MsgOut.BodyStream, qDoc);
> try
> {
> MQueue.Send(MsgOut);
> }
> catch ( Exception e )
> {
> outstring = "Error";
> log.Error("Failed to Q Referral to "+qPath, e);
>
> }
> // close the message queue
> MQueue.Close();
> return outstring;
>



Tomas Restrepo \(MVP\)

2005-10-24, 10:37 am

Namshub,

>
> When I submit the string in the message queue it automatically defaults to
> the XMLFormmater and puts the wrapper around the message.


I would just forgo the XmlFormatter. The only reliable way to send messages
to biztalk using System.Messaging (and receiving them from biztalk) is *not*
to use any message formatter, and instead simply write the message directly
to the Message's BodyStream.

In your case, this would allow you to avoid the XML tags, and then simply
use the FlatFileDisassembler in a receive pipeline to parse the message.

Here's an example:


MessageQueue queue = new MessageQueue("...");

string contents = @"MESSAGE CONTENTS HERE";

MessageQueueTransaction tx = new MessageQueueTransaction();
tx.Begin();
try {
Message msg = new Message();
StreamWriter writer =
new StreamWriter(msg.BodyStream, Encoding.Unicode);
writer.Write(contents);
writer.Flush();
queue.Send(msg, tx);
tx.Commit();
} catch ( Exception e ) {
Console.WriteLine(e);
tx.Abort();
}


--
Tomas Restrepo
tomasr@mvps.org
http://www.winterdom.com/


Namshub

2005-10-24, 10:37 am

U are a GOD!!!!!

I've spent the best part of a week trying to figure out how to get this to
work.... and now it does thanks to you...

So Thanks...
+ i've bookedmarked your website... ;-)

Ric



"Tomas Restrepo (MVP)" <tomasr@mvps.org> wrote in message
news:uQh%23d$W1FHA.3300@TK2MSFTNGP15.phx.gbl...
> Namshub,
>
>
> I would just forgo the XmlFormatter. The only reliable way to send
> messages to biztalk using System.Messaging (and receiving them from
> biztalk) is *not* to use any message formatter, and instead simply write
> the message directly to the Message's BodyStream.
>
> In your case, this would allow you to avoid the XML tags, and then simply
> use the FlatFileDisassembler in a receive pipeline to parse the message.
>
> Here's an example:
>
>
> MessageQueue queue = new MessageQueue("...");
>
> string contents = @"MESSAGE CONTENTS HERE";
>
> MessageQueueTransaction tx = new MessageQueueTransaction();
> tx.Begin();
> try {
> Message msg = new Message();
> StreamWriter writer =
> new StreamWriter(msg.BodyStream, Encoding.Unicode);
> writer.Write(contents);
> writer.Flush();
> queue.Send(msg, tx);
> tx.Commit();
> } catch ( Exception e ) {
> Console.WriteLine(e);
> tx.Abort();
> }
>
>
> --
> Tomas Restrepo
> tomasr@mvps.org
> http://www.winterdom.com/
>



Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com