Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

moved queue setup to its own method

  • Loading branch information...
commit 37f29b16cea48a61eba7cd9a5f626ef1cc3a8663 1 parent 940effb
@mvrhov authored
Showing with 21 additions and 5 deletions.
  1. +21 −5 RabbitMq/Producer.php
View
26 RabbitMq/Producer.php
@@ -9,7 +9,8 @@
class Producer extends BaseAmqp
{
- protected $declared = false;
+ protected $exchangeDeclared = false;
+ protected $queueDeclared = false;
public function exchangeDeclare()
{
@@ -21,23 +22,38 @@ public function exchangeDeclare()
$this->exchangeOptions['auto_delete'],
$this->exchangeOptions['internal']);
- $this->declared = true;
+ $this->exchangeDeclared = true;
+ }
- if (('' != $this->queueOptions['name']) && (null !== $this->queueOptions['name'])) {
+ public function queueDeclare()
+ {
+ if (null !== $this->queueOptions['name']) {
list($queueName, ,) = $this->ch->queue_declare($this->queueOptions['name'], $this->queueOptions['passive'],
$this->queueOptions['durable'], $this->queueOptions['exclusive'],
$this->queueOptions['auto_delete'], $this->queueOptions['nowait'],
$this->queueOptions['arguments'], $this->queueOptions['ticket']);
$this->ch->queue_bind($queueName, $this->exchangeOptions['name'], $this->routingKey);
+
+ $this->queueDeclared = true;
}
}
- public function publish($msgBody, $routingKey = '')
+ public function setupProducer()
{
- if (!$this->declared) {
+ if (!$this->exchangeDeclared) {
$this->exchangeDeclare();
}
+
+ if (!$this->queueDeclared) {
+ $this->queueDeclare();
+ }
+ }
+
+ public function publish($msgBody, $routingKey = '')
+ {
+ $this->setupProducer();
+
$msg = new AMQPMessage($msgBody, array('content_type' => 'text/plain', 'delivery_mode' => 2));
$this->ch->basic_publish($msg, $this->exchangeOptions['name'], $routingKey);
}
Please sign in to comment.
Something went wrong with that request. Please try again.