本文整理汇总了PHP中AMQPQueue::get方法的典型用法代码示例。如果您正苦于以下问题:PHP AMQPQueue::get方法的具体用法?PHP AMQPQueue::get怎么用?PHP AMQPQueue::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AMQPQueue
的用法示例。
在下文中一共展示了AMQPQueue::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* {@inheritDoc}
*/
public function get()
{
$envelope = $this->queue->get();
if (!$envelope) {
return;
}
return new Message($envelope->getBody(), array('content_type' => $envelope->getContentType(), 'routing_key' => $envelope->getRoutingKey(), 'delivery_tag' => $envelope->getDeliveryTag(), 'delivery_mode' => $envelope->getDeliveryMode(), 'exchange_name' => $envelope->getExchangeName(), 'is_redelivery' => $envelope->isRedelivery(), 'content_encoding' => $envelope->getContentEncoding(), 'type' => $envelope->getType(), 'timestamp' => $envelope->getTimeStamp(), 'priority' => $envelope->getPriority(), 'expiration' => $envelope->getExpiration(), 'app_id' => $envelope->getAppId(), 'message_id' => $envelope->getMessageId(), 'reply_to' => $envelope->getReplyTo(), 'correlation_id' => $envelope->getCorrelationId(), 'headers' => $envelope->getHeaders(), 'user_id' => $envelope->getUserId(), 'cluster_id' => 0, 'channel' => '', 'consumer_tag' => ''), $envelope->getDeliveryTag());
}
示例2: get
/**
* @inheritdoc
*/
public function get($flags = null)
{
if (false !== ($envelope = $this->delegate->get(self::convertToDelegateFlags($flags)))) {
$envelope = new Envelope($envelope);
}
return $envelope;
}
示例3: get
/**
* @inheritdoc
*/
public function get(int $flags = Constants::AMQP_NOPARAM)
{
$envelope = $this->queue->get($flags);
if ($envelope instanceof \AMQPEnvelope) {
$envelope = new Envelope($envelope);
}
return $envelope;
}
示例4: read
/**
* @param \AMQPQueue $queue
* @return bool|string
*/
public static function read(\AMQPQueue $queue)
{
usleep(10000);
$envelope = $queue->get(\AMQP_NOPARAM);
if ($envelope) {
$message = $envelope->getBody();
$queue->ack($envelope->getDeliveryTag());
return $message;
}
return false;
}
示例5: take
public function take()
{
$q = new \AMQPQueue($this->amqpChannel);
$q->setName($this->name);
$msg = $q->get();
if (empty($msg)) {
return false;
} else {
return new MessageTakeControl($q, $msg);
}
}
示例6: get
/**
* @param int $flags
*
* @return Envelope|bool
*/
public function get($flags = Client::NOPARAM)
{
try {
$message = $this->rawQueue->get($flags);
if ($message instanceof \AMQPEnvelope) {
$message = Envelope::createFromRaw($message, $this->decodeStrategy);
}
return $message;
} catch (\Exception $e) {
ClientHelper::throwRightException($e);
}
}
示例7: execute
/**
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln(sprintf('Get %d messages from queue "%s"', $input->getOption('nb-messages'), $input->getArgument('queue')));
$fromChannel = $this->getChannel($input->getArgument('connection'), $input->getArgument('vhost'));
$queue = new \AMQPQueue($fromChannel);
$queue->setName($input->getArgument('queue'));
$noRequeue = $input->getOption('no-requeue');
$nbMessages = $input->getOption('nb-messages');
for ($i = 0; $i < $nbMessages; $i++) {
if ($noRequeue) {
$message = $queue->get(AMQP_AUTOACK);
} else {
$message = $queue->get();
}
if (false === $message) {
$output->writeln('No more messages in queue.');
return;
}
$output->writeln(print_r($message, true));
}
}
示例8: getProxy
public function getProxy($https = false)
{
if ($https) {
$queueName = 'q_proxy_https';
} else {
$queueName = 'q_proxy';
}
$params = array('host' => '10.168.45.191', 'port' => 5672, 'login' => 'guest', 'password' => 'guest', 'vhost' => '/kwd');
$conn = new AMQPConnection($params);
$conn->connect();
$channel = new AMQPChannel($conn);
$queue = new AMQPQueue($channel);
$queue->setName($queueName);
$message = $queue->get(AMQP_AUTOACK);
$proxy = $message->getBody();
while (!$this->_testProxy($proxy, $https)) {
$message = $queue->get(AMQP_AUTOACK);
$proxy = $message->getBody();
}
$conn->disconnect();
return $proxy;
}
示例9: readQueue
public function readQueue($q_name)
{
$q = new \AMQPQueue($this->channel);
$q->setName($q_name);
//$q->setFlags(AMQP_DURABLE);
//$q->declare();
//$q->bind('exchange', $bindingkey);
//消息获取
$messages = $q->get(AMQP_AUTOACK);
if ($messages) {
return $messages->getBody();
} else {
return false;
}
}
示例10: get
/**
* (non-PHPdoc)
* @see ContentEngine\Request.QueueInterface::get()
*/
public function get()
{
if (!isset($this->queue)) {
throw new \Exception('No AMQP queue set.');
}
$envelope = $this->queue->get($this->flags);
if (!$envelope) {
return null;
}
// extract data
$serial = $envelope->getBody();
$item = $this->serialiser->unserialise($serial);
$item['amqpDeliveryTag'] = $envelope->getDeliveryTag();
$item['amqpMessageId'] = $envelop->getMessageId();
return $item;
}
示例11: GetMessageBody
/**
* Return result of task execution for $task_id
* @param AMQPConnection $connection Connection object
* @param string $task_id Celery task identifier
* @param boolean $removeMessageFromQueue whether to remove message from queue
* @return array array('body' => JSON-encoded message body, 'complete_result' => AMQPEnvelope object)
* or false if result not ready yet
*/
function GetMessageBody($connection, $task_id, $removeMessageFromQueue = true)
{
$this->Connect($connection);
$ch = $connection->channel;
$q = new AMQPQueue($ch);
$q->setName($task_id);
$q->setFlags(AMQP_AUTODELETE | AMQP_DURABLE);
$q->declareQueue();
try {
$q->bind('celeryresults', $task_id);
} catch (AMQPQueueException $e) {
if ($removeMessageFromQueue) {
$q->delete();
}
$connection->disconnect();
return false;
}
$message = $q->get(AMQP_AUTOACK);
if (!$message) {
if ($removeMessageFromQueue) {
$q->delete();
}
$connection->disconnect();
return false;
}
if ($message->getContentType() != 'application/json') {
if ($removeMessageFromQueue) {
$q->delete();
}
$connection->disconnect();
throw new CeleryException('Response was not encoded using JSON - found ' . $message->getContentType() . ' - check your CELERY_RESULT_SERIALIZER setting!');
}
if ($removeMessageFromQueue) {
$q->delete();
}
$connection->disconnect();
return array('complete_result' => $message, 'body' => $message->getBody());
}
示例12: getCompleteResult
/**
* Connect to queue, see if there's a result waiting for us
* Private - to be used internally
*/
private function getCompleteResult()
{
if ($this->complete_result) {
return $this->complete_result;
}
$this->connection->connect();
$ch = new AMQPChannel($this->connection);
$q = new AMQPQueue($ch);
$q->setName($this->task_id);
$q->setFlags(AMQP_AUTODELETE);
# $q->setArgument('x-expires', 86400000);
$q->declareQueue();
try {
$q->bind('celeryresults', $this->task_id);
} catch (AMQPQueueException $e) {
$q->delete();
$this->connection->disconnect();
return false;
}
$message = $q->get(AMQP_AUTOACK);
if (!$message) {
$q->delete();
$this->connection->disconnect();
return false;
}
$this->complete_result = $message;
if ($message->getContentType() != 'application/json') {
$q->delete();
$this->connection->disconnect();
throw new CeleryException('Response was not encoded using JSON - found ' . $message->getContentType() . ' - check your CELERY_RESULT_SERIALIZER setting!');
}
$this->body = json_decode($message->getBody());
$q->delete();
$this->connection->disconnect();
return false;
}
示例13: AMQPConnection
$rabbit = new AMQPConnection(array('host' => '127.0.0.1', 'port' => '5672', 'login' => 'guest', 'password' => 'guest'));
$rabbit->connect();
$channel = new AMQPChannel($rabbit);
$queue = new AMQPExchange($channel);
$queue->setName('amq.direct');
/**
* Добавляем очередь откуда будем брать страницы
*/
$q = new AMQPQueue($channel);
$q->setName('pages_to_scan');
$q->declare();
$q->bind('amq.direct', 'analyze_page');
/**
* Обрабатываем пока в очереди не закончатся сообщения
*/
while (true) {
$page = $q->get();
if ($page) {
$url = $page->getBody();
echo "Parsing: {$url}\n";
$analyzer = new PageAnalyzer($url);
/**
* Если страница еще не была проанализирована, обрабатываем и добавляем в индекс
*/
$analyzer->analyze();
$q->ack($page->getDeliveryTag());
} else {
sleep(1);
}
}
$rabbit->disconnect();
示例14: asyncRead
/**
* Асинхронное чтение ответов
* @param string $transactionId
* @param callable $callBack - Функция вызываемая для каждой строки.
* Приимвет два параметра
* \AMQPEnvelope $envelope
* \AMQPQueue $queue
* Чтобы подтвердить получение нужно вызвать метод $queue->ack($envelope->getDeliveryTag());
* Чтобы перейти к следующему элементу без подтверждения получения нужно вызвать метод $queue->cancel($envelope->getDeliveryTag());
* Если возвращает false, то передор возвращается.
* @return \AMQPQueue - Возвращает очередь чтобы ее можно было удалить, если она уже не нужна
* @throws \Exception
*/
public function asyncRead($transactionId, $callBack)
{
if (!is_callable($callBack)) {
throw new \Exception('Callback not callable');
}
$chanel = $this->amqp->newChannel();
$queue = new \AMQPQueue($chanel);
$queue->setName($transactionId);
// Таким образом можно проверить существует ли очередь.
// Если она не существует, то будет ошибка и нужно вернуть пустой ответ
$queue->setFlags(AMQP_PASSIVE);
try {
$queue->declareQueue();
} catch (\Exception $e) {
return $queue;
}
/** @var \AMQPEnvelope $envelop */
while ($envelop = $queue->get()) {
if (call_user_func($callBack, $envelop, $queue) === false) {
break;
}
}
return $queue;
}
示例15: checkDelivery
/**
* Check delivered message from MQ
* @param object $queue
* @return array $queArray
* @access public
*/
public function checkDelivery(\AMQPQueue $queue)
{
$queArray = array();
$queue->bind($this->exchangeOptions['name'], $this->queueOptions['routing_key']);
while ($message = $queue->get()) {
if ($message->isRedelivery()) {
$queArray[] = $message->getDeliveryTag() . "=" . $message->getBody();
}
}
return $queArray;
}