Skip to content

Commit 69fde42

Browse files
SWR-17938 #comment Vhost Not Created Automatically
1 parent d11fbd2 commit 69fde42

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ Only the latest version will get new features. Bug fixes will be provided using
1111

1212
| Package Version | Laravel Version | Bug Fixes Until | |
1313
|-----------------|-----------------|------------------|---------------------------------------------------------------------------------------------|
14-
| 1 | 19 | April 23th, 2025 | [Documentation](https://github.com/vyuldashev/laravel-queue-rabbitmq/blob/master/README.md) |
14+
| 1 | 20 | April 23th, 2025 | [Documentation](https://github.com/vyuldashev/laravel-queue-rabbitmq/blob/master/README.md) |
1515

1616
## Installation
1717

1818
You can install this package via composer using this command:
1919

2020
```
21-
composer require salesmessage/php-lib-rabbitmq:^1.19 --ignore-platform-reqs
21+
composer require salesmessage/php-lib-rabbitmq:^1.20 --ignore-platform-reqs
2222
```
2323

2424
The package will automatically register itself.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
},
3535
"extra": {
3636
"branch-alias": {
37-
"dev-master": "1.19-dev"
37+
"dev-master": "1.20-dev"
3838
},
3939
"laravel": {
4040
"providers": [

src/Queue/RabbitMQQueueBatchable.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ protected function createChannel(): AMQPChannel
6565
{
6666
try {
6767
return parent::createChannel();
68-
} catch (AMQPConnectionClosedException) {
68+
} catch (AMQPConnectionClosedException $exception) {
69+
if ($this->isVhostFailedException($exception) && (false === $this->createNotExistsVhost())) {
70+
throw $exception;
71+
}
72+
6973
$this->reconnect();
7074
return parent::createChannel();
7175
}
@@ -148,5 +152,27 @@ private function addQueueToIndex(string $queue): bool
148152

149153
return $isQueueActivated && $isVhostActivated;
150154
}
155+
156+
/**
157+
* @param AMQPConnectionClosedException $exception
158+
* @return bool
159+
*/
160+
private function isVhostFailedException(AMQPConnectionClosedException $exception): bool
161+
{
162+
$dto = new ConnectionNameDto($this->getConnectionName());
163+
$vhostName = (string) $dto->getVhostName();
164+
165+
$notFoundErrorMessage = sprintf('NOT_ALLOWED - vhost %s not found', $vhostName);
166+
if ((403 === $exception->getCode()) && str_contains($exception->getMessage(), $notFoundErrorMessage)) {
167+
return true;
168+
}
169+
170+
$deletedErrorMessage = sprintf('CONNECTION_FORCED - vhost \'%s\' is deleted', $vhostName);
171+
if (str_contains($exception->getMessage(), $deletedErrorMessage)) {
172+
return true;
173+
}
174+
175+
return false;
176+
}
151177
}
152178

0 commit comments

Comments
 (0)