|
11 | 11 | //! - **Multiple Delivery Strategies**: Configure how messages are delivered to handle different reliability needs.
|
12 | 12 | //! - **Automatic Cleanup**: Dead actor references are automatically removed from subscription lists.
|
13 | 13 | //!
|
14 |
| -//! # When to use Broker vs PubSub |
15 |
| -//! |
16 |
| -//! The `broker` module provides a more sophisticated routing system compared to the simpler `pubsub` module: |
17 |
| -//! |
18 |
| -//! - Use **Broker** when you need hierarchical topics, pattern-based subscriptions, or different delivery strategies. |
19 |
| -//! - Use **PubSub** when you only need simple broadcast to all listeners with optional type-based filtering. |
20 |
| -//! |
21 | 14 | //! # Example
|
22 | 15 | //!
|
23 | 16 | //! ```
|
24 | 17 | //! use kameo::Actor;
|
25 |
| -//! use kameo_actors::broker::{Broker, Subscribe, Publish, DeliveryStrategy}; |
| 18 | +//! use kameo_actors::broker::{Broker, Subscribe, Publish}; |
| 19 | +//! use kameo_actors::DeliveryStrategy; |
26 | 20 | //! use glob::Pattern;
|
27 | 21 | //! # use std::time::Duration;
|
28 | 22 | //! # use kameo::message::{Context, Message};
|
|
62 | 56 | //! # });
|
63 | 57 | //! ```
|
64 | 58 |
|
65 |
| -use std::{collections::HashMap, time::Duration}; |
| 59 | +use std::collections::HashMap; |
66 | 60 |
|
67 | 61 | use glob::{MatchOptions, Pattern};
|
68 | 62 | use kameo::prelude::*;
|
69 | 63 |
|
| 64 | +use crate::DeliveryStrategy; |
| 65 | + |
70 | 66 | /// A generic topic-based message broker for the actor system.
|
71 | 67 | ///
|
72 | 68 | /// The broker manages subscriptions to topics and delivers messages published
|
@@ -268,42 +264,3 @@ impl<M: Clone + Send + 'static> Message<Publish<M>> for Broker<M> {
|
268 | 264 | }
|
269 | 265 | }
|
270 | 266 | }
|
271 |
| - |
272 |
| -/// Strategies for delivering messages to subscribers. |
273 |
| -/// |
274 |
| -/// Different strategies provide different trade-offs between reliability, |
275 |
| -/// performance, and resource usage. |
276 |
| -#[derive(Clone, Copy, Debug, Default, Hash, PartialEq, Eq)] |
277 |
| -pub enum DeliveryStrategy { |
278 |
| - /// Block until all messages are delivered. |
279 |
| - /// |
280 |
| - /// This strategy ensures reliable delivery but may cause the broker |
281 |
| - /// to block if any recipient's mailbox is full. |
282 |
| - Guaranteed, |
283 |
| - |
284 |
| - /// Skip actors with full mailboxes. |
285 |
| - /// |
286 |
| - /// This strategy attempts to deliver messages immediately without blocking, |
287 |
| - /// but will skip recipients whose mailboxes are full. |
288 |
| - #[default] |
289 |
| - BestEffort, |
290 |
| - |
291 |
| - /// Try to deliver with timeout (blocks the publisher). |
292 |
| - /// |
293 |
| - /// This strategy waits for each recipient to accept the message, but only |
294 |
| - /// up to the specified timeout duration. The broker will block during delivery. |
295 |
| - TimedDelivery(Duration), |
296 |
| - |
297 |
| - /// Spawn a task for each delivery (non-blocking). |
298 |
| - /// |
299 |
| - /// This strategy spawns a separate task for each message delivery, |
300 |
| - /// allowing the broker to continue processing other messages immediately. |
301 |
| - /// Tasks will retry indefinitely if mailboxes are full. |
302 |
| - Spawned, |
303 |
| - |
304 |
| - /// Spawn a task with timeout for each delivery. |
305 |
| - /// |
306 |
| - /// This strategy combines the benefits of spawned delivery with a timeout, |
307 |
| - /// ensuring that delivery attempts don't consume resources indefinitely. |
308 |
| - SpawnedWithTimeout(Duration), |
309 |
| -} |
0 commit comments