本文整理汇总了PHP中PhpAmqpLib\Channel\AMQPChannel::basic_cancel方法的典型用法代码示例。如果您正苦于以下问题:PHP AMQPChannel::basic_cancel方法的具体用法?PHP AMQPChannel::basic_cancel怎么用?PHP AMQPChannel::basic_cancel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpAmqpLib\Channel\AMQPChannel
的用法示例。
在下文中一共展示了AMQPChannel::basic_cancel方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initialize
/**
* Create consumer.
*/
private function initialize()
{
$this->messages = [];
list($queue) = $this->channel->queue_declare('', false, false, true, true);
$this->channel->queue_bind($queue, $this->exchange);
$this->channel->basic_consume($queue, '', false, false, false, false, function (AMQPMessage $message) {
$this->messages[] = $message;
$this->channel->basic_cancel($message->delivery_info['consumer_tag']);
});
}
示例2: consume
/**
* Listener for the queue
* @param string $consumer_url
* @param array $post_vars
*/
public function consume($consumer_url, $post_vars = array())
{
$this->consumer_url = $consumer_url;
$this->consumer_post = $post_vars;
if ($this->consumer_count < $this->consumer_max) {
$this->consumer_start = time();
$callback = function (AMQPMessage $message) {
$post_vars = $this->consumer_post;
$post_vars['url'] = $this->consumer_url;
$post_vars['queue'] = $this->queue;
$post_vars['message'] = $message->body;
$response = $this->httpRequest->post($this->consumer_url, $post_vars);
$code = $this->httpRequest->statusCode();
if ($code == 200) {
$message->delivery_info['channel']->basic_ack($message->delivery_info['delivery_tag']);
} else {
// log the error to a file
$log_message = $code . "\n\n";
$log_message .= $message->body . "\n\n";
$log_message .= print_r($message, true);
$log_message .= "\n\n\n";
$log_message .= print_r($response, true);
Log::error($log_message);
}
if ($this->consumer_start + $this->ttl < time()) {
$this->channel->basic_cancel($message->delivery_info['consumer_tag']);
}
};
$this->channel->basic_consume($this->queue, '', false, false, false, false, $callback);
while (count($this->channel->callbacks)) {
$this->channel->wait();
}
}
}
示例3: basicCancel
/**
* @param MessageInterface $message
*
* @throws ConnectorException
*/
public function basicCancel(MessageInterface $message)
{
/** @var AMQPMessage $amqpMessage */
$amqpMessage = $message->getOriginalMessage();
if (!$amqpMessage instanceof AMQPMessage) {
throw ConnectorException::invalidOriginalMessageType(AMQPMessage::class, get_class($message));
}
$this->channel->basic_cancel($amqpMessage->delivery_info['consumer_tag']);
$this->logger->info(sprintf('Message consumption stopped!'));
}
示例4: work
/**
* Start listen queue for tasks
*
* @param int $processMessages max number of messages for processing
*
* @return Generator
*/
public function work(int $processMessages = null) : Generator
{
$this->messagesProcessed = 0;
while (count($this->channel->callbacks)) {
$this->channel->wait();
if ($this->lastResult instanceof Result) {
(yield $this->lastResult);
$this->lastResult = null;
$this->messagesProcessed++;
}
if (null !== $processMessages && $this->messagesProcessed >= $processMessages) {
break;
}
}
$this->channel->basic_cancel($this->consumerTag);
}
示例5: createReplyConsumer
/**
* @return string
*/
private function createReplyConsumer()
{
$tag = uniqid('reply-consumer-');
$this->channel->basic_consume(self::REPLY_QUEUE, $tag, false, true, false, false, function (AMQPMessage $message) {
if (!($id = $message->get('correlation_id'))) {
return;
}
if (!isset($this->unresolved[$id])) {
return;
}
$this->unresolved[$id]->setReply($message);
unset($this->unresolved[$id]);
if (empty($this->unresolved)) {
$this->channel->basic_cancel($message->delivery_info['consumer_tag']);
$this->consumer = null;
}
});
return $tag;
}
示例6: cancelConsumer
/**
* Cancel a specific consumer.
*
* @param string $consumerId
*
* @return $this
*/
public function cancelConsumer($consumerId)
{
$this->channel->basic_cancel($consumerId);
return $this;
}