Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- abstract class AbstractCarrier {
- protected $connection;
- protected $channel;
- protected $queueName;
- public function __construct($queueName, $host = 'localhost', $port = 5672, $username = 'guest', $password = 'guest') {
- $this->queueName = $queueName;
- $this->connection = new AMQPStreamConnection($host, $port, $username, $password);
- $this->channel = $this->connection->channel();
- $this->channel->queue_declare($queueName, false, false, false, false);
- }
- /**
- * This method is called by the script that implements the carrier. It is blocking.
- * The call to basic_consume calls the 'receivedParcel' method which is implmented by the subclasses
- */
- public function waitForMail() {
- $this->channel->basic_consume($this->queueName, $this->queueName, false,false,false,false, [$this, 'receivedParcel']);
- while (count($this->channel->callbacks)) {
- $this->channel->wait();
- }
- $this->channel->close();
- $this->connection->close();
- }
- /* Stub to be implemented by sub classes */
- protected function receivedParcel($msg){}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement