@@ -4,9 +4,7 @@ |
||
4 | 4 | |
5 | 5 | use Puzzle\AMQP\Client; |
6 | 6 | use Puzzle\AMQP\WritableMessage; |
7 | -use Puzzle\AMQP\Messages\InMemoryJson; |
|
8 | 7 | use Psr\Log\NullLogger; |
9 | -use Puzzle\AMQP\Collections; |
|
10 | 8 | |
11 | 9 | class InMemory implements Client |
12 | 10 | { |
@@ -4,14 +4,11 @@ |
||
4 | 4 | |
5 | 5 | use Puzzle\Configuration; |
6 | 6 | use Puzzle\PrefixedConfiguration; |
7 | - |
|
8 | 7 | use Puzzle\AMQP\Client; |
9 | -use Puzzle\AMQP\Messages; |
|
10 | 8 | use Puzzle\AMQP\Workers\MessageAdapter; |
11 | 9 | use Psr\Log\LoggerAwareTrait; |
12 | 10 | use Psr\Log\NullLogger; |
13 | 11 | use Puzzle\AMQP\WritableMessage; |
14 | -use Puzzle\AMQP\Collections; |
|
15 | 12 | |
16 | 13 | class Pecl implements Client |
17 | 14 | { |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | |
33 | 33 | private function ensureIsConnected() |
34 | 34 | { |
35 | - if(! $this->channel instanceof \AMQPChannel) |
|
35 | + if (!$this->channel instanceof \AMQPChannel) |
|
36 | 36 | { |
37 | 37 | $configuration = new PrefixedConfiguration($this->configuration, 'amqp/broker'); |
38 | 38 | |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $connection->setPassword($configuration->readRequired('password')); |
44 | 44 | |
45 | 45 | $vhost = $configuration->read('vhost', null); |
46 | - if($vhost !== null) |
|
46 | + if ($vhost !== null) |
|
47 | 47 | { |
48 | 48 | $connection->setVhost($vhost); |
49 | 49 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | |
111 | 111 | $ex = new \AMQPExchange($this->channel); |
112 | 112 | |
113 | - if(!empty($exchangeName)) |
|
113 | + if (!empty($exchangeName)) |
|
114 | 114 | { |
115 | 115 | $ex->setName($exchangeName); |
116 | 116 | $ex->setType($type); |
@@ -60,8 +60,7 @@ discard block |
||
60 | 60 | try |
61 | 61 | { |
62 | 62 | $ex = $this->getExchange($exchangeName); |
63 | - } |
|
64 | - catch (\Exception $e) |
|
63 | + } catch (\Exception $e) |
|
65 | 64 | { |
66 | 65 | $this->logMessage($exchangeName, $message); |
67 | 66 | |
@@ -93,8 +92,7 @@ discard block |
||
93 | 92 | $message->getFlags(), |
94 | 93 | $message->packAttributes() |
95 | 94 | ); |
96 | - } |
|
97 | - catch (\Exception $e) |
|
95 | + } catch (\Exception $e) |
|
98 | 96 | { |
99 | 97 | $this->logMessage($ex->getName(), $message); |
100 | 98 |
@@ -19,6 +19,12 @@ |
||
19 | 19 | $this->overwrite = true; |
20 | 20 | } |
21 | 21 | |
22 | + /** |
|
23 | + * @param boolean $autostart |
|
24 | + * @param boolean $autorestart |
|
25 | + * @param string $appId |
|
26 | + * @param string $destination |
|
27 | + */ |
|
22 | 28 | public function generate(array $workers, $autostart, $autorestart, $server, $appId, $destination, OutputInterface $output) |
23 | 29 | { |
24 | 30 | foreach($workers as $worker => $data) |
@@ -21,14 +21,14 @@ discard block |
||
21 | 21 | |
22 | 22 | public function generate(array $workers, $autostart, $autorestart, $server, $appId, $destination, OutputInterface $output) |
23 | 23 | { |
24 | - foreach($workers as $worker => $data) |
|
24 | + foreach ($workers as $worker => $data) |
|
25 | 25 | { |
26 | - if( ! $data['isDeploymentAllowed']) |
|
26 | + if (!$data['isDeploymentAllowed']) |
|
27 | 27 | { |
28 | 28 | continue; |
29 | 29 | } |
30 | 30 | |
31 | - if( ! in_array($server, $data['servers'])) |
|
31 | + if (!in_array($server, $data['servers'])) |
|
32 | 32 | { |
33 | 33 | continue; |
34 | 34 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | $this->filesystem->write($filename, $configuration, $this->overwrite); |
46 | 46 | |
47 | 47 | $message = sprintf('%s', $destination . $filename); |
48 | - if($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) |
|
48 | + if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) |
|
49 | 49 | { |
50 | 50 | $message = sprintf("<comment>%s%s</comment>\n%s\n", $destination, $filename, $configuration); |
51 | 51 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | |
74 | 74 | public function setBody($body) |
75 | 75 | { |
76 | - if(! is_array($body)) |
|
76 | + if (!is_array($body)) |
|
77 | 77 | { |
78 | 78 | $body = array($body); |
79 | 79 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | |
105 | 105 | public function addHeaders(array $headers) |
106 | 106 | { |
107 | - foreach($headers as $name => $value) |
|
107 | + foreach ($headers as $name => $value) |
|
108 | 108 | { |
109 | 109 | $this->addHeader($name, $value); |
110 | 110 | } |
@@ -121,14 +121,14 @@ discard block |
||
121 | 121 | |
122 | 122 | public function packAttributes($timestamp = false) |
123 | 123 | { |
124 | - if($timestamp === false) |
|
124 | + if ($timestamp === false) |
|
125 | 125 | { |
126 | 126 | $timestamp = (new \DateTime("now"))->getTimestamp(); |
127 | 127 | } |
128 | 128 | |
129 | - return array_map(function ($value) use($timestamp) { |
|
129 | + return array_map(function($value) use($timestamp) { |
|
130 | 130 | |
131 | - if($value instanceof \Closure) |
|
131 | + if ($value instanceof \Closure) |
|
132 | 132 | { |
133 | 133 | $value = $value($timestamp); |
134 | 134 | } |
@@ -147,9 +147,9 @@ discard block |
||
147 | 147 | |
148 | 148 | public function setAttribute($attributeName, $value) |
149 | 149 | { |
150 | - if($attributeName !== 'headers') |
|
150 | + if ($attributeName !== 'headers') |
|
151 | 151 | { |
152 | - if(array_key_exists($attributeName, $this->attributes)) |
|
152 | + if (array_key_exists($attributeName, $this->attributes)) |
|
153 | 153 | { |
154 | 154 | $this->attributes[$attributeName] = $value; |
155 | 155 | } |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | |
173 | 173 | public function getAttribute($attributeName) |
174 | 174 | { |
175 | - if(array_key_exists($attributeName, $this->attributes)) |
|
175 | + if (array_key_exists($attributeName, $this->attributes)) |
|
176 | 176 | { |
177 | 177 | return $this->attributes[$attributeName]; |
178 | 178 | } |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | { |
204 | 204 | $routingKey = $readableMessage->getRoutingKey(); |
205 | 205 | |
206 | - if($newRoutingKey !== false) |
|
206 | + if ($newRoutingKey !== false) |
|
207 | 207 | { |
208 | 208 | $routingKey = $newRoutingKey; |
209 | 209 | } |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | $writableMessage = new static($routingKey); |
212 | 212 | |
213 | 213 | $decodedBody = $readableMessage->getDecodedBody(); |
214 | - if(! is_array($decodedBody)) |
|
214 | + if (!is_array($decodedBody)) |
|
215 | 215 | { |
216 | 216 | $decodedBody = array($decodedBody); |
217 | 217 | } |
@@ -222,9 +222,9 @@ discard block |
||
222 | 222 | |
223 | 223 | $attributes = $readableMessage->getAttributes(); |
224 | 224 | $skippedAttributes = array('timestamp', 'headers', 'app_id', 'routing_key'); |
225 | - foreach($attributes as $attributeName => $value) |
|
225 | + foreach ($attributes as $attributeName => $value) |
|
226 | 226 | { |
227 | - if(! in_array($attributeName, $skippedAttributes)) |
|
227 | + if (!in_array($attributeName, $skippedAttributes)) |
|
228 | 228 | { |
229 | 229 | $writableMessage->setAttribute($attributeName, $value); |
230 | 230 | } |
@@ -23,12 +23,12 @@ discard block |
||
23 | 23 | $workerContext = null; |
24 | 24 | $key = $this->computeWorkerServiceKey($workerName); |
25 | 25 | |
26 | - if(isset($this->container[$key])) |
|
26 | + if (isset($this->container[$key])) |
|
27 | 27 | { |
28 | 28 | $workerContext = $this->container[$key]; |
29 | 29 | } |
30 | 30 | |
31 | - if(isset($this->container[self::MESSAGE_HOOKS_DIC_KEY])) |
|
31 | + if (isset($this->container[self::MESSAGE_HOOKS_DIC_KEY])) |
|
32 | 32 | { |
33 | 33 | $workerContext->setMessageHooks($this->container[self::MESSAGE_HOOKS_DIC_KEY]); |
34 | 34 | } |
@@ -64,12 +64,12 @@ discard block |
||
64 | 64 | { |
65 | 65 | $workers = array(); |
66 | 66 | |
67 | - foreach($extractedWorkers as $worker) |
|
67 | + foreach ($extractedWorkers as $worker) |
|
68 | 68 | { |
69 | 69 | $key = $this->formatWorkerName($worker); |
70 | 70 | $worker = $this->container[$worker]; |
71 | 71 | |
72 | - if($worker instanceof WorkerContext) |
|
72 | + if ($worker instanceof WorkerContext) |
|
73 | 73 | { |
74 | 74 | $workers[$key] = [ |
75 | 75 | 'queue' => $worker->getQueue(), |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | |
43 | 43 | public function getWorker() |
44 | 44 | { |
45 | - if($this->worker instanceof \Closure) |
|
45 | + if ($this->worker instanceof \Closure) |
|
46 | 46 | { |
47 | 47 | $closure = $this->worker; |
48 | 48 | $this->worker = $closure(); |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | |
100 | 100 | public function deployInstances($numberOfInstance) |
101 | 101 | { |
102 | - if(! empty($numberOfInstance)) |
|
102 | + if (!empty($numberOfInstance)) |
|
103 | 103 | { |
104 | 104 | $this->instances = (int) $numberOfInstance; |
105 | 105 | } |
@@ -114,9 +114,9 @@ discard block |
||
114 | 114 | |
115 | 115 | public function deployOn($servers) |
116 | 116 | { |
117 | - if(! empty($servers)) |
|
117 | + if (!empty($servers)) |
|
118 | 118 | { |
119 | - if(! is_array($servers)) |
|
119 | + if (!is_array($servers)) |
|
120 | 120 | { |
121 | 121 | $servers = [$servers]; |
122 | 122 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | $callable = $this->getFormatterStrategy($this->getContentType()); |
51 | 51 | $body = $this->getRawBody(); |
52 | 52 | |
53 | - if($callable instanceof \Closure) |
|
53 | + if ($callable instanceof \Closure) |
|
54 | 54 | { |
55 | 55 | $body = $callable($body); |
56 | 56 | } |
@@ -65,11 +65,11 @@ discard block |
||
65 | 65 | |
66 | 66 | public function applyHooks(MessageHookCollection $messageHookCollection) |
67 | 67 | { |
68 | - if(!empty($messageHookCollection)) |
|
68 | + if (!empty($messageHookCollection)) |
|
69 | 69 | { |
70 | - foreach($messageHookCollection as $messageHook) |
|
70 | + foreach ($messageHookCollection as $messageHook) |
|
71 | 71 | { |
72 | - if($messageHook instanceof MessageHook) |
|
72 | + if ($messageHook instanceof MessageHook) |
|
73 | 73 | { |
74 | 74 | $this->decodedBody = $messageHook->process($this->decodedBody); |
75 | 75 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | public function getAttribute($attributeName) |
86 | 86 | { |
87 | 87 | $messageProperties = $this->message->getProperties(); |
88 | - if(array_key_exists($attributeName, $messageProperties)) |
|
88 | + if (array_key_exists($attributeName, $messageProperties)) |
|
89 | 89 | { |
90 | 90 | return $messageProperties[$attributeName]; |
91 | 91 | } |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | }, |
102 | 102 | ); |
103 | 103 | |
104 | - if(array_key_exists($contentType, $formatterStrategies) === true) |
|
104 | + if (array_key_exists($contentType, $formatterStrategies) === true) |
|
105 | 105 | { |
106 | 106 | return $formatterStrategies[$contentType]; |
107 | 107 | } |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | private function getHeader($headerName) |
135 | 135 | { |
136 | 136 | $headers = $this->getHeaders(); |
137 | - if(array_key_exists($headerName, $headers)) |
|
137 | + if (array_key_exists($headerName, $headers)) |
|
138 | 138 | { |
139 | 139 | return $headers[$headerName]; |
140 | 140 | } |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | { |
159 | 159 | $headers = $this->getHeaders(); |
160 | 160 | |
161 | - if(! array_key_exists('routing_key', $headers)) |
|
161 | + if (!array_key_exists('routing_key', $headers)) |
|
162 | 162 | { |
163 | 163 | return null; |
164 | 164 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | |
26 | 26 | $hooks = $this->workerContext->getMessageHooks(); |
27 | 27 | |
28 | - if(!empty($hooks)) |
|
28 | + if (!empty($hooks)) |
|
29 | 29 | { |
30 | 30 | $message->applyHooks($hooks); |
31 | 31 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | { |
39 | 39 | $processResult = $this->workerContext->getWorker()->process($message); |
40 | 40 | } |
41 | - catch(\Exception $exception) |
|
41 | + catch (\Exception $exception) |
|
42 | 42 | { |
43 | 43 | $this->onWorkerProcessed(); |
44 | 44 |
@@ -37,8 +37,7 @@ |
||
37 | 37 | try |
38 | 38 | { |
39 | 39 | $processResult = $this->workerContext->getWorker()->process($message); |
40 | - } |
|
41 | - catch(\Exception $exception) |
|
40 | + } catch(\Exception $exception) |
|
42 | 41 | { |
43 | 42 | $this->onWorkerProcessed(); |
44 | 43 |
@@ -43,12 +43,12 @@ |
||
43 | 43 | 'max_execution_time' => self::DEFAULT_MAX_EXECUTION_TIME, |
44 | 44 | ); |
45 | 45 | |
46 | - if(!empty($this->retries)) |
|
46 | + if (!empty($this->retries)) |
|
47 | 47 | { |
48 | 48 | $options['instant_retry_attempts'] = $this->retries; |
49 | 49 | } |
50 | 50 | |
51 | - if(!empty($this->delay)) |
|
51 | + if (!empty($this->delay)) |
|
52 | 52 | { |
53 | 53 | $options['instant_retry_delay'] = $this->delay * 1000000; //computed in microseconds |
54 | 54 | } |