pub struct SessionAffinity { /* private fields */ }Expand description
Mapping of a session to its assigned consumer.
Session affinity ensures that all messages for a given session are processed by the same consumer, maintaining ordering and state consistency.
§Examples
use queue_runtime::sessions::SessionAffinity;
use queue_runtime::message::SessionId;
use std::time::{SystemTime, Duration};
let session_id = SessionId::new("order-789".to_string()).unwrap();
let affinity = SessionAffinity::new(
session_id.clone(),
"worker-3".to_string(),
Duration::from_secs(300)
);
assert_eq!(affinity.session_id(), &session_id);
assert_eq!(affinity.consumer_id(), "worker-3");
assert!(!affinity.is_expired());Implementations§
Source§impl SessionAffinity
impl SessionAffinity
Sourcepub fn new(
session_id: SessionId,
consumer_id: String,
affinity_duration: Duration,
) -> Self
pub fn new( session_id: SessionId, consumer_id: String, affinity_duration: Duration, ) -> Self
Sourcepub fn session_id(&self) -> &SessionId
pub fn session_id(&self) -> &SessionId
Get the session ID.
Sourcepub fn consumer_id(&self) -> &str
pub fn consumer_id(&self) -> &str
Get the consumer ID.
Sourcepub fn affinity_duration(&self) -> Duration
pub fn affinity_duration(&self) -> Duration
Get the affinity duration.
Sourcepub fn assigned_at(&self) -> Instant
pub fn assigned_at(&self) -> Instant
Get when the affinity was assigned.
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Sourcepub fn time_remaining(&self) -> Duration
pub fn time_remaining(&self) -> Duration
Trait Implementations§
Source§impl Clone for SessionAffinity
impl Clone for SessionAffinity
Source§fn clone(&self) -> SessionAffinity
fn clone(&self) -> SessionAffinity
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for SessionAffinity
impl RefUnwindSafe for SessionAffinity
impl Send for SessionAffinity
impl Sync for SessionAffinity
impl Unpin for SessionAffinity
impl UnsafeUnpin for SessionAffinity
impl UnwindSafe for SessionAffinity
Blanket Implementations§
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