Search code examples
c#msmq

MSMQ Message ID (as Variant)


I have a MSMQ Trigger that opens a standalone executable. The Rule Action passes the Message ID (as variant) as an invocation parameter. I then use the message id to receive the message via Queue.ReceiveById().

Everything is working fine, but there is a little catch. The Message ID is sent like this:

{5EADA58F-C733-48C3-A52A-A9FA749E7ADF}\2063

But the Queue.ReceiveById() function requires the Message ID to look like this (without brackets)

5EADA58F-C733-48C3-A52A-A9FA749E7ADF\2063

Can someone explain to me what the curly brackets mean? Is there a proper way to convert this (other than just removing the brackets)?

Edit: I should make explicit that the Message ID is being passed as a string, since it is being passed as a command-line argument to the EXE


Solution

  • The ID is a Guid plus an additional identifier:

    The identifier is composed of 20 bytes and includes two items: the machine Guid of the sending computer and a unique identifier for the message on the computer. The combination of the two items produces a message identifier that is unique on the network.

    So there's no build-in parsing/reformatting function that I know of.

    If you want to "parse" the guid part of the string to reformat it, you could do do something like:

    string id = @"{5EADA58F-C733-48C3-A52A-A9FA749E7ADF}\2063";
    string[] parts = id.Split('\\');
    Guid g = Guid.Parse(parts[0]);
    string newID = String.Join("\\",g.ToString("D").ToUpper(),parts[1]);
    

    You might find that more "elegant", but it seems heavy to just remove a couple of curly braces.