开发者

Find old messages in MSMQ

I this scenario there are two queues. "Error" and "MyQueue".

The messages are dumped into MyQueue and processed from there. If they fail they are moved to the Error queue. An administration might move a message back into the MyQueue for processing again.

My task if to scan/peek the two queue to find and count all the messages that has been 开发者_C百科cycling around for more than one hour.

It seems that

message.SentTime
message.ArrivedTime

are both useless, since they are updated each time the message enters a queue.

On solution would be to place an timestamp in the body of the message, this would however require me to open all messages to determine if the message is "old".

Any better alternatives?


The problem is that it is not the same message cycling round the queues. "Moving" a message is normally deleting the original and creating a new one based on the original contents, which is why you can't use the sent and arrived times.

Do the moved messages have new unique MessageID values each time? If not then maybe you could generate a table matching MessageID to the time it was initially created.

Cheers
John Breakwell


You might be able to use the AppSpecific property of the Message class for this. Unfortunately it's a 32-bit integer; if it were a long you could store DateTime.Ticks there and then use that as the timestamp you need to calculate how long the message has been around.

You could lose some of the bits in Ticks to fit the value into AppSpecific like this:

ticksInt = (int) DateTime.Now.Ticks >> 23;

This gives you second-scale precision which I assume is enough for your case... however you can't use the built-in DateTime or TimeSpan methods that convert back from Ticks if you do this, so you'll have to convert manually, or just calculate the delta between Now and this value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜