Skip to content

Instantly share code, notes, and snippets.

@xphere
Created November 13, 2013 10:24
Show Gist options
  • Select an option

  • Save xphere/7446830 to your computer and use it in GitHub Desktop.

Select an option

Save xphere/7446830 to your computer and use it in GitHub Desktop.
Verbose method for AMQP queue declaration. Before: $queue = $channel->queue_declare('queue_name', false, true, false, false, true); Now: $queue = QueueBuilder::create($channel, 'queue_name')->setDurable()->setAutoDelete()->buildQueue();
<?php
namespace Amqp;
use PhpAmqpLib\Channel\AMQPChannel;
class QueueBuilder
{
/** @var AMQPChannel */
protected $channel;
protected $name = '';
protected $passive = false;
protected $durable = false;
protected $exclusive = false;
protected $auto_delete = true;
protected $nowait = false;
protected $arguments = null;
protected $ticket = null;
/**
* @param AMQPChannel $channel
* @param string $name
*
* @return self
*/
static public function create(AMQPChannel $channel, $name = '')
{
$builder = new self();
return $builder
->setChannel($channel)
->setName($name)
;
}
protected function __construct()
{
}
public function setChannel(AMQPChannel $channel)
{
$this->channel = $channel;
return $this;
}
public function setName($name)
{
$this->name = (string) $name;
return $this;
}
public function setPassive($passive = true)
{
$this->passive = (bool) $passive;
return $this;
}
public function setDurable($durable = true)
{
$this->durable = (bool) $durable;
return $this;
}
public function setExclusive($exclusive = true)
{
$this->exclusive = (bool) $exclusive;
return $this;
}
public function setAutoDelete($auto_delete = true)
{
$this->auto_delete = (bool) $auto_delete;
return $this;
}
public function setNowait($nowait = true)
{
$this->nowait = (bool) $nowait;
return $this;
}
public function setArguments($arguments)
{
$this->arguments = $arguments;
return $this;
}
public function setTicket($ticket)
{
$this->ticket = (int) $ticket;
return $this;
}
public function buildQueue()
{
return $this->channel->queue_declare(
$this->name,
$this->passive,
$this->durable,
$this->exclusive,
$this->auto_delete,
$this->nowait,
$this->arguments,
$this->ticket
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment