Skip to content

Multiple types of rules use on the same resource name #154

@BamLubi

Description

@BamLubi

I'am trying to use crate sentinel_core in my project, I need to apply QPS rule and Connection rule on the same resource name.

The question is when to use EntryBuilder::exit() to release the entry.

As far as i'm known,

  • QPS is defined as the rate at which requests arrive.
  • Concurrency is defined as the number of requests currently is processing.

No matter how to understand it, if the "entry.exit()" time is same for both, then they are no different.
I'm not sure if I'm wrong or if two resource names should be set for this scenario.

sentinel_core::flow::load_rules(vec![Arc::new(sentinel_core::flow::Rule {
    resource: "example".into(),
    threshold: 1.0,
    stat_interval_ms: 1000,
    calculate_strategy: sentinel_core::flow::CalculateStrategy::Direct,
    control_strategy: sentinel_core::flow::ControlStrategy::Reject,
    ..Default::default()
})]);
sentinel_core::isolation::load_rules(vec![Arc::new(sentinel_core::isolation::Rule {
    id: Default::default(),
    resource: "example".into(),
    metric_type: isolation::MetricType::Concurrency,
    threshold: 1,
})]);

let entry_builder = sentinel_core::EntryBuilder::new("example".to_string())
    .with_traffic_type(sentinel_core::base::TrafficType::Inbound);

match entry_builder.build() {
    Ok(entry) => {
        // 被允许的请求
        println!("Request {}: Allowed", i);
        // 在此处理业务逻辑...

        // 确保退出 entry
        entry.exit()
    }
    Err(_) => {
        // 被拒绝的请求
        println!("Request {}: Blocked by Sentinel", i);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions