Skip to content

Commit

Permalink
Make vhost configurable #39
Browse files Browse the repository at this point in the history
  • Loading branch information
cerpusoddarne committed Jan 30, 2019
1 parent 259e984 commit e90d4fd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Tools like the Rabbitmq *[Management](https://www.rabbitmq.com/management.html)*

### Configuration

In order to configure rabbitmq host, port, username, password and configure the timeout values too, add the following inside the connections array in config/queue.php file:
In order to configure rabbitmq host, port, username, password and configure the timeout and vhost values too, add the following inside the connections array in config/queue.php file:

```php
'rabbitmq' => [
Expand All @@ -45,10 +45,11 @@ In order to configure rabbitmq host, port, username, password and configure the
'connection_timeout' => 30,
'read_write_timeout' => 30,
'heartbeat' => 15,
'vhost' => '/',
],
```

The default value for `connection_timeout` and `read_write_timeout` is set to 30 (seconds) and `heartbeat` is set to 15 (seconds).
The default value for `connection_timeout` and `read_write_timeout` is set to 30 (seconds) and `heartbeat` is set to 15 (seconds). The `vhost` value defaults to '/'.

And register the service provider by adding `Vinelab\Bowler\BowlerServiceProvider::class` to the providers array in `config/app`.

Expand Down
3 changes: 2 additions & 1 deletion src/BowlerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ public function register()
$rbmqConnectionTimeout = config('queue.connections.rabbitmq.connection_timeout') ? (int) config('queue.connections.rabbitmq.connection_timeout') : 30;
$rbmqReadWriteTimeout = config('queue.connections.rabbitmq.read_write_timeout') ? (int) config('queue.connections.rabbitmq.read_write_timeout') : 30;
$rbmqHeartbeat = config('queue.connections.rabbitmq.heartbeat') ? (int) config('queue.connections.rabbitmq.heartbeat') : 15;
$rbmqVhost = config('queue.connections.rabbitmq.vhost', '/');

return new Connection($rbmqHost, $rbmqPort, $rbmqUsername, $rbmqPassword, $rbmqConnectionTimeout, $rbmqReadWriteTimeout, $rbmqHeartbeat);
return new Connection($rbmqHost, $rbmqPort, $rbmqUsername, $rbmqPassword, $rbmqConnectionTimeout, $rbmqReadWriteTimeout, $rbmqHeartbeat, $rbmqVhost);
});

$this->app->bind(
Expand Down
14 changes: 10 additions & 4 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ class Connection
*/
private $heartbeat = 15;

/**
* RabbitMQ vhost.
* @var string
*/
private $vhost = '/';

/**
* @param string $host the ip of the rabbitmq server, default: localhost
* @param int $port. default: 5672
Expand All @@ -88,7 +94,7 @@ class Connection
* @param int $readWriteTimeout, default: 30
* @param int $heartbeat, default: 15
*/
public function __construct($host = 'localhost', $port = 5672, $username = 'guest', $password = 'guest', $connectionTimeout = 30, $readWriteTimeout = 30, $heartbeat = 15)
public function __construct($host = 'localhost', $port = 5672, $username = 'guest', $password = 'guest', $connectionTimeout = 30, $readWriteTimeout = 30, $heartbeat = 15, $vhost = '/')
{
$this->host = $host;
$this->port = $port;
Expand All @@ -97,13 +103,13 @@ public function __construct($host = 'localhost', $port = 5672, $username = 'gues
$this->connectionTimeout = $connectionTimeout;
$this->readWriteTimeout = $readWriteTimeout;
$this->heartbeat = $heartbeat;
$this->vhost = $vhost;

$this->initAMQPStreamConnection($host, $port, $username, $password, $connectionTimeout, $readWriteTimeout, $heartbeat);
$this->initAMQPStreamConnection($host, $port, $username, $password, $connectionTimeout, $readWriteTimeout, $heartbeat, $vhost);
}

protected function initAMQPStreamConnection($host, $port, $username, $password, $connectionTimeout, $readWriteTimeout, $heartbeat, $vhost = '/',$insist = false, $login_method = 'AMQPLAIN', $login_response = null, $locale = 'en_US', $context = null, $keepalive = false)
protected function initAMQPStreamConnection($host, $port, $username, $password, $connectionTimeout, $readWriteTimeout, $heartbeat, $vhost = '/', $insist = false, $login_method = 'AMQPLAIN', $login_response = null, $locale = 'en_US', $context = null, $keepalive = false)
{
$vhost = '/';
$insist = false;
$login_method = 'AMQPLAIN';
$login_response = null;
Expand Down

0 comments on commit e90d4fd

Please sign in to comment.