public static function run() { while (true) { $messageQueue = MessageQueue::getInstance(); $message = $messageQueue->getMessage(); if (false == $message) { print "no message in message queue\n"; sleep(20); } /* * Write code here to process the $message * * * * * * * * * */ /* * When finish process the $message,,ack the message */ $ret = DBUnACKQueue::ackMessage($message); if (false == $ret) { print "failed to ack message: {$message}\n"; sleep(10); } else { print "finish ack: {$message}\n"; } } }
public static function getInstance() { if (null === self::$_instance) { self::$_instance = new MessageQueue(); } return self::$_instance; }
public static function send($queueName, $message) { $client = MessageQueue::getInstance(); if ($client->publish($queueName, $message)) { return true; } else { return false; } }
public function send() { $c = new Encrypt(); $message = $c->encode(json_encode($this->attributes)); $q = MessageQueue::Get($account); try { $q->send($this->queue, $message); return TRUE; } catch (AWSException $ex) { return FALSE; } }
/** * Constructor. Private. * * @param unknown_type $name */ private function __construct($name) { $conf = Config::Get('cloud'); if (isset($conf->channel->items[$name])) { $this->queue = $name; $this->qmanager = MessageQueue::GetQueue($conf->channel->items[$name]->queue); $this->db = KeyValueDB::Get($conf->channel->items[$name]->db); $this->domain = $conf->channel->items[$name]->domain; } else { throw new Exception("Cannot find queue named '{$name}' in Config."); } }
public function processQueueOnShutdown($newsletterID) { if (class_exists('MessageQueue')) { //start processing of email sending for this newsletter ID after shutdown MessageQueue::send("newsletter", new MethodInvocationMessage('NewsletterSendController', "process_queue_invoke", $newsletterID)); MessageQueue::consume_on_shutdown(); } else { // Do the sending in real-time, if there is not MessageQueue to do it out-of-process. // Caution: Will only send the first batch (see $items_to_batch_process), // needs to be continued manually afterwards, e.g. through the "restart queue processing" // in the admin UI. $this->processQueue($newsletterID); } }
public function triggerReindex(LoggerInterface $logger, $batchSize, $taskName, $classes = null) { $queue = Config::inst()->get(__CLASS__, 'reindex_queue'); $logger->info('Queuing message'); MessageQueue::send($queue, new MethodInvocationMessage('SolrReindexMessageHandler', 'run_reindex', $batchSize, $taskName, $classes)); }
/** * Initializes the method we wan to test. * * @return void * @see PHPUnit_Framework_TestCase::setUp() */ protected function setUp() { $this->messageQueue = MessageQueue::createQueue(MessageQueueTest::NAME); }
<?php /** * URL rules for the CMS module * * @package newsletter */ if (!defined('NEWSLETTER_DIR')) { define('NEWSLETTER_DIR', basename(dirname(__FILE__))); } if (class_exists('MessageQueue')) { MessageQueue::add_interface("default", array("queues" => "/.*/", "implementation" => "SimpleDBMQ", "encoding" => "php_serialize", "send" => array("onShutdown" => "all"), "delivery" => array("onerror" => array("log")), "retrigger" => "no", "onShutdownMessageLimit" => "1")); } //SS_Log::add_writer(new SS_LogFileWriter(BASE_PATH . '/logN.txt'), SS_Log::NOTICE); //SS_Log::add_writer(new SS_LogFileWriter(BASE_PATH . '/logW.txt'), SS_Log::WARN); //SS_Log::add_writer(new SS_LogFileWriter(BASE_PATH . '/logE.txt'), SS_Log::ERR);
static function SendEmail($senderAddress, $senderName, $replyToAddress, $recipientAddress, $subject, $content, $contentType = "text/plain") { //save to db $email = new Email(); $email->simpleSave(Application::PARTNER_CODE, $senderAddress, $senderName, $recipientAddress, null, $subject, 'en', $contentType, $content); //queue $queueMessage = json_encode(array('emailId' => $email->getId())); $email->addEvent(EmailEventType::QUEUED); //this has to happen before actually placing on the queue //because the email must be flagged as queued to be processed $mq = MessageQueue::GetInstance(MessageQueue::LOCAL); $mq->send(MessageQueue::EMAIL_QUEUE, $queueMessage); return $email->getId(); /* //set addresses if (!is_null($senderName)) { $senderAddress = $senderName.' <'.$senderAddress.'>'; } //build headers $headers = ''; $headers .= 'From: '.$senderAddress."\n"; if (!is_null($replyToAddress)) { $headers .= 'Reply-To: '.$replyToAddress."\n"; } $headers .= 'X-Mailer: PHP/' . phpversion()."\n"; $headers .= 'Content-Type: '.$contentType.'; charset=UTF-8'."\n"; //send if (mail($recipientAddress, $subject, $content, $headers)) { $email->addEvent(EmailEventType::SENT); } else { $email->addEvent(EmailEventType::FAILED); } $email->save(); */ }
/** * Given a message received by a remote system, unencode the message and deliver it. * @param $queue * @param $message * @return void */ function processRawMessage($raw) { $cooked = $this->decode($raw); $queue = $cooked["queue"]; $msgframe = $cooked["msgframe"]; $conf = MessageQueue::get_queue_config($queue); MessageQueue::decode_message($msgframe, $conf); MessageQueue::deliver_message($msgframe, $conf); }
public function addqueue($queue) { $q = MessageQueue::GetQueue('sqs'); $q->create_queue($queue); vomit($q->list_queues()); }
function index() { $req = $this->getRequest()->requestVars(); $queue = $req && isset($req["queue"]) ? $req["queue"] : null; $limit = $req && isset($req["limit"]) ? $req["limit"] : null; // Work out what processes need to be run. Tries 'actions' and 'action', which are synonyms. if ($req && isset($req["actions"])) { $actions = $req["actions"]; } else { if ($req && isset($req["action"])) { $actions = $req["action"]; } else { $actions = "all"; } } $retrigger = $req && isset($req["retrigger"]) ? $req["retrigger"] : ""; $actions = explode(",", $actions); $flush = false; $consume = false; foreach ($actions as $a) { if ($a == "flush" || $a == "all") { $flush = true; } if ($a == "consume" || $a == "all") { $consume = true; } } if ($flush) { MessageQueue::flush($queue); } if ($consume) { $count = MessageQueue::consume($queue, $limit ? array("limit" => $limit) : null); if (!$count) { return $this->httpError(404, 'No messages'); } } if ($retrigger == "yes") { // @todo This assumes the queue is simpleDBMQ. Not performant on long queue. // @todo Generalise counting. $count = DB::query("select count(*) from \"SimpleDBMQ\" where \"QueueName\"='{$queue}'")->value(); if ($count > 0) { MessageQueue::consume_in_subprocess($queue); } } return 'True'; }
public function triggerProcessing() { MessageQueue::send(Config::inst()->get('SearchMessageQueueUpdater', 'reindex_queue'), new MethodInvocationMessage($this, "process")); }
<?php $argv = $_SERVER['argv']; if (count($argv) != 2) { echo "参数不合法\r\n"; exit; } $queueName = $argv[1]; $callBack = isset(MessageQueueConfig::$callBack[$queueName]) ? MessageQueueConfig::$callBack[$queueName] : array(); if (!empty($callBack) && !empty($callBack['callBackClassName']) && !empty($callBack['callBackMethod'])) { MessageQueue::consume($queueName, array($callBack['callBackClassName'], $callBack['callBackMethod'])); } else { echo "队列:{$queueName},回调配置出错\r\n"; }
/** * After executing the message queue tests, restore the original queue interfaces. * @return void */ function tearDownOnce() { // Remove any queue definitions that are set up by tests. Currently only 'default' is used. MessageQueue::remove_interface("default"); // Restore each interface. foreach (self::$saved_interfaces as $name => $def) { MessageQueue::add_interface($name, $def); } parent::tearDownOnce(); }
<?php /** * Created by PhpStorm. * User: zmw * Date: 2015/8/8 * Time: 20:46 */ require_once dirname(dirname(__FILE__)) . '/components/MessageQueue.php'; $messageQueue = MessageQueue::getInstance(); for ($i = 0; $i < 100; $i++) { $message = uniqid(); $ret = $messageQueue->addMessage($message); if (false == $ret) { print $message; print " insert failed\n"; } else { print $message; print " success \n"; } }