pub struct LimitConnPlugin {
role: Role,
conn: i64,
burst: i64,
key: String,
key_constant: bool,
rejected_code: u16,
rejected_msg: Option<String>,
resources: Arc<PluginResources>,
}Expand description
One node of a limit-conn acquire/release pair.
Holds a handle to the process-wide crate::traffic::ConnRegistry; the
per-key counter is resolved at request time from the interpolated key so
concurrency is measured per client (or per whatever the key selects), shared
across both nodes of the pair.
Fields§
§role: Role§conn: i64Maximum sustained concurrent requests.
burst: i64Extra concurrent requests tolerated above conn.
key: StringKey template (interpolated per request unless key_type is constant).
key_constant: boolWhen true, key is used verbatim rather than interpolated.
rejected_code: u16Status returned when the limit is exceeded.
rejected_msg: Option<String>Optional human-readable rejection message (JSON {"error_msg": ...}).
resources: Arc<PluginResources>Implementations§
Source§impl LimitConnPlugin
impl LimitConnPlugin
Sourcepub fn from_config(
config: &HashMap<String, Value>,
resources: &Arc<PluginResources>,
) -> Result<Self, String>
pub fn from_config( config: &HashMap<String, Value>, resources: &Arc<PluginResources>, ) -> Result<Self, String>
Builds one node of the pair from node config.
Accepted keys:
phase/role(string, required):acquire(before upstream) orrelease(after upstream). Any other value is a config error.conn(integer, default20): maximum sustained concurrent requests. Must be> 0.burst(integer, default0): extra concurrent requests tolerated aboveconn. Must be>= 0. The hard ceiling isconn + burst.key(string template, default"$remote_addr"): the concurrency key, interpolated per request (seecrate::vars::interpolate). Both nodes of a pair must use the samekeyandconn/burstso they share one counter.key_type(string, defaultvar):constantuseskeyverbatim; any other value (var,var_combination) interpolates it.rejected_code(integer, default503): status for over-limit requests.rejected_msg(string, optional): message returned as a JSON body{"error_msg": "..."}on rejection.default_conn_delay(number, optional): accepted for APISIX config compatibility but ignored — featherbit rejects rather than delays.
# before upstream
type: limit-conn
config:
phase: acquire
conn: 100
burst: 50
key: $remote_addr
rejected_code: 503
---
# after upstream (on both success and error paths)
type: limit-conn
config:
phase: release
conn: 100
burst: 50
key: $remote_addrSourcefn resolve_key(&self, ctx: &Context) -> String
fn resolve_key(&self, ctx: &Context) -> String
Resolves the concurrency key for this request.
Trait Implementations§
Source§impl Plugin for LimitConnPlugin
impl Plugin for LimitConnPlugin
Source§fn plugin_type(&self) -> &str
fn plugin_type(&self) -> &str
Unique identifier for the plugin type (e.g., “proxy-rewrite”, “upstream”).
Source§fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: Context,
_named_inputs: &'life1 HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<PluginOutput, PluginExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: Context,
_named_inputs: &'life1 HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<PluginOutput, PluginExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Executes the plugin logic against the request/response context. Read more
Auto Trait Implementations§
impl Freeze for LimitConnPlugin
impl !RefUnwindSafe for LimitConnPlugin
impl Send for LimitConnPlugin
impl Sync for LimitConnPlugin
impl Unpin for LimitConnPlugin
impl UnsafeUnpin for LimitConnPlugin
impl !UnwindSafe for LimitConnPlugin
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more