Search code examples
phpmessage-queuemsmq

Setting Recoverable attribute for MSMQ messages in PHP


I'd like to set a Recoverable attribute form messages which I'm sending to MSMQ. I've been searching some resources how to do this in PHP but I haven't found any. I've tried this

    if(!$msgOut = new COM("MSMQ.MSMQMessage")){
        return false;
    }           

    $msgOut->Body = $this->getBody(); 
    $msgOut->Label = $this->getLabel();
    $msgOut->Recoverable = true;
    $msgOut->Send($msgQueue); 

but it does not work. I've also tried to set the boolean as a string value and integer but none of it worked. When I try $msgOut->Recoverable = "true"; or $msgOut->Recoverable = true; I got com_exception

Unable to lookup `Recoverable': Unknown name.


Solution

  • There is no recoverable property, so this line is wrong:

    $msgOut->Recoverable = true;
    

    According the documentation of the class MSMQMessage, the property name should be "Delivery" and value is MQMSG_DELIVERY_RECOVERABLE:

    public const int MQMSG_DELIVERY_EXPRESS = 0;
    public const int MQMSG_DELIVERY_RECOVERABLE = 1;
    

    You can send recoverable message in this way:

    $msgOut->Body = $this->getBody(); 
    $msgOut->Label = $this->getLabel();
    $msgOut->Delivery = 1;
    $msgOut->Send($msgQueue);