简体   繁体   中英

put a message into msmq with the message expiration time out

If there is an out of the box way to put a message into msmq with a defined expiration time out. under expiration I mean the following scenario:

  • a message sender sends messages into a queue quite frequently
 message 1 published at 1:00 message 2 published at 1:02 message 3 published at 1:04 
  • a message reciever takes a message from the queue and runs a time expencive procedure

message 1 recieved at 1:00 and processed at 1:05

  • by the application logic it make sence to process messages which are not older a particular time frame

we shold process messages that are not older than 1 min so uder this requirement I wish that message 2 would disappeared from the queue

Questions:

  • can I archive that by an out of the box functionality?
  • if not? what would is the best practice to do this?
  • is msmq is correct technology for this use case in principle? Which one would suit the requrement better?

The Message class has a TimeToBeReceived property (see MSDN ). I think it should meet your requirement.

Also, it seems to me that your system cannot consume messages at the same pace as it produces them. It's difficult to tell without knowing further details about the system, but it may be worth exploring the possibility of consuming the messages in parallel (if you are not already doing that).

如果您可以访问Producer / Consumer的源代码,则可以在内存中共享队列,并使用LINQ过滤预期时间范围内的消息并处理它们

The System.Messaging.Message class has a property for TimeToBeReceived which will cause the message to be ignores (or posted to the bad letter queue) if it times out.

The only issue is that you have to be sure that the time on the client-side is synchronised with the time on the server side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM