<?php
// config/packages/deeep_service_client.php
declare(strict_types=1);
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
return App::config([
'deeep_service_client' => [
// Default settings for all services
'defaults' => [
'timeout' => [
'connect' => 5.0, // Connection timeout in seconds
'request' => 30.0, // Overall request timeout in seconds
],
'retry' => [
'enabled' => true,
'max_attempts' => 3, // Total attempts (1 initial + 2 retries)
'delay' => 1000, // Initial delay in milliseconds
'multiplier' => 2.0, // Exponential backoff multiplier
'max_delay' => 30000, // Maximum delay in milliseconds
'jitter' => 0.1, // Random jitter factor (0.0 - 1.0)
'retry_on' => [429, 502, 503, 504],
'retry_on_methods' => ['GET', 'HEAD', 'PUT', 'DELETE', 'OPTIONS'],
'respect_retry_after' => true,
],
'logging' => [
'enabled' => true,
'level' => 'info', // Log level: debug, info, warning, error
'log_body' => false, // Log request/response bodies
'max_body_length' => 1000,
'sensitive_headers' => [ // Headers to redact in logs
'authorization',
'api-key',
'x-api-key',
'cookie',
'set-cookie',
],
],
'circuit_breaker' => [
'enabled' => false,
'failure_threshold' => 5, // Failures before opening circuit
'open_timeout' => 30, // Seconds before retry attempt
'half_open_requests' => 1, // Test requests in half-open state
],
],
'services' => [
// Simple service
'my_api' => [
'host' => '%env(resolve:MY_API_HOST)%',
'proxy' => '%env(resolve:PROXY_HOST)%', // Optional
'auth' => [
'type' => 'bearer', // bearer, api_key, basic
'credentials' => [
'token' => '%env(resolve:API_TOKEN)%',
],
],
// Overrides for specific service
'timeout' => [
'connect' => 10.0,
'request' => 60.0,
],
'retry' => [
'max_attempts' => 5,
'delay' => 2000,
],
'logging' => [
'log_body' => true,
],
'circuit_breaker' => [
'enabled' => true,
],
],
// Multi-host configuration
'multi_host_api' => [
'hosts' => [
'strategy' => 'failover', // failover, round_robin, parallel
'mode' => 'first', // For parallel: first, all
'timeout' => 5.0, // Strategy timeout
'health_check' => [
'enabled' => false,
'interval' => 30,
'path' => '/health',
'timeout' => 5,
],
'list' => [
[
'url' => 'https://primary.example.com',
'proxy' => null,
'weight' => 1,
],
[
'url' => 'https://backup.example.com',
],
],
],
],
],
],
]);
Override timeout and retry settings for individual requests via ConfigurableRequestInterface:
use Deeep\ServiceClient\Config\RetryConfig;
use Deeep\ServiceClient\Config\TimeoutConfig;
use Deeep\ServiceClient\Contract\ConfigurableRequestInterface;
use Deeep\ServiceClient\Enum\HttpMethod;
use Deeep\ServiceClient\Request\AbstractRequest;
final readonly class SlowApiRequest extends AbstractRequest implements ConfigurableRequestInterface
{
public function __construct(
private array $payload,
) {}
public function getService(): string
{
return 'slow_api';
}
public function getMethod(): HttpMethod
{
return HttpMethod::POST;
}
public function getUri(): string
{
return '/process';
}
public function getBody(): array
{
return $this->payload;
}
public function getTimeout(): ?TimeoutConfig
{
return new TimeoutConfig(
connect: 10.0,
request: 300.0, // 5 minutes for slow API
);
}
public function getRetry(): ?RetryConfig
{
return new RetryConfig(
enabled: true,
maxAttempts: 5,
delay: 5000,
);
}
}
How can I help you explore Laravel packages today?