Expand description
§PSMatcher
A pub/sub matcher algorithm implementation that efficiently matches events against subscriptions. The algorithm pre-processes subscriptions into a matching tree for optimized event matching.
§Overview
This crate provides a pub/sub matching system where:
- Subscriptions are conjunctions of elementary predicates
- Events must have at least one string attribute called “topic”
- The matching tree is built during pre-processing for efficient matching
§Example
use psmatcher::{Matcher, Subscription, ElementaryPredicate, ElementaryTest};
use psmatcher::event_types::{DefaultEvent, AttributeValue};
// Create a matcher
let mut matcher = Matcher::new();
// Create a subscription for weather updates in San Francisco
let subscription = Subscription::new("weather-sf")
.with_predicate(ElementaryPredicate::new(
ElementaryTest::Equals {
attribute: "topic".to_string(),
value: AttributeValue::String("weather".to_string()),
},
false,
))
.with_predicate(ElementaryPredicate::new(
ElementaryTest::Equals {
attribute: "city".to_string(),
value: AttributeValue::String("San Francisco".to_string()),
},
false,
));
// Add the subscription to the matcher
matcher.add_subscription(subscription);
// Create a subscription using regex pattern matching
let regex_subscription = Subscription::new("california-cities")
.with_predicate(ElementaryPredicate::new(
ElementaryTest::regex("topic".to_string(), "weather|forecast").unwrap(),
false,
))
.with_predicate(ElementaryPredicate::new(
ElementaryTest::regex("city".to_string(), "San (Francisco|Jose|Diego)").unwrap(),
false,
));
// Add the regex subscription to the matcher
matcher.add_subscription(regex_subscription);
// Create an event
let event = DefaultEvent::new("weather")
.with_attribute("city", AttributeValue::String("San Francisco".to_string()))
.with_attribute("temperature", AttributeValue::Float(72.5));
// Match the event against subscriptions
let matches = matcher.match_event(&event).unwrap();
// Check if our subscriptions matched
assert!(matches.contains("weather-sf"));
assert!(matches.contains("california-cities"));For more examples and detailed documentation, see the README module.
Modules§
- collections
- Deterministic collection aliases for simulation testing.
- event_
types - helpers
- readme
- README Documentation
- traits
Macros§
- attr_
map - list_
from_ attr_ values - list_
from_ bools - list_
from_ floats - list_
from_ ints - list_
from_ strs - map_
from_ attr_ values
Structs§
- Elementary
Predicate - Represents an elementary predicate, which is the result of an elementary test
- Matcher
- The main matcher API for pub/sub matching
- Matching
Tree - The matching tree for efficient event matching
- Subscription
- A subscription is a conjunction of elementary predicates
Enums§
- Elementary
Test - Represents an elementary test that can be performed on an event attribute
- Matcher
Error - Errors that can occur during pub/sub matching operations