I'm building a message queue on Azure using Service Bus, working through the PHP SDK, and am having some problems with PeekLock messages timing out too quickly.
I can connect to the queue and retrieve a message using PeekLock, however, if I take longer than five seconds to delete the message, Azure throws a 404 error indicating that the lock has expired, and the message is put back into the queue as though it had never been processed.
Here's an example of some test code I've used. Assume in this example that the Azure SDK is loaded and the appropriate namespaces have been referenced.
<?php
// .. load the sdk and namespaces etc ...
$service_bus = ServicesBuilder::getInstance()->createServiceBusService([connection string goes here]);
$options = new ReceiveMessageOptions();
$options->setPeekLock();
$message = $service_bus->receiveQueueMessage("[queue name here]", $options);
print "message body is: " . $message->getBody();
$service_bus->deleteMessage($message);
?>
This code executes perfectly - the message is retrieved, the body is displayed, and the message is deleted. However, if I insert a sleep(5);
just before the deleteMessage() call, the Service Bus API returns the following error:
Error: The lock supplied is invalid. Either the lock expired, or the message has already been removed from the queue.
When creating the queue via the Azure portal, I explicitly set the lock timeout period to five minutes, and I've experimented with setting different timeout periods on other queues and all of them still revert to a five second expiry.
What am I doing wrong here?
Issue Resolved:
I got a reply from the Azure support team, who quickly figured out that the Azure portal isn't persisting the lock duration that's selected when creating a queue. The default expiry is apparently five seconds (although I couldn't find any references to this default value in any of the docs, which is annoying) which is why it was timing out.
So anyway, the dev team are apparently working on a fix, and everything should be working soon.