pub struct LimitConnPlugin {
role: Role,
conn: i64,
burst: i64,
key: String,
key_tpl: Template,
key_constant: bool,
rejected_code: u16,
rejected_msg: Option<Template>,
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_tpl: TemplatePre-parsed key: supports {{namespace.path}} references and legacy
$var interpolation (see Template::render_with_legacy). Only used
when key_constant is false.
key_constant: boolWhen true, key is used verbatim rather than interpolated.
rejected_code: u16Status returned when the limit is exceeded.
rejected_msg: Option<Template>Optional human-readable rejection message (JSON {"error_msg": ...}).
Supports {{namespace.path}} references (no legacy $var
interpolation — this field never supported it, so this sweep must not
start).
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, rendered per request — supports{{namespace.path}}references plus legacy$varinterpolation (seecrate::vars::template::Template::render_with_legacy) unlesskey_type: constant. 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. Supports{{namespace.path}}references.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
Source§fn execute<'life0, 'async_trait>(
&'life0 self,
ctx: Context,
) -> Pin<Box<dyn Future<Output = Result<PluginOutput, PluginExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn execute<'life0, 'async_trait>(
&'life0 self,
ctx: Context,
) -> Pin<Box<dyn Future<Output = Result<PluginOutput, PluginExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn reads_response_body(&self) -> bool
fn reads_response_body(&self) -> bool
context.response.body. Read moreSource§fn cache_target(&self) -> Option<CacheTarget>
fn cache_target(&self) -> Option<CacheTarget>
proxy-cache half. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for LimitConnPlugin
impl !UnwindSafe for LimitConnPlugin
impl Freeze for LimitConnPlugin
impl Send for LimitConnPlugin
impl Sync for LimitConnPlugin
impl Unpin for LimitConnPlugin
impl UnsafeUnpin 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
§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>
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>
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