Skip to main content

SessionKeyExtractor

Trait SessionKeyExtractor 

Source
pub trait SessionKeyExtractor {
    // Required method
    fn get_metadata(&self, key: &str) -> Option<String>;

    // Provided methods
    fn list_metadata_keys(&self) -> Vec<String> { ... }
    fn get_all_metadata(&self) -> HashMap<String, String> { ... }
}
Expand description

Trait for extracting metadata from messages for session key generation.

This trait provides a completely generic interface for messages to expose metadata that can be used to generate session keys. It makes no assumptions about the message structure or domain.

§Design

The trait uses a key-value interface where messages expose named metadata fields. Session key generators query for the metadata they need.

§Example

use queue_runtime::sessions::SessionKeyExtractor;

struct MyMessage {
    user_id: String,
    resource_id: String,
}

impl SessionKeyExtractor for MyMessage {
    fn get_metadata(&self, key: &str) -> Option<String> {
        match key {
            "user_id" => Some(self.user_id.clone()),
            "resource_id" => Some(self.resource_id.clone()),
            _ => None,
        }
    }

    fn list_metadata_keys(&self) -> Vec<String> {
        vec!["user_id".to_string(), "resource_id".to_string()]
    }
}

Required Methods§

Source

fn get_metadata(&self, key: &str) -> Option<String>

Get a metadata value by key.

Returns None if the key doesn’t exist or has no value for this message.

§Arguments
  • key - The metadata key to retrieve
§Returns

Optional string value for the requested key

Provided Methods§

Source

fn list_metadata_keys(&self) -> Vec<String>

List all available metadata keys for this message.

This is useful for debugging and introspection. Default implementation returns an empty list.

§Returns

Vector of available metadata key names

Source

fn get_all_metadata(&self) -> HashMap<String, String>

Get all metadata as a map (optional, for bulk operations).

Default implementation iterates over list_metadata_keys() and calls get_metadata() for each key.

§Returns

HashMap of all available metadata

Implementors§