use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use PhpAmqpLib\Connection\AMQPStreamConnection;
class Receive extends Command { protected function configure() { $this ->setName('receive') ->setDescription('Send message') ->setHelp("Send message"); }
protected function execute(InputInterface $input, OutputInterface $output) { $connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest'); $channel = $connection->channel();
$channel->queue_declare('hello', false, false, false, false);
echo ' [*] Waiting for messages. To exit press CTRL+C', "\n";
$count = 1; $callback = function($msg) use (&$count) { echo " [$count] Received ", $msg->body, "\n"; $count++; };
$channel->basic_qos(null, 1, null); $channel->basic_consume('task_queue', '', false, true, false, false, $callback);
while(count($channel->callbacks)) { $channel->wait(); } } }
|