Badaro
Badaro

Reputation: 3480

Lookup by an arbitrary identifier in MSMQ?

Is there a way to assign an identifier to a message in MSMQ, then later locate that message (if it's still in the queue) by that identifier?

Being more specific, it need to be a unique identifier under my control, not something assigned by MSMQ.

Upvotes: 1

Views: 1143

Answers (2)

kirotnes
kirotnes

Reputation: 259

Why not use CorrelationId?

var message = new Message(new Messageval(), new BinaryMessageFormatter());
message.CorrelationId = messageId;
queue.Send(message);

And then retrieve the message like this:

var resp = (Messageval) queue.ReceiveByCorrelationId(messageId,
                                                     TimeSpan.FromSeconds(30))
                             .Body;

The CorrelationId needs to consist of exactly 20 bytes or else an exception will be thrown upon assignment.

Upvotes: 2

Filburt
Filburt

Reputation: 18082

You could use the messages Label property if you want to use an identifier that is created before the message is sent.

The message LookupID identifier is not accessible until the message has been sent.

Upvotes: 3

Related Questions