use crate::{
EventBus,
EventBusResult,
EventEnvelope,
PublishOptions,
StagedEvent,
StagedEventEnvelope,
TransactionalPublisher,
};
pub trait TransactionalEventBus: EventBus {
type Publisher: TransactionalPublisher;
fn create_transactional_publisher(&self) -> EventBusResult<Self::Publisher>;
fn publish_batch_atomically<T>(
&self,
envelopes: Vec<EventEnvelope<T>>,
options: PublishOptions<T>,
) -> EventBusResult<()>
where
T: Clone + Send + Sync + 'static,
{
let staged = envelopes
.into_iter()
.map(|envelope| {
Box::new(StagedEventEnvelope::new(envelope, options.clone()))
as Box<dyn StagedEvent>
})
.collect::<Vec<_>>();
self.publish_batch_atomically_staged(staged)
}
fn publish_batch_atomically_staged(
&self,
events: Vec<Box<dyn StagedEvent>>,
) -> EventBusResult<()>;
}