public function get($queueName, $timeout = null)
 {
     // Simulate timeout
     $tic = time();
     do {
         $workload = $this->parseResponse($this->sqs->receive_message($queueName))->ReceiveMessageResult->Message;
         if ($workload) {
             $this->parseResponse($this->sqs->delete_message($queueName, strval($workload->ReceiptHandle)));
             if (md5($workload->Body) == $workload->MD5OfBody) {
                 return unserialize($workload->Body);
             } else {
                 throw new \RuntimeException('Corrupted response');
             }
         } else {
             // Wait
             sleep(1);
         }
     } while (null !== $timeout && time() - $tic < $timeout);
     return null;
 }
<?php

require_once '/usr/share/php/AWSSDKforPHP/sdk.class.php';
define('AWS_KEY', 'AKIAIGKECZXA7AEIJLMQ');
define('AWS_SECRET_KEY', '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');
define('AWS_ACCOUNT_ID', '457964863276');
$queue_name = $_GET['queue'];
$sqs = new AmazonSQS();
$sqs->set_region($sqs::REGION_EU_W1);
$queue = $sqs->create_queue($queue_name);
$queue->isOK() or die('could not create queue ' + $queue_name);
$receive_response = $sqs->receive_message($queue->body->QueueUrl(0));
$delete_response = $sqs->delete_message($queue->body->QueueUrl(0), (string) $receive_response->body->ReceiptHandle(0));
$body = json_decode($receive_response->body->Body(0));
pr($body);
function pr($var)
{
    print '<pre>';
    print_r($var);
    print '</pre>';
}
 * License.
 */
error_reporting(E_ALL);
require_once 'sdk.class.php';
// Make sure that an argument was supplied
if ($argc != 2) {
    exit("Usage: " . $argv[0] . " QUEUE_NAME\n");
}
// Create the SQS access object
$sqs = new AmazonSQS();
$queueName = $argv[1];
// Get URL for queue
$queueURL = $sqs->create_queue($queueName)->body->CreateQueueResult->QueueUrl;
// Poll for new items
while (true) {
    $res = $sqs->receive_message($queueURL);
    if ($res->isOK()) {
        if (isset($res->body->ReceiveMessageResult->Message)) {
            $message = $res->body->ReceiveMessageResult->Message;
            $messageBody = $message->Body;
            $receiptHandle = (string) $message->ReceiptHandle;
            print "Message: '{$messageBody}'\n";
            $sqs->delete_message($queueURL, $receiptHandle);
        } else {
            sleep(1);
        }
    } else {
        $error = $res->body->Error->Message;
        print "Could not pull message from queue: {$error}\n";
    }
}
 /**
  * Method: receive_message()
  * 	Identical to <AmazonSQS::receive_message()>, except that you don't need to pass in a queue URL.
  * 
  * Access:
  * 	public
  * 
  * Parameters:
  * 	opt - See <AmazonSQS::receive_message()>.
  * 
  * Returns:
  * 	<TarzanHTTPResponse> object
  * 
  * See Also:
  * 	Example Usage - http://tarzan-aws.com/docs/examples/sqsqueue/receive_message.phps
  */
 public function receive_message($opt = null)
 {
     if ($this->queue_url) {
         return parent::receive_message($this->queue_url, $opt);
     }
     throw new SQSQueue_Exception(SQSQUEUE_DEFAULT_ERROR);
 }
示例#5
0
<?php

define('_PS_ADMIN_DIR_', getcwd());
define('PS_ADMIN_DIR', _PS_ADMIN_DIR_);
// Retro-compatibility
include PS_ADMIN_DIR . '/../config/config.inc.php';
include PS_ADMIN_DIR . '/functions.php';
$sqs = new AmazonSQS();
$sqs->set_region(AmazonSQS::REGION_APAC_SE1);
$db = Db::getInstance(_PS_USE_SQL_SLAVE_);
for ($count = 1; $count < 10; $count++) {
    $response = $sqs->receive_message(INVITE_QUEUE);
    if (!$response->body->ReceiveMessageResult->Message) {
        sleep(5);
    } else {
        if (processMessage($response, $db)) {
        }
        $handle = $response->body->ReceiveMessageResult->Message->ReceiptHandle;
        $sqs->delete_message(INVITE_QUEUE, $handle);
    }
}
/**
 * @param unknown_type $response
 * @param Db $db
 * @return boolean
 */
function processMessage($response, $db)
{
    echo $response->body->ReceiveMessageResult->Message->Body . PHP_EOL;
    $message = Tools::jsonDecode($response->body->ReceiveMessageResult->Message->Body, true);
    $id_customer = $message['id_customer'];
示例#6
0
$delete = 'true';
if ($argc > 1 && $argv[1] == "--no-delete") {
    $delete = 'false';
    array_splice($argv, 1, 1);
    $argc--;
}
// Make sure that an argument was supplied
if ($argc != 2) {
    exit("Usage: " . $argv[0] . " [--no-delete] QUEUE_NAME\n");
}
// Create the SQS access object
$sqs = new AmazonSQS();
$queueName = $argv[1];
// Poll for new items
while (true) {
    $res = $sqs->receive_message($queueName);
    if ($res->isOK()) {
        if (isset($res->body->ReceiveMessageResult->Message)) {
            $message = $res->body->ReceiveMessageResult->Message;
            $messageBody = $message->Body;
            $receiptHandle = (string) $message->ReceiptHandle;
            print "Message: '{$messageBody}'\n";
            if ($delete == 'true') {
                $sqs->delete_message($queueName, $receiptHandle);
            }
        } else {
            sleep(1);
        }
    } else {
        $error = $res->body->Error->Message;
        print "Could not pull message from queue: {$error}\n";
 public static function setAsideCron()
 {
     self::echomsg(null, "Start Sudarshan Stock Sync - SetAside", true);
     $sqs = new AmazonSQS();
     $sqs->set_region(AmazonSQS::REGION_APAC_SE1);
     $db = Db::getInstance(_PS_USE_SQL_SLAVE_);
     $updates = false;
     while (true) {
         $response = $sqs->receive_message(STOCK_SYNC_QUEUE);
         if (!$response->body->ReceiveMessageResult->Message) {
             break;
         } else {
             $updates = true;
             self::echomsg(null, "--------------------------------------------------", true);
             $message = Tools::jsonDecode($response->body->ReceiveMessageResult->Message->Body, true);
             $supplier_reference = $message['supplier_reference'];
             $sup_details = explode("::", $supplier_reference);
             if (count($sup_details) !== 2) {
                 self::echomsg($message, "Action Needed - Invalid Vendor Code. Manual SetAside needed", true);
             } else {
                 $design_no = $sup_details[0];
                 $item_code = $sup_details[1];
                 $id_product = $message["id_product"];
                 $reference = $message["reference"];
                 $id_order = $message["id_order"];
                 $quantity = (int) $message["quantity"];
                 $product = array();
                 $product['id_product'] = $id_product;
                 $product['reference'] = $reference;
                 $product['supplier_reference'] = $supplier_reference;
                 $product['id_order'] = $id_order;
                 self::echomsg($product, "Quantity #{$quantity} - Waiting for SetAside Update");
                 for ($i = 1; $i <= $quantity; $i++) {
                     try {
                         $client = self::getClient();
                         $data = array("Itemcode" => $item_code, "DesignNo" => $design_no, "OrderNo" => (string) $id_order, "Size" => "-");
                         $result = $client->SetAside($data);
                         if ((int) $result->SetAsideResult === 1) {
                             self::echomsg($product, "SetAside success", true);
                         } else {
                             self::echomsg($product, "Manual SetAside Action Needed - System SetAside Failed", true);
                         }
                     } catch (Exception $ex) {
                         $ex_msg = $ex->getMessage();
                         if (stripos($ex_msg, "is insufficient for the requested quantity")) {
                             self::echomsg($product, "<b>Out of Stock</b>", true);
                         } else {
                             self::send_tech_mail('Stock Sync Update SetAside', "Set Aside API Failed");
                             self::echomsg($product, "Manual SetAside Action Needed - System SetAside Failed", true);
                         }
                     }
                 }
             }
             $handle = $response->body->ReceiveMessageResult->Message->ReceiptHandle;
             $sqs->delete_message(STOCK_SYNC_QUEUE, $handle);
         }
     }
     self::echomsg(null, "--------------------------------------------------", true);
     self::echomsg(null, "End Sudarshan Stock Sync - SetAside", true);
     if ($updates) {
         self::send_log_mail('Set Aside');
     }
     return true;
 }
<?php

define('_PS_ADMIN_DIR_', getcwd());
define('PS_ADMIN_DIR', _PS_ADMIN_DIR_);
// Retro-compatibility
include PS_ADMIN_DIR . '/../config/config.inc.php';
include PS_ADMIN_DIR . '/rules/rules_base.php';
echo "\nRule Processor Triggered";
//VBRewards::removeRewards(17, 7, 1, 210, 'testing delete', 12, $date = false);
$db = Db::getInstance(_PS_USE_SQL_SLAVE_);
$sqs = new AmazonSQS();
$sqs->set_region(AmazonSQS::REGION_APAC_SE1);
$db = Db::getInstance(_PS_USE_SQL_SLAVE_);
for ($count = 1; $count < 10; $count++) {
    $response = $sqs->receive_message(RULES_QUEUE);
    if (!$response->body->ReceiveMessageResult->Message) {
        sleep(0);
    } else {
        if (processMessage($response, $db)) {
        }
        $handle = $response->body->ReceiveMessageResult->Message->ReceiptHandle;
        $sqs->delete_message(RULES_QUEUE, $handle);
    }
}
function processMessage($response, $db)
{
    echo $response->body->ReceiveMessageResult->Message->Body . PHP_EOL;
    //$message = Tools::jsonDecode('{"id_event":5,"date_event":"2012-03-14 13:07:18","reference":"274","id_customer":"10687"}', true);
    $message = Tools::jsonDecode($response->body->ReceiveMessageResult->Message->Body, true);
    $id_event = $message['id_event'];
    $res = $db->ExecuteS("select le.id_event, le.name as 'event_name', r.id_rule, r.name as 'rule_name', re.execute_sequence\n\t\t\t\t\t\t\tfrom vb_rules r\n\t\t\t\t\t\t\tinner join vb_loyalty_rule_events re on (r.id_rule = re.id_rule)\n\t\t\t\t\t\t\tinner join vb_loyalty_events le on le.id_event = re.id_event\n\t\t\t\t\t\t\twhere le.id_event = " . $message['id_event'] . " order by le.id_event, re.execute_sequence");