Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load timeouts from laravel config #612

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,33 @@ Available protocols : `tcp`, `ssl`, `tls`
],
```

### Network Timeouts

For network timeouts configuration you can use option parameters.
All float values are in seconds and zero value can mean infinite timeout.
Example contains default values.

```php
'connections' => [
// ...

'rabbitmq' => [
// ...

'options' => [
// ...

'connection_timeout' => 3.0,
'read_timeout' => 3.0,
'write_timeout' => 3.0,
'channel_rpc_timeout' => 0.0,
],
],

// ...
],
```

### Octane support

Starting with 13.3.0, this package supports [Laravel Octane](https://laravel.com/docs/octane) out of the box.
Expand Down
24 changes: 24 additions & 0 deletions src/Queue/Connection/ConfigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static function make(array $config = []): AMQPConnectionConfig
self::getHostFromConfig($connectionConfig, $config);
self::getHeartbeatFromConfig($connectionConfig, $config);
self::getNetworkProtocolFromConfig($connectionConfig, $config);
self::getTimeoutsFromConfig($connectionConfig, $config);
});
}

Expand Down Expand Up @@ -99,4 +100,27 @@ protected static function getNetworkProtocolFromConfig(AMQPConnectionConfig $con
$connectionConfig->setNetworkProtocol($networkProtocol);
}
}

protected static function getTimeoutsFromConfig(AMQPConnectionConfig $connectionConfig, array $config): void
{
$connectionTimeout = Arr::get($config, self::CONFIG_OPTIONS.'.connection_timeout');
if (is_numeric($connectionTimeout) && floatval($connectionTimeout) >= 0) {
$connectionConfig->setConnectionTimeout((float) $connectionTimeout);
}

$readTimeout = Arr::get($config, self::CONFIG_OPTIONS.'.read_timeout');
if (is_numeric($readTimeout) && floatval($readTimeout) >= 0) {
$connectionConfig->setReadTimeout((float) $readTimeout);
}

$writeTimeout = Arr::get($config, self::CONFIG_OPTIONS.'.write_timeout');
if (is_numeric($writeTimeout) && floatval($writeTimeout) >= 0) {
$connectionConfig->setWriteTimeout((float) $writeTimeout);
}

$chanelRpcTimeout = Arr::get($config, self::CONFIG_OPTIONS.'.channel_rpc_timeout');
if (is_numeric($chanelRpcTimeout) && floatval($chanelRpcTimeout) >= 0) {
$connectionConfig->setChannelRPCTimeout((float) $chanelRpcTimeout);
}
}
}