1 | <?php |
||
25 | class AMQPBackendDispatcher extends QueueBackendDispatcher |
||
26 | { |
||
27 | /** |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $settings; |
||
31 | |||
32 | /** |
||
33 | * @var AMQPChannel |
||
34 | */ |
||
35 | protected $channel; |
||
36 | |||
37 | /** |
||
38 | * @var AMQPConnection |
||
39 | */ |
||
40 | protected $connection; |
||
41 | |||
42 | /** |
||
43 | * @param array $settings |
||
44 | * @param array $queues |
||
45 | * @param string $defaultQueue |
||
46 | * @param array $backends |
||
47 | */ |
||
48 | public function __construct(array $settings, array $queues, $defaultQueue, array $backends) |
||
49 | { |
||
50 | parent::__construct($queues, $defaultQueue, $backends); |
||
51 | |||
52 | $this->settings = $settings; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @return AMQPChannelannel |
||
57 | */ |
||
58 | public function getChannel() |
||
59 | { |
||
60 | if (!$this->channel) { |
||
61 | $this->connection = new AMQPConnection( |
||
|
|||
62 | $this->settings['host'], |
||
63 | $this->settings['port'], |
||
64 | $this->settings['user'], |
||
65 | $this->settings['pass'], |
||
66 | $this->settings['vhost'] |
||
67 | ); |
||
68 | |||
69 | $this->channel = $this->connection->channel(); |
||
70 | |||
71 | register_shutdown_function(array($this, 'shutdown')); |
||
72 | } |
||
73 | |||
74 | return $this->channel; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | */ |
||
80 | public function getBackend($type) |
||
81 | { |
||
82 | $default = null; |
||
83 | |||
84 | if (count($this->queues) === 0) { |
||
85 | foreach ($this->backends as $backend) { |
||
86 | if ($backend['type'] === 'default') { |
||
87 | return $backend['backend']; |
||
88 | } |
||
89 | } |
||
90 | } |
||
91 | |||
92 | foreach ($this->backends as $backend) { |
||
93 | if ('all' === $type && $backend['type'] === '') { |
||
94 | return $backend['backend']; |
||
95 | } |
||
96 | |||
97 | if ($backend['type'] === $type) { |
||
98 | return $backend['backend']; |
||
99 | } |
||
100 | |||
101 | if ($backend['type'] === $this->defaultQueue) { |
||
102 | $default = $backend['backend']; |
||
103 | } |
||
104 | } |
||
105 | |||
106 | if ($default === null) { |
||
107 | throw new BackendNotFoundException('Could not find a message backend for the type '.$type); |
||
108 | } |
||
109 | |||
110 | return $default; |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * {@inheritdoc} |
||
115 | */ |
||
116 | public function getIterator() |
||
120 | |||
121 | /** |
||
122 | * {@inheritdoc} |
||
123 | */ |
||
124 | public function handle(MessageInterface $message, EventDispatcherInterface $dispatcher) |
||
128 | |||
129 | /** |
||
130 | * {@inheritdoc} |
||
131 | */ |
||
132 | public function getStatus() |
||
164 | |||
165 | /** |
||
166 | * Calls the rabbitmq management api /api/<vhost>/queues endpoint to list the available queues. |
||
167 | * |
||
168 | * @see http://hg.rabbitmq.com/rabbitmq-management/raw-file/3646dee55e02/priv/www-api/help.html |
||
169 | * |
||
170 | * @return array |
||
171 | */ |
||
172 | protected function getApiQueueStatus() |
||
185 | |||
186 | /** |
||
187 | * {@inheritdoc} |
||
188 | */ |
||
189 | public function cleanup() |
||
193 | |||
194 | /** |
||
195 | */ |
||
196 | public function shutdown() |
||
206 | |||
207 | /** |
||
208 | * {@inheritdoc} |
||
209 | */ |
||
210 | public function initialize() |
||
213 | } |
||
214 |
This class, trait or interface has been deprecated.