func main()

in example/isolation/concurrency_limitation_example.go [28:67]


func main() {
	cfg := config.NewDefaultConfig()
	// for testing, logging output to console
	cfg.Sentinel.Log.Logger = logging.NewConsoleLogger()
	err := sentinel.InitWithConfig(cfg)
	if err != nil {
		logging.Error(err, "fail")
		os.Exit(1)
	}
	logging.ResetGlobalLoggerLevel(logging.DebugLevel)
	ch := make(chan struct{})

	r1 := &isolation.Rule{
		Resource:   "abc",
		MetricType: isolation.Concurrency,
		Threshold:  12,
	}
	_, err = isolation.LoadRules([]*isolation.Rule{r1})
	if err != nil {
		logging.Error(err, "fail")
		os.Exit(1)
	}

	for i := 0; i < 15; i++ {
		go func() {
			for {
				e, b := sentinel.Entry("abc", sentinel.WithBatchCount(1))
				if b != nil {
					logging.Info("[Isolation] Blocked", "reason", b.BlockType().String(), "rule", b.TriggeredRule(), "snapshot", b.TriggeredValue())
					time.Sleep(time.Duration(rand.Uint64()%20) * time.Millisecond)
				} else {
					logging.Info("[Isolation] Passed")
					time.Sleep(time.Duration(rand.Uint64()%20) * time.Millisecond)
					e.Exit()
				}
			}
		}()
	}
	<-ch
}