本文整理匯總了PHP中PhpAmqpLib\Channel\AMQPChannel::basic_get方法的典型用法代碼示例。如果您正苦於以下問題:PHP AMQPChannel::basic_get方法的具體用法?PHP AMQPChannel::basic_get怎麽用?PHP AMQPChannel::basic_get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PhpAmqpLib\Channel\AMQPChannel
的用法示例。
在下文中一共展示了AMQPChannel::basic_get方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: get
/**
* {@inheritDoc}
*/
public function get()
{
$envelope = $this->channel->basic_get($this->queueName);
if (null === $envelope) {
return null;
}
$properties = $envelope->has('application_headers') ? $envelope->get('application_headers') : array();
return new Message($envelope->body, $properties, $envelope->get('delivery_tag'));
}
示例2: popMessage
/**
* Remove the next message in line. And if no message is available
* wait $interval seconds.
*
* @param string $queueName
* @param int $interval
* @return array An array like array($message, $receipt);
*/
public function popMessage($queueName, $interval = 5)
{
$message = $this->channel->basic_get($queueName);
if (!$message) {
// sleep for 10 ms to prevent hammering CPU
usleep(10000);
return [null, null];
}
return [$message->body, $message->get('delivery_tag')];
}
示例3: consume
/**
* @param $queue
*
* @return mixed
*/
public function consume($queue)
{
$messageBody = false;
$message = $this->ch->basic_get($queue);
if ($message) {
$this->ch->basic_ack($message->delivery_info['delivery_tag']);
$messageBody = $message->body;
}
return $messageBody;
}
示例4: get
/**
* {@inheritDoc}
*/
public function get()
{
$envelope = $this->channel->basic_get($this->queueName);
if (null === $envelope) {
return null;
}
// Explanation on these properties can be found at:
// https://github.com/videlalvaro/php-amqplib/blob/091/doc/AMQPMessage.md
$properties = array('content_type' => $envelope->has('content_type') ? $envelope->get('content_type') : '', 'delivery_mode' => $envelope->has('delivery_mode') ? $envelope->get('delivery_mode') : 0, 'content_encoding' => $envelope->has('content_encoding') ? $envelope->get('content_encoding') : '', 'type' => $envelope->has('type') ? $envelope->get('type') : '', 'timestamp' => $envelope->has('timestamp') ? $envelope->get('timestamp') : 0, 'priority' => $envelope->has('priority') ? $envelope->get('priority') : 0, 'expiration' => $envelope->has('expiration') ? $envelope->get('expiration') : '', 'app_id' => $envelope->has('app_id') ? $envelope->get('app_id') : '', 'message_id' => $envelope->has('message_id') ? $envelope->get('message_id') : '', 'reply_to' => $envelope->has('reply_to') ? $envelope->get('reply_to') : '', 'correlation_id' => $envelope->has('correlation_id') ? $envelope->get('correlation_id') : '', 'user_id' => $envelope->has('user_id') ? $envelope->get('user_id') : 0, 'cluster_id' => $envelope->has('cluster_id') ? $envelope->get('cluster_id') : 0, 'channel' => isset($envelope->delivery_info['channel']) ? $envelope->delivery_info['channel'] : '', 'consumer_tag' => isset($envelope->delivery_info['consumer_tag']) ? $envelope->delivery_info['consumer_tag'] : '', 'delivery_tag' => isset($envelope->delivery_info['delivery_tag']) ? $envelope->delivery_info['delivery_tag'] : '', 'is_redelivery' => isset($envelope->delivery_info['redelivered']) ? $envelope->delivery_info['redelivered'] : false, 'exchange_name' => isset($envelope->delivery_info['exchange']) ? $envelope->delivery_info['exchange'] : '', 'routing_key' => isset($envelope->delivery_info['routing_key']) ? $envelope->delivery_info['routing_key'] : '');
$properties['headers'] = array();
if ($envelope->has('application_headers')) {
foreach ($envelope->get('application_headers') as $key => $value) {
$properties['headers'][$key] = $value[1];
}
}
return new Message($envelope->body, $properties, $envelope->get('delivery_tag'));
}
示例5: pop
/**
* Pop the next job off of the queue.
*
* @param string|null $queue
*
* @return \Illuminate\Queue\Jobs\Job|null
*/
public function pop($queue = null)
{
$queue = $this->getQueueName($queue);
$this->declareQueue($queue);
// get envelope
$message = $this->channel->basic_get($queue);
if ($message instanceof AMQPMessage) {
return new RabbitMQJob($this->container, $this, $message, $queue, $this->channel);
}
return;
}
示例6: getNextMessage
/**
* Get the next message from the queue.
* @return AMQPMessage
* @throws ConnectionError Thrown by self::openConnection if connection cannot be established
*/
public function getNextMessage()
{
$this->openConnection();
$message = $this->channel->basic_get($this->config->getQueueName());
// Currently no reason to want to see any message more than once so
// ack every message received from the queue.
if ($message) {
// direct delivery_info array access recommended in PhpAmqpLib documentation
$this->channel->basic_ack($message->delivery_info['delivery_tag']);
}
return $message;
}
示例7: get
/**
* {@inheritDoc}
*/
public function get()
{
$envelope = $this->channel->basic_get($this->queueName);
if (null === $envelope) {
return;
}
$properties = [];
$propertyKeys = ['content_type', 'delivery_mode', 'content_encoding', 'type', 'timestamp', 'priority', 'expiration', 'app_id', 'message_id', 'reply_to', 'correlation_id', 'user_id', 'cluster_id', 'channel', 'consumer_tag', 'delivery_tag', 'redelivered', 'exchange', 'routing_key'];
foreach ($propertyKeys as $key) {
if ($envelope->has($key)) {
$properties[$key] = $envelope->get($key);
}
}
$properties['headers'] = [];
if ($envelope->has('application_headers')) {
foreach ($envelope->get('application_headers') as $key => $value) {
$properties['headers'][$key] = $value[1];
}
}
return new Message($envelope->body, $properties, $envelope->get('delivery_tag'));
}
示例8: pop
/**
* {@inheritdoc}
*/
public function pop(string $queue = null)
{
$queue = $this->getQueue($queue);
try {
$this->declareQueue($queue);
} catch (AMQPRuntimeException $exception) {
$this->connection->reconnect();
$this->declareQueue($queue);
}
// get envelope
$message = $this->channel->basic_get($queue);
if ($message instanceof AMQPMessage) {
return new RabbitMQJob($this->container, $this, $this->channel, $queue, $message);
}
}
示例9: waitForMessage
/**
* Read a queue until there's a message or until a timeout.
*
* @param string $queue
* @param int $timeout Time to wait in seconds
* @return AMQPMessage|null
*/
protected function waitForMessage($queue, $timeout)
{
$timeStart = microtime(true);
do {
// Get message and auto-ack
$response = $this->channel->basic_get($queue);
if ($response) {
return $response;
}
// Sleep 300 ms
usleep(300000);
$timeSpent = microtime(true) - $timeStart;
} while ($timeSpent < $timeout);
return null;
}
示例10: pop
/**
* {@inheritdoc}
*/
public function pop($queue, $timeout = 0)
{
$this->queueDeclare($queue);
$message = $this->channel->basic_get($queue);
// @codeCoverageIgnoreStart
if ($timeout > 0) {
$start = microtime(true);
while (is_null($message) and $timeout > microtime(true) - $start) {
sleep(1);
$message = $this->channel->basic_get($queue);
}
}
// @codeCoverageIgnoreEnd
if ($message instanceof AMQPMessage) {
return new $this->managerClass($queue, $message, $this);
}
throw new QueueEmptyException($queue);
}
示例11: publishGet
/**
* Publish a message, then get it immediately
* @return \PhpAmqpLib\Message\AMQPMessage
*/
protected function publishGet()
{
$msg = new AMQPMessage($this->msgBody, array('content_type' => 'text/plain', 'delivery_mode' => 1, 'correlation_id' => 'my_correlation_id', 'reply_to' => 'my_reply_to'));
$this->ch->basic_publish($msg, $this->exchange, $this->queue);
return $this->ch->basic_get($this->queue);
}
示例12: getMessage
/**
* @param $queueTitle
* @return mixed
*/
public function getMessage($queueTitle)
{
return $this->channel->basic_get($queueTitle)->body;
}