| @@ 9-60 (lines=52) @@ | ||
| 6 | use Puzzle\AMQP\WritableMessage; |
|
| 7 | use Psr\Log\LoggerAwareTrait; |
|
| 8 | ||
| 9 | class PrefixedExchangesClient implements Client |
|
| 10 | { |
|
| 11 | const |
|
| 12 | DELIMITER = '.'; |
|
| 13 | ||
| 14 | use LoggerAwareTrait; |
|
| 15 | ||
| 16 | private |
|
| 17 | $client, |
|
| 18 | $exchangesPrefix; |
|
| 19 | ||
| 20 | public function __construct(Client $client, $exchangesPrefix) |
|
| 21 | { |
|
| 22 | $this->client = $client; |
|
| 23 | $this->exchangesPrefix = $exchangesPrefix; |
|
| 24 | } |
|
| 25 | ||
| 26 | public function publish($exchangeName, WritableMessage $message) |
|
| 27 | { |
|
| 28 | return $this->client->publish( |
|
| 29 | $this->computeExchangeName($exchangeName), |
|
| 30 | $message |
|
| 31 | ); |
|
| 32 | } |
|
| 33 | ||
| 34 | private function computeExchangeName($exchangeName) |
|
| 35 | { |
|
| 36 | $exchangeParts = []; |
|
| 37 | ||
| 38 | if(! empty($this->exchangesPrefix)) |
|
| 39 | { |
|
| 40 | $exchangeParts[] = trim($this->exchangesPrefix); |
|
| 41 | } |
|
| 42 | ||
| 43 | $exchangeParts[] = $exchangeName; |
|
| 44 | ||
| 45 | return trim(implode(self::DELIMITER, $exchangeParts)); |
|
| 46 | ||
| 47 | } |
|
| 48 | ||
| 49 | public function getQueue($queueName) |
|
| 50 | { |
|
| 51 | return $this->client->getQueue($queueName); |
|
| 52 | } |
|
| 53 | ||
| 54 | public function getExchange($exchangeName) |
|
| 55 | { |
|
| 56 | return $this->client->getExchange( |
|
| 57 | $this->computeExchangeName($exchangeName) |
|
| 58 | ); |
|
| 59 | } |
|
| 60 | } |
|
| 61 | ||
| @@ 9-56 (lines=48) @@ | ||
| 6 | use Puzzle\AMQP\WritableMessage; |
|
| 7 | use Psr\Log\LoggerAwareTrait; |
|
| 8 | ||
| 9 | class PrefixedQueueNameClient implements Client |
|
| 10 | { |
|
| 11 | const |
|
| 12 | DELIMITER = '.'; |
|
| 13 | ||
| 14 | use LoggerAwareTrait; |
|
| 15 | ||
| 16 | private |
|
| 17 | $client, |
|
| 18 | $queueNamePrefix; |
|
| 19 | ||
| 20 | public function __construct(Client $client, $queueNamePrefix) |
|
| 21 | { |
|
| 22 | $this->client = $client; |
|
| 23 | $this->queueNamePrefix = $queueNamePrefix; |
|
| 24 | } |
|
| 25 | ||
| 26 | public function publish($exchangeName, WritableMessage $message) |
|
| 27 | { |
|
| 28 | return $this->client->publish($exchangeName, $message); |
|
| 29 | } |
|
| 30 | ||
| 31 | public function getQueue($queueName) |
|
| 32 | { |
|
| 33 | $prefixedQueueName = $this->computePrefixedQueueName($queueName); |
|
| 34 | ||
| 35 | return $this->client->getQueue($prefixedQueueName); |
|
| 36 | } |
|
| 37 | ||
| 38 | public function getExchange($exchangeName) |
|
| 39 | { |
|
| 40 | return $this->client->getExchange($exchangeName); |
|
| 41 | } |
|
| 42 | ||
| 43 | private function computePrefixedQueueName($queueName) |
|
| 44 | { |
|
| 45 | $queueNameParts = []; |
|
| 46 | ||
| 47 | if(! empty($this->queueNamePrefix)) |
|
| 48 | { |
|
| 49 | $queueNameParts[] = trim($this->queueNamePrefix); |
|
| 50 | } |
|
| 51 | ||
| 52 | $queueNameParts[] = $queueName; |
|
| 53 | ||
| 54 | return implode(self::DELIMITER, $queueNameParts); |
|
| 55 | } |
|
| 56 | } |
|
| 57 | ||