Reputation: 882
I have ServiceStack service registered as a message queue handler. While the service is handling a message and an error is encountered I would like to pull the remaining messages from the queue and send them to a different queue. Here is the code I am trying to use.
if (error)
{
using (var mqClient = TryResolve<IMessageFactory>().CreateMessageQueueClient())
{
var callMessage = mqClient.Get<CallMessage>(QueueNames<CallMessage>.In);
while (callMessage != null)
{
mqClient.Ack(callMessage);
PublishMessage(new TextMessage { Text = callMessage.Text });
// Get the next message. Null is returned when the queue is empty
callMessage = mqClient.Get<CallMessage>(QueueNames<CallMessage>.In);
}
}
}
However, upon calling mqClient.Get the CallMessage queue seems to get deadlocked with an active Unacked message.
What is the proper technique for pulling messages from a queue and republishing them to a different queue?
Upvotes: 0
Views: 1089
Reputation: 143339
You want to instead use IMessageQueueClient.GetAsync
to retrieve a message from a queue, which will either return the next message or null
if there are no more messages pending.
IMessageQueueClient.Get
is a synchronous blocking Get that will block until it receives a message or the optional timeout has elapsed, if no timeout is given it will block forever until it receives a message.
Upvotes: 1