/**
 * Receive Message Action Sample
 * Retrieves one or more messages from the specified queue.  For each message returned, the response includes the message body; MD5 digest of the message body; receipt handle, which is the identifier you must provide when deleting the message; and message ID of each message. Messages returned by this action stay in the queue until you delete them. However, once a message is returned to a ReceiveMessage request, it is not returned on subsequent ReceiveMessage requests for the duration of the VisibilityTimeout. If you do not specify a VisibilityTimeout in the request, the overall visibility timeout for the queue is used for the returned messages.
 *   
 * @param Amazon_SQS_Interface $service instance of Amazon_SQS_Interface
 * @param mixed $request Amazon_SQS_Model_ReceiveMessage or array of parameters
 */
function invokeReceiveMessage(Amazon_SQS_Interface $service, $request)
{
    try {
        $response = $service->receiveMessage($request);
        echo "Service Response\n";
        echo "=============================================================================\n";
        echo "        ReceiveMessageResponse\n";
        if ($response->isSetReceiveMessageResult()) {
            echo "            ReceiveMessageResult\n";
            $receiveMessageResult = $response->getReceiveMessageResult();
            $messageList = $receiveMessageResult->getMessage();
            foreach ($messageList as $message) {
                echo "                Message\n";
                if ($message->isSetMessageId()) {
                    echo "                    MessageId\n";
                    echo "                        " . $message->getMessageId() . "\n";
                }
                if ($message->isSetReceiptHandle()) {
                    echo "                    ReceiptHandle\n";
                    echo "                        " . $message->getReceiptHandle() . "\n";
                }
                if ($message->isSetMD5OfBody()) {
                    echo "                    MD5OfBody\n";
                    echo "                        " . $message->getMD5OfBody() . "\n";
                }
                if ($message->isSetBody()) {
                    echo "                    Body\n";
                    echo "                        " . $message->getBody() . "\n";
                }
                $attributeList = $message->getAttribute();
                foreach ($attributeList as $attribute) {
                    echo "                    Attribute\n";
                    if ($attribute->isSetName()) {
                        echo "                        Name\n";
                        echo "                            " . $attribute->getName() . "\n";
                    }
                    if ($attribute->isSetValue()) {
                        echo "                        Value\n";
                        echo "                            " . $attribute->getValue() . "\n";
                    }
                }
            }
        }
        if ($response->isSetResponseMetadata()) {
            echo "            ResponseMetadata\n";
            $responseMetadata = $response->getResponseMetadata();
            if ($responseMetadata->isSetRequestId()) {
                echo "                RequestId\n";
                echo "                    " . $responseMetadata->getRequestId() . "\n";
            }
        }
    } catch (Amazon_SQS_Exception $ex) {
        echo "Caught Exception: " . $ex->getMessage() . "\n";
        echo "Response Status Code: " . $ex->getStatusCode() . "\n";
        echo "Error Code: " . $ex->getErrorCode() . "\n";
        echo "Error Type: " . $ex->getErrorType() . "\n";
        echo "Request ID: " . $ex->getRequestId() . "\n";
        echo "XML: " . $ex->getXML() . "\n";
    }
}
Esempio n. 2
0
/**
 * List Queues Action Sample
 * 
 * The ListQueues action returns a list of your queues.
 *   
 * @param Amazon_SQS_Interface $service instance of Amazon_SQS_Interface
 * @param mixed $request Amazon_SQS_Model_ListQueues or array of parameters
 */
function invokeListQueues(Amazon_SQS_Interface $service, $request)
{
    try {
        $response = $service->listQueues($request);
        echo "Service Response\n";
        echo "=============================================================================\n";
        echo "        ListQueuesResponse\n";
        if ($response->isSetListQueuesResult()) {
            echo "            ListQueuesResult\n";
            $listQueuesResult = $response->getListQueuesResult();
            $queueUrlList = $listQueuesResult->getQueueUrl();
            foreach ($queueUrlList as $queueUrl) {
                echo "                QueueUrl\n";
                echo "                    " . $queueUrl;
            }
        }
        if ($response->isSetResponseMetadata()) {
            echo "            ResponseMetadata\n";
            $responseMetadata = $response->getResponseMetadata();
            if ($responseMetadata->isSetRequestId()) {
                echo "                RequestId\n";
                echo "                    " . $responseMetadata->getRequestId() . "\n";
            }
        }
    } catch (Amazon_SQS_Exception $ex) {
        echo "Caught Exception: " . $ex->getMessage() . "\n";
        echo "Response Status Code: " . $ex->getStatusCode() . "\n";
        echo "Error Code: " . $ex->getErrorCode() . "\n";
        echo "Error Type: " . $ex->getErrorType() . "\n";
        echo "Request ID: " . $ex->getRequestId() . "\n";
        echo "XML: " . $ex->getXML() . "\n";
    }
}
/**
 * Get Queue Attributes Action Sample
 * 
 * Gets one or all attributes of a queue. Queues currently have two attributes you can get: ApproximateNumberOfMessages and VisibilityTimeout.
 *   
 * @param Amazon_SQS_Interface $service instance of Amazon_SQS_Interface
 * @param mixed $request Amazon_SQS_Model_GetQueueAttributes or array of parameters
 */
function invokeGetQueueAttributes(Amazon_SQS_Interface $service, $request)
{
    try {
        $response = $service->getQueueAttributes($request);
        echo "Service Response\n";
        echo "=============================================================================\n";
        echo "        GetQueueAttributesResponse\n";
        if ($response->isSetGetQueueAttributesResult()) {
            echo "            GetQueueAttributesResult\n";
            $getQueueAttributesResult = $response->getGetQueueAttributesResult();
            $attributeList = $getQueueAttributesResult->getAttribute();
            foreach ($attributeList as $attribute) {
                echo "                Attribute\n";
                if ($attribute->isSetName()) {
                    echo "                    Name\n";
                    echo "                        " . $attribute->getName() . "\n";
                }
                if ($attribute->isSetValue()) {
                    echo "                    Value\n";
                    echo "                        " . $attribute->getValue() . "\n";
                }
            }
        }
        if ($response->isSetResponseMetadata()) {
            echo "            ResponseMetadata\n";
            $responseMetadata = $response->getResponseMetadata();
            if ($responseMetadata->isSetRequestId()) {
                echo "                RequestId\n";
                echo "                    " . $responseMetadata->getRequestId() . "\n";
            }
        }
    } catch (Amazon_SQS_Exception $ex) {
        echo "Caught Exception: " . $ex->getMessage() . "\n";
        echo "Response Status Code: " . $ex->getStatusCode() . "\n";
        echo "Error Code: " . $ex->getErrorCode() . "\n";
        echo "Error Type: " . $ex->getErrorType() . "\n";
        echo "Request ID: " . $ex->getRequestId() . "\n";
        echo "XML: " . $ex->getXML() . "\n";
    }
}
/**
 * Remove Permission Action Sample
 * Removes the permission with the specified statement id from the queue.
 *   
 * @param Amazon_SQS_Interface $service instance of Amazon_SQS_Interface
 * @param mixed $request Amazon_SQS_Model_RemovePermission or array of parameters
 */
function invokeRemovePermission(Amazon_SQS_Interface $service, $request)
{
    try {
        $response = $service->removePermission($request);
        echo "Service Response\n";
        echo "=============================================================================\n";
        echo "        RemovePermissionResponse\n";
        if ($response->isSetResponseMetadata()) {
            echo "            ResponseMetadata\n";
            $responseMetadata = $response->getResponseMetadata();
            if ($responseMetadata->isSetRequestId()) {
                echo "                RequestId\n";
                echo "                    " . $responseMetadata->getRequestId() . "\n";
            }
        }
    } catch (Amazon_SQS_Exception $ex) {
        echo "Caught Exception: " . $ex->getMessage() . "\n";
        echo "Response Status Code: " . $ex->getStatusCode() . "\n";
        echo "Error Code: " . $ex->getErrorCode() . "\n";
        echo "Error Type: " . $ex->getErrorType() . "\n";
        echo "Request ID: " . $ex->getRequestId() . "\n";
        echo "XML: " . $ex->getXML() . "\n";
    }
}
Esempio n. 5
0
/**
 * Send Message Action Sample
 * The SendMessage action delivers a message to the specified queue.
 *   
 * @param Amazon_SQS_Interface $service instance of Amazon_SQS_Interface
 * @param mixed $request Amazon_SQS_Model_SendMessage or array of parameters
 */
function invokeSendMessage(Amazon_SQS_Interface $service, $request)
{
    try {
        $response = $service->sendMessage($request);
        echo "Service Response\n";
        echo "=============================================================================\n";
        echo "        SendMessageResponse\n";
        if ($response->isSetSendMessageResult()) {
            echo "            SendMessageResult\n";
            $sendMessageResult = $response->getSendMessageResult();
            if ($sendMessageResult->isSetMessageId()) {
                echo "                MessageId\n";
                echo "                    " . $sendMessageResult->getMessageId() . "\n";
            }
            if ($sendMessageResult->isSetMD5OfMessageBody()) {
                echo "                MD5OfMessageBody\n";
                echo "                    " . $sendMessageResult->getMD5OfMessageBody() . "\n";
            }
        }
        if ($response->isSetResponseMetadata()) {
            echo "            ResponseMetadata\n";
            $responseMetadata = $response->getResponseMetadata();
            if ($responseMetadata->isSetRequestId()) {
                echo "                RequestId\n";
                echo "                    " . $responseMetadata->getRequestId() . "\n";
            }
        }
    } catch (Amazon_SQS_Exception $ex) {
        echo "Caught Exception: " . $ex->getMessage() . "\n";
        echo "Response Status Code: " . $ex->getStatusCode() . "\n";
        echo "Error Code: " . $ex->getErrorCode() . "\n";
        echo "Error Type: " . $ex->getErrorType() . "\n";
        echo "Request ID: " . $ex->getRequestId() . "\n";
        echo "XML: " . $ex->getXML() . "\n";
    }
}