Resilience
Overview
Fountain bundles resilience patterns — flow control, circuit breaking, and rate limiting — to keep services stable under load.
Available packages:
fsentinel— Sentinel-based flow control, circuit breaking, and adaptive system protection.
Example
A Sentinel flow-control setup:
go
/* !!
* File: main.go
* File Created: Tuesday, 28th June 2022 4:24:43 pm
* Author: Kim Ericko ([email protected])
* -----
* Last Modified: Thursday, 30th June 2022 4:25:20 pm
* Modified By: Kim Ericko ([email protected])
* -----
* Copyright 2022 Soludian, soludian.com
* All rights reserved.
*
* Licensed under the SOLUDIAN TECHNOLOGY SOLUTION CO., LTD Software License Agreement.
* Unauthorized use, reproduction, or distribution is prohibited (the "License");
*
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* [email protected] / https://www.soludian.com/license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* -----
*
* HISTORY:
*
* Date By Comments
* ---------- --- ---------------------------------------------------------
*/
package main
import (
"fmt"
"github.com/gofiber/fiber/v3"
"gitlab.soludian.com/soludian/fountain"
"gitlab.soludian.com/soludian/fountain/libs/flog"
"gitlab.soludian.com/soludian/fountain/libs/fnet/fhttp"
)
var logger = flog.NewFountainLoggerOnce()
type APIServer struct {
*fhttp.Server
}
func (s *APIServer) Initialize() error {
s.Server = fhttp.InstallFountainInstance()
s.Server.Get("/panic", func(ctx fiber.Ctx) error {
err := fmt.Errorf("Route panic")
logger.WErr(err).Panicf(err.Error())
return err
})
s.Server.Get("/200", func(ctx fiber.Ctx) error {
return ctx.SendString("hello")
})
s.Server.Get("/hello", func(ctx fiber.Ctx) error {
return ctx.JSON("Hello client: " + ctx.Get("app"))
})
s.Server.Get("/500", func(ctx fiber.Ctx) error {
return ctx.Status(500).JSON("Hello client: " + ctx.Get("app"))
})
return nil
}
// export FOUNTAIN_DEBUG_MODE=true && go run main.go
// ab -n 10 -c 10 http://127.0.0.1:9007/hello, you can see 429, indicating current limit
func main() {
server := &APIServer{}
fountain.WithAppInstances(server).Serving()
}See also
- Reference:
fsentinel - Observability — monitor the behavior these rules govern
- Examples index