pub struct Topic {
pub name: String,
pub partitions: Vec<Partition>,
pub subscribers: Vec<Subscriber>,
}Fields§
§name: String§partitions: Vec<Partition>§subscribers: Vec<Subscriber>Implementations§
Source§impl Topic
impl Topic
Sourcepub fn new(name: &str, num_partitions: usize, replication_factor: usize) -> Self
pub fn new(name: &str, num_partitions: usize, replication_factor: usize) -> Self
Creates a new topic.
§Arguments
name- The name of the topic.num_partitions- The number of partitions for the topic.replication_factor- The replication factor for the topic.
§Examples
use pilgrimage::broker::topic::Topic;
let topic = Topic::new("test_topic", 3, 2);
assert_eq!(topic.name, "test_topic");
assert_eq!(topic.partitions.len(), 3);
assert_eq!(topic.partitions[0].replicas.len(), 2);Sourcepub fn add_subscriber(&mut self, subscriber: Subscriber)
pub fn add_subscriber(&mut self, subscriber: Subscriber)
Adds a subscriber to the topic.
§Arguments
subscriber- The subscriber to add.
§Examples
use pilgrimage::broker::topic::Topic;
use pilgrimage::subscriber::types::Subscriber;
let mut topic = Topic::new("test_topic", 3, 2);
let subscriber = Subscriber::new("sub1", Box::new(|msg: String| {
println!("Received message: {}", msg);
}));
topic.add_subscriber(subscriber);
assert_eq!(topic.subscribers.len(), 1);pub fn remove_subscriber(&mut self, _subscriber_id: &str)
Sourcepub fn publish(
&mut self,
message: String,
partition_key: Option<&str>,
) -> Result<usize, BrokerError>
pub fn publish( &mut self, message: String, partition_key: Option<&str>, ) -> Result<usize, BrokerError>
Publishes a message to the topic.
§Arguments
message- The message to publish.partition_key- An optional key for partitioning.
§Examples
use pilgrimage::broker::topic::Topic;
use pilgrimage::broker::error::BrokerError;
let mut topic = Topic::new("test_topic", 3, 2);
let result = topic.publish("test_message".to_string(), None);
assert!(result.is_ok());Trait Implementations§
Auto Trait Implementations§
impl Freeze for Topic
impl !RefUnwindSafe for Topic
impl Send for Topic
impl Sync for Topic
impl Unpin for Topic
impl !UnwindSafe for Topic
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§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