承接 dedenfarhanhub/db-failover 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dedenfarhanhub/db-failover

Composer 安装命令:

composer require dedenfarhanhub/db-failover

包简介

Laravel DB Failover + Telegram Notification + Circuit Breaker + Dynamic DB Switching

README 文档

README

Build

Description

SultanDB is a Laravel package that automatically performs failover to a backup database connection when the primary connection is down. This package supports:

  • Dynamic Connection Switching
  • Circuit Breaker Pattern
  • Telegram & Slack Notification
  • Auto DB Health Monitoring
  • Redis Fallback Cache
  • CI/CD Pipeline

Installation

1. Install via Composer

composer require dedenfarhanhub/db-failover

2. Publish Configuration

php artisan vendor:publish --tag=db-failover-config

3. Environment Setup

Add the following lines to your .env file:

DB_FAILOVER_TELEGRAM=true
TELEGRAM_BOT_TOKEN=xxxxxx
TELEGRAM_CHAT_ID=xxxxx

Usage Example

Middleware Implementation

Add middleware to app/Http/Kernel.php:

protected $middleware = [
    \SultanDB\Middleware\DBMonitor::class,
];

Sending Manual Telegram Notification

use SultanDB\Helpers\Telegram;

Telegram::sendMessage("Database is down!");

Features

1. Dynamic Connection Switching

Automatically switches from the primary connection to the secondary connection if the primary connection fails.

2. Circuit Breaker Pattern

Counts the number of failures within a certain period before automatically breaking the connection.

3. Automatic Notifications

Sends notifications to Telegram if there is any database connection issue.

4. Redis Fallback Cache

Automatically falls back to Redis Cache if all database connections fail.

Configuration

config/db-failover.php

return [
    'telegram' => [
        'enabled' => env('DB_FAILOVER_TELEGRAM', true),
        'token' => env('TELEGRAM_BOT_TOKEN'),
        'chat_id' => env('TELEGRAM_CHAT_ID'),
    ],
    'circuit_breaker' => [
        'attempt_limit' => 3,
        'timeout' => 300,
    ],
    'db_switch' => [
        'redis_timeout' => 300,
    ],
];

Testing

php artisan test

Contributing

Pull requests are highly welcome 🔥. Please include tests and documentation where possible.

License

MIT

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-05