本文整理汇总了PHP中PhpAmqpLib\Channel\AMQPChannel::basic_consume方法的典型用法代码示例。如果您正苦于以下问题:PHP AMQPChannel::basic_consume方法的具体用法?PHP AMQPChannel::basic_consume怎么用?PHP AMQPChannel::basic_consume使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpAmqpLib\Channel\AMQPChannel
的用法示例。
在下文中一共展示了AMQPChannel::basic_consume方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: consume
public function consume(ConsumerInterface $consumer, $callback)
{
$this->channel->basic_consume($consumer->getName(), '', false, false, false, false, $callback);
while (count($this->channel->callbacks)) {
$this->channel->wait();
}
}
示例2: waitingForCall
public function waitingForCall()
{
$this->channel->basic_consume(self::QUEUE_NAME, '', false, false, false, false, array($this, 'receive'));
while (count($this->channel->callbacks)) {
$this->channel->wait();
}
}
示例3: listen
/**
* Infinite loop: Listens for messages from the queue and sends them to the callback.
*
* @param callback $callback
*/
public function listen($callback)
{
$this->channel->basic_qos(null, 1, null);
$this->channel->basic_consume(self::QUEUE_NAME, '', false, true, false, false, $callback);
while ($this->channel->callbacks) {
$this->channel->wait();
}
}
示例4: consume
/**
* @param string $exchangeName
* @param callable $callback
*/
public function consume($exchangeName, callable $callback)
{
$this->callback = $callback;
$this->channel->basic_consume($exchangeName, '', false, true, false, false, [$this, 'callback']);
while (count($this->channel->callbacks)) {
$this->channel->wait();
}
}
示例5: consume
public function consume()
{
$queue = $this->initialize();
$tag = $this->handler->name();
$this->channel->basic_consume($queue, $tag, false, false, false, false, [$this, 'handle']);
while (isset($this->channel->callbacks[$tag])) {
$this->channel->wait();
}
}
示例6: testSendFile
public function testSendFile()
{
$this->msg_body = file_get_contents(__DIR__ . '/fixtures/data_1mb.bin');
$msg = new AMQPMessage($this->msg_body, array('delivery_mode' => 1));
$this->ch->basic_publish($msg, $this->exchange_name, $this->queue_name);
$this->ch->basic_consume($this->queue_name, '', false, false, false, false, array($this, 'process_msg'));
while (count($this->ch->callbacks)) {
$this->ch->wait();
}
}
示例7: testPublishConsume
public function testPublishConsume()
{
$this->msg_body = 'foo bar baz äëïöü';
$msg = new AMQPMessage($this->msg_body, 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_name, $this->queue_name);
$this->ch->basic_consume($this->queue_name, getmypid(), false, false, false, false, array($this, 'process_msg'));
while (count($this->ch->callbacks)) {
$this->ch->wait();
}
}
示例8: setUp
/**
* Set up AMQP connection.
*/
public function setUp()
{
$container = $this->getContainer();
$exchangeName = 'general';
$connection = new AMQPConnection($container->getParameter('ongr_task_messenger.publisher.default.amqp.host'), $container->getParameter('ongr_task_messenger.publisher.default.amqp.port'), $container->getParameter('ongr_task_messenger.publisher.default.amqp.user'), $container->getParameter('ongr_task_messenger.publisher.default.amqp.password'));
$this->channel = $connection->channel();
list($queueName, , ) = $this->channel->queue_declare();
$this->channel->queue_bind($queueName, $exchangeName, explode('.', gethostname())[0]);
$this->channel->basic_consume($queueName, getmypid(), false, true, true, true, [$this, 'verifyMessage']);
}
示例9: 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']);
});
}
示例10: consume
/**
* @param string $queue
* @param string $exchange
* @param string $routingKey
* @param callable $callback
*/
public function consume($queue, $exchange, $routingKey, $callback)
{
$this->declareComponents($routingKey, $exchange, $queue);
$this->channel->basic_consume($queue, '', false, false, false, false, function ($amqpMessage) use($callback) {
$message = new Message($amqpMessage);
$callback($message);
});
while (count($this->channel->callbacks)) {
$this->channel->wait();
}
}
示例11: consume
/**
* @param callable $callback
* @return void
*/
public function consume(callable $callback)
{
$internCallback = function ($msg) use($callback) {
//echo " [x] Received ", $msg->body, "\n";
$callback(unserialize($msg->body));
};
$this->exchange->basic_consume($this->exchangeName, '', false, true, false, false, $internCallback);
while (count($this->exchange->callbacks)) {
$this->exchange->wait();
}
}
示例12: wait
/**
* {@inheritdoc}
*/
public function wait(Closure $callback)
{
$this->channel->basic_consume($this->queue, '', false, true, false, false, function ($rabbitMessage) use($callback) {
$message = $this->serializer->unserialize($rabbitMessage->body);
$callback($message);
$rabbitMessage->delivery_info['channel']->basic_ack($rabbitMessage->delivery_info['delivery_tag']);
});
while (count($this->channel->callbacks)) {
$this->channel->wait();
}
}
示例13: testFrameOrder
public function testFrameOrder()
{
$msg = new AMQPMessage('');
$hdrs = new AMQPTable(array('x-foo' => 'bar'));
$msg->set('application_headers', $hdrs);
for ($i = 0; $i < $this->msg_count; $i++) {
$this->ch->basic_publish($msg, $this->exchange_name, $this->queue_name);
}
$this->ch2->basic_consume($this->queue_name, '', false, true, false, false, array($this, 'process_msg'));
while (count($this->ch2->callbacks)) {
$this->ch2->wait();
}
}
示例14: thereShouldBeAMessageInQueue
/**
* @Then there should be a message in queue :queue
*
* @param $queue
* @param PyStringNode $string
*/
public function thereShouldBeAMessageInQueue($queue, PyStringNode $string = null)
{
$expected = $string ? $string->getRaw() : null;
if (null === $expected) {
$this->channel->basic_consume($queue);
} else {
$consumer = function (AMQPMessage $message) use($expected) {
$this->channel->basic_ack($message->delivery_info['delivery_tag']);
Assert::that($message->body)->equal($expected);
};
$this->channel->basic_consume($queue, '', false, false, false, false, $consumer);
}
$this->channel->wait(null, false, 4);
}
示例15: process_msg1
public function process_msg1($msg)
{
$delivery_info = $msg->delivery_info;
$this->q1msgs++;
if ($this->q1msgs < 2) {
$this->ch2->basic_consume($this->queue_name2, "", false, true, false, false, array($this, 'process_msg2'));
}
while (count($this->ch2->callbacks)) {
$this->ch2->wait();
}
if ($this->q1msgs == 2) {
$delivery_info['channel']->basic_cancel($delivery_info['consumer_tag']);
}
}