Commits

Alvaro Videla committed 57a0b71

adds rogue consumer

  • Participants
  • Parent commits 8b4ee91

Comments (0)

Files changed (1)

rogue_consumer.php

+<?php
+
+require_once __DIR__.'/vendor/autoload.php';
+
+use PhpAmqpLib\Connection\AMQPConnection;
+use PhpAmqpLib\Message\AMQPMessage;
+
+define('HOST', 'localhost');
+define('PORT', 5672);
+define('USER', 'guest');
+define('PASS', 'guest');
+define('VHOST', '/');
+
+$exchange = 'amq.direct';
+$queue = 'task_queue';
+
+$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
+$ch = $conn->channel();
+
+$ch->queue_declare($queue, false, true, false, false);
+$ch->queue_bind($queue, $exchange);
+
+function process_message($msg) {
+    $msg->delivery_info['channel']->
+        basic_ack($msg->delivery_info['delivery_tag']);
+}
+
+$ch->basic_consume($queue, '', false, false, false, false, 'process_message');
+
+function shutdown($ch, $conn) {
+    $ch->close();
+    $conn->close();
+}
+register_shutdown_function('shutdown', $ch, $conn);
+
+// Loop as long as the channel has callbacks registered
+while (count($ch->callbacks)) {
+    $ch->wait();
+}