1 | <?php |
||
13 | class RabbitMqManagerExtension extends Extension implements PrependExtensionInterface |
||
14 | { |
||
15 | /** |
||
16 | * @inheritdoc |
||
17 | */ |
||
18 | 4 | public function load(array $configs, ContainerBuilder $container) |
|
61 | |||
62 | /** |
||
63 | * @inheritdoc |
||
64 | */ |
||
65 | 2 | public function prepend(ContainerBuilder $container) |
|
78 | |||
79 | /** |
||
80 | * @param ContainerInterface $container |
||
81 | * @param string $name |
||
82 | * @param string $command |
||
83 | * @param array $config |
||
84 | * @param array $consumer |
||
85 | * |
||
86 | * @return array |
||
87 | */ |
||
88 | 3 | private function generateConfiguration(ContainerInterface $container, $name, $command, array $config, array $consumer) |
|
89 | { |
||
90 | 3 | $connection = $this->getConnection($container, $consumer); |
|
91 | |||
92 | return [ |
||
93 | 2 | 'name' => $name, |
|
94 | 2 | 'processor' => $config['processor'], |
|
95 | 2 | 'messages' => $config['messages'], |
|
96 | 2 | 'callback' => $consumer['callback'], |
|
97 | 'connection' => [ |
||
98 | 2 | 'host' => $connection['host'], |
|
99 | 2 | 'port' => $connection['port'], |
|
100 | 2 | 'user' => $connection['user'], |
|
101 | 2 | 'password' => $connection['password'], |
|
102 | 2 | 'vhost' => $connection['vhost'], |
|
103 | 2 | ], |
|
104 | 'supervisor' => [ |
||
105 | 2 | 'count' => $config['worker']['count'], |
|
106 | 2 | 'startsecs' => $config['worker']['startsecs'], |
|
107 | 2 | 'autorestart' => $config['worker']['autorestart'], |
|
108 | 2 | 'stopsignal' => $config['worker']['stopsignal'], |
|
109 | 2 | 'stopwaitsecs' => $config['worker']['stopwaitsecs'], |
|
110 | 2 | ], |
|
111 | 'command' => [ // todo make this configurable at some point. as for now it's not important... |
||
112 | 2 | 'console' => '%kernel.root_dir%/../bin/console', |
|
113 | 2 | 'command' => isset($config['command']['command']) ? $config['command']['command'] : $command, |
|
114 | 'arguments' => [ |
||
115 | 2 | '--env=%kernel.environment%', |
|
116 | 2 | '--app=%kernel.name%', |
|
117 | 2 | ], |
|
118 | 2 | ], |
|
119 | 'worker' => [ |
||
120 | 2 | 'compression' => $config['compression'], |
|
121 | 'prefetch' => [ |
||
122 | 2 | 'count' => isset($consumer['qos_options']['prefetch_count']) ? $consumer['qos_options']['prefetch_count'] : 0, |
|
123 | 2 | 'global' => isset($consumer['qos_options']['global']) ? $consumer['qos_options']['global'] : false, |
|
124 | 2 | ], |
|
125 | 'exchange' => [ |
||
126 | 2 | 'name' => $consumer['exchange_options']['name'], |
|
127 | 2 | 'type' => $consumer['exchange_options']['type'], |
|
128 | 2 | 'autodelete' => isset($consumer['exchange_options']['auto_delete']) ? $consumer['exchange_options']['auto_delete'] : false, |
|
129 | 2 | 'durable' => isset($consumer['exchange_options']['durable']) ? $consumer['exchange_options']['durable'] : true, |
|
130 | 2 | ], |
|
131 | 'queue' => [ |
||
132 | 2 | 'name' => $consumer['queue_options']['name'], |
|
133 | 2 | 'routing' => isset($consumer['queue_options']['routing_keys']) ? $consumer['queue_options']['routing_keys'] : null, |
|
134 | 2 | ], |
|
135 | 2 | ], |
|
136 | 2 | ]; |
|
137 | } |
||
138 | |||
139 | /** |
||
140 | * @param ContainerInterface $container |
||
141 | * @param array $consumer |
||
142 | * |
||
143 | * @return array |
||
144 | * |
||
145 | * @throws InvalidConfigurationException |
||
146 | */ |
||
147 | 3 | private function getConnection(ContainerInterface $container, array $consumer) |
|
162 | } |
||
163 |