pub struct Consumer { /* private fields */ }
Expand description
Main consumer structure for handling async streams and event dispatching
Implementations§
Source§impl Consumer
impl Consumer
Sourcepub fn new(config: ConsumerTaskConfig) -> Self
pub fn new(config: ConsumerTaskConfig) -> Self
Create a new consumer with the given configuration
Sourcepub async fn register_handler(
&self,
handler: Arc<dyn EventHandler>,
) -> Result<()>
pub async fn register_handler( &self, handler: Arc<dyn EventHandler>, ) -> Result<()>
Register an event handler
Sourcepub async fn unregister_handler(&self, handler_id: &str) -> Result<()>
pub async fn unregister_handler(&self, handler_id: &str) -> Result<()>
Unregister an event handler
Sourcepub async fn get_event_receiver(&self) -> Result<Receiver<JetstreamEvent>>
pub async fn get_event_receiver(&self) -> Result<Receiver<JetstreamEvent>>
Get a broadcast receiver for events
Sourcepub async fn run_background(
&self,
cancellation_token: CancellationToken,
) -> Result<()>
pub async fn run_background( &self, cancellation_token: CancellationToken, ) -> Result<()>
Run the consumer in the background
§Example
use atproto_jetstream::{Consumer, ConsumerTaskConfig, CancellationToken};
let config = ConsumerTaskConfig {
user_agent: "my-app/1.0".to_string(),
compression: false,
zstd_dictionary_location: String::new(),
jetstream_hostname: "jetstream1.us-east.bsky.network".to_string(),
collections: vec!["app.bsky.feed.post".to_string()],
dids: vec![], // Subscribe to all DIDs
max_message_size_bytes: None, // No limit
cursor: None, // Live-tail from current time
require_hello: true, // Wait for initial options update
};
let consumer = Consumer::new(config);
let cancellation_token = CancellationToken::new();
// To cancel the consumer later:
// cancellation_token.cancel();
consumer.run_background(cancellation_token).await?;
Auto Trait Implementations§
impl Freeze for Consumer
impl !RefUnwindSafe for Consumer
impl Send for Consumer
impl Sync for Consumer
impl Unpin for Consumer
impl !UnwindSafe for Consumer
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