none
Parameter input from MSMQ Rule problem ! RRS feed

  • Question

  • I have a MSMQ Trigger that uses a RULE.

    The Rule has the MSMQ body sent as a parameter to the executable

    The executable was tested with the same body as debug command line that the queue sends.

    The debug command line I can read, the same default XML comes out as Chinese characters... and I cannot find the JSON delimiters or load it into Xdocument or XMLDocument..

    I have tried send Message body as string and message body as variant but results are the same.

    Message bodyType is default ....

    Other have designed the message body as XML as input, any ideas ??  Someone must have seen this before !

    Thanks !!!

    Rule to send body of queue as input parameter

    Image as body appears in queue

    Args ( input parameter for queue item )


    andrew

    Thursday, October 19, 2017 6:02 PM

Answers

  • Hi Edward,

    I wanted to be able to consume either content passed as XML or content passed as JSON by way of loading the paramter from the queue ( without directly reading the queue. 

    There does NOT appear to be a way to use XML  AND also load the body via the parameter for the rule ( invoked by the MSMQ trigger ).

    We will use plain text ( that it contains Json formatting is not relevant )  because it appears as the only way parameters ( meaning the message body ) can be passed to the args in the executable.   I dont consider the situation solved, but rather it should be noted somewhere on MSDN that its a limitation

    Also  I cannot recommend using the activeXformt because it lost the last } in the string....

    Only using the stream method is reliable for passingt the body  as an argument

      System.IO.StreamWriter writer = new System.IO.StreamWriter(message.BodyStream, Encoding.Unicode);
               writer.Write(inputSample);
                writer.Flush();
               message.BodyType = 8;
                myQueue.Send(message);

    Thanks Andrew


    andrew



    • Edited by andrewcw Tuesday, October 24, 2017 3:34 AM clarify
    • Marked as answer by andrewcw Tuesday, October 24, 2017 3:35 AM
    Tuesday, October 24, 2017 3:31 AM

All replies

  • Hi Andrew,

    Could you share us a simple project and detail steps? Then, we could try to reproduce your issue at our side.

    Based on your description, it seems you want to get the value in queue and convert it to JSON. Based on Body image, could you get the Json string in exe application? I think you could try convert the string “{‘imageName’:’xxxx’}” to Json object.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, October 20, 2017 2:06 AM
  • Thanks Edward Z. It is true , if I coerce the developers touse a non XML body, then I dont have a problem.  But we cannot always count on that leverage.

    Heres simple code to reproduce / generate the 2 message with txt & xml bodies in the same queue.  etc. 

    Step 1. Create console app Test2QueBodies

    static void Main(string[] args)
            {

                MessageQueue myQueue = new MessageQueue(".\\private$\\wcf"); 
                Message message = new Message();
                message.Label = "TXT";
                string inputSample = @"{'key':'value'}";
                System.IO.StreamWriter writer = new System.IO.StreamWriter(message.BodyStream, Encoding.Unicode);
                writer.Write(inputSample);
                writer.Flush();
                message.BodyType = 8;
                myQueue.Send(message);
                // now XML style
                message.Label = "XML";
                message.Body = inputSample;
                myQueue.Send(message);

          }

    Step 2 create a reader ParamTest.exe for the the messages

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.IO;

    namespace ParamTest
    {
        class Program
        {
            static void Main(string[] args)
            {
                for (int i= 0; i< args.Length; i++)
                {
                    Console.WriteLine(args[i]);
                    using (StreamWriter strw = File.AppendText("QuickLog2.txt"))
                    {    
                        strw.WriteLine(args[i]);
                    }

                }
                using (StreamWriter strw = File.AppendText("QuickLog2.txt"))
                {
                    strw.WriteLine("Done with ParamTest.exe: " + DateTime.Now.ToString());
                }
            }
        }
    }

    Step 3  make 2 rules

    Rule TXT   Condition  Message label contains "TXT"   Rule Action ( invoke exe to read args ) parameters select /add Message body (as string )

    Rule XML   Condition  Message label contains "XML"   Rule Action ( invoke exe to read args ) parameters select /add Message body (as string )

    Both rules nearly identical except for the label

    Step 4. Create the trigger on the queue and add Rule TXT and Rule XML  & enable

    Step 5. Run Test2QueBodies... generates the 2 messages... & ideally ParamTest.exe is started...

    Step 6.  examine QuickLog2.txt   { for the XML I get Chinese characters .... )

    Thanks Andrew


    andrew

    Friday, October 20, 2017 4:25 PM
  • Hi Andrew,

    I made a test with your steps, and I could get the same result.

    In my option, it is caused by that passing body value from Message Queue to exe args. While setting body value, it is serialized by XmlMessageFormatter. Before processing the body, we need to de-serialize the body content. While we custom the receive of Message Queue, we could achieve it. But, we could not custom it while MSMQ passing the body from message to exe application.

    In general, we send string body by BodyStream which would not cause this issue. If you want to set string body directly, I suggest you set the Formatter like below.

    MessageQueue myQueue = new MessageQueue(".\\private$\\wcf");
                Message message = new Message();
                string inputSample = @"{'key':'value'}";            
                message.Label = "XML";
                message.Formatter = new ActiveXMessageFormatter();
                message.Body = inputSample;
                myQueue.Send(message);

    Best Regards,

    Edward

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, October 23, 2017 6:15 AM
  • Hi Edward !

    Thanks for your reply.  The original goal was

    1. have the string  be represented as XML in the queue

    2. Extract that XML by way of having the body ( xml ) passed by the rule as a parameter to the exe of the rule.

    When we use

    message.Formatter = new ActiveXMessageFormatter();

    2 things happen

    1. the queue now has a string but its not the XML

    2. the string in the queue is missing the closing brace ( "}" ).  At least that's what I found, did you  ?

    Currently to get the body of the message passed from the queue via the rule

    I am forced to require the input to be using code as you earlier showed me.  ( no XML in queue )

              System.IO.StreamWriter writer = new System.IO.StreamWriter(message.BodyStream, Encoding.Unicode);
               writer.Write(inputSample);
                writer.Flush();
               message.BodyType = 8;
                myQueue.Send(message);

    Thanks ...!


    andrew


    • Edited by andrewcw Monday, October 23, 2017 6:36 PM clarity
    Monday, October 23, 2017 6:35 PM
  • Hi andrewcw,

    >> have the string  be represented as XML in the queue

    You send a Json string to Queue, what is XML string do you want in the queue? If you need XML string, you need to send XML instead of Json string.

    Since your original issue related with “the same default XML comes out as Chinese characters” has been resolved, I would suggest you mark the helpful reply as answer to close current thread.

    For this new issue related with sending XML messing to Queue, I would suggest you post a new thread, and then we could focus on this new issue.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, October 24, 2017 2:39 AM
  • Hi Edward,

    I wanted to be able to consume either content passed as XML or content passed as JSON by way of loading the paramter from the queue ( without directly reading the queue. 

    There does NOT appear to be a way to use XML  AND also load the body via the parameter for the rule ( invoked by the MSMQ trigger ).

    We will use plain text ( that it contains Json formatting is not relevant )  because it appears as the only way parameters ( meaning the message body ) can be passed to the args in the executable.   I dont consider the situation solved, but rather it should be noted somewhere on MSDN that its a limitation

    Also  I cannot recommend using the activeXformt because it lost the last } in the string....

    Only using the stream method is reliable for passingt the body  as an argument

      System.IO.StreamWriter writer = new System.IO.StreamWriter(message.BodyStream, Encoding.Unicode);
               writer.Write(inputSample);
                writer.Flush();
               message.BodyType = 8;
                myQueue.Send(message);

    Thanks Andrew


    andrew



    • Edited by andrewcw Tuesday, October 24, 2017 3:34 AM clarify
    • Marked as answer by andrewcw Tuesday, October 24, 2017 3:35 AM
    Tuesday, October 24, 2017 3:31 AM