|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ETNA\Silex\Provider\RabbitMQ; |
|
4
|
|
|
|
|
5
|
|
|
use PhpAmqpLib\Message\AMQPMessage; |
|
6
|
|
|
use PhpAmqpLib\Channel\AMQPChannel; |
|
7
|
|
|
/** |
|
8
|
|
|
* |
|
9
|
|
|
*/ |
|
10
|
|
|
class Exchange |
|
11
|
|
|
{ |
|
12
|
|
|
private $name; |
|
13
|
|
|
private $channel; |
|
14
|
|
|
private $type = "direct"; |
|
15
|
|
|
private $passive = false; |
|
16
|
|
|
private $durable = false; |
|
17
|
|
|
private $auto_delete = true; |
|
18
|
|
|
|
|
19
|
|
|
public function __construct($name, AMQPChannel $channel, $options) |
|
20
|
|
|
{ |
|
21
|
|
|
$this->name = $name; |
|
22
|
|
|
$this->channel = $channel; |
|
23
|
|
|
$this->type = isset($options["type"]) ? $options["type"] : "direct"; |
|
24
|
|
|
$this->passive = isset($options["passive"]) ? $options["passive"] : false; |
|
25
|
|
|
$this->durable = isset($options["durable"]) ? $options["durable"] : true; |
|
26
|
|
|
$this->auto_delete = isset($options["auto_delete"]) ? $options["auto_delete"] : false; |
|
27
|
|
|
|
|
28
|
|
|
if ($name != "") { |
|
29
|
|
|
$channel->exchange_declare( |
|
30
|
|
|
$name, |
|
31
|
|
|
$this->type, |
|
32
|
|
|
$this->passive, |
|
33
|
|
|
$this->durable, |
|
34
|
|
|
$this->auto_delete |
|
35
|
|
|
); |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function getName() |
|
|
|
|
|
|
40
|
|
|
{ |
|
41
|
|
|
return $this->name; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function getChannel() |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->channel; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function getType() |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->type; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function isPassive() |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->passive; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function isDurable() |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->durable; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function isAutoDelete() |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->auto_delete; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function send($message, $routing_key = "", $mandatory = false, $immediate = false, $ticket = null) |
|
70
|
|
|
{ |
|
71
|
|
|
$message = new AMQPMessage(json_encode($message), ["Content-Type" => "application/json"]); |
|
72
|
|
|
$this->channel->basic_publish($message, $this->name, $routing_key, $mandatory, $immediate, $ticket); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.