定制 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
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固