I have an MSMQ which would be used almost as some form of "Schedule queue" for sending out tweets at specific time (Think of it as setting a time to send a specific tweet out).
I have sort of ran into a brick wall in how I would retrieve items from the queue. I am aware of the Peek()
and Remove()
methods, and they work, but they wouldn't remove the item which is next scheduled to be processed, they would simply only retrieve the the oldest item on the queue.
I have also had a look at using the TimeToBeReceived
property, but it doesn't seem to make much difference.
If I was to add an message to the queue, with the TimeToBeReceived
property of the next hour, I shouldn't expect to be able to retrieve it for the next hour, it the RetrieveNextItem()
method I have written should either return nothing at all or the next item where the time has passed. Could anyone explain to me how I would accomplish this?
Please see my code below to get an general idea on what I already have.
public void AddItemToQueue(IScheduledTweet scheduledTweet)
{
MessageQueue messageQueue = new MessageQueue(@".\Private$\TwitterBot");
Message message = new Message();
message.Body = scheduledTweet;
message.TimeToBeReceived = scheduledTweet.Time.TimeOfDay;
messageQueue.Send(scheduledTweet);
}
public IScheduledTweet RetrieveNextItem()
{
IScheduledTweet returnValue;
MessageQueue messageQueue;
messageQueue = new MessageQueue(@".\Private$\TwitterBot");
messageQueue.MessageReadPropertyFilter.TimeToBeReceived = true;
messageQueue.Formatter = new XmlMessageFormatter(new Type[] { typeof(ScheduledTweet) });
// I expect the message variable to be a message where its TimeToBeReceived property is either equal to the current time, or past the time.
Message message = messageQueue.Peek();
returnValue = (ScheduledTweet)message.Body;
return returnValue;
}