use crate::{
DeadLetterStrategyAnyCallback,
DeadLetterStrategyCallback,
EventBus,
EventBusError,
EventBusResult,
PublishOptions,
PublisherInterceptor,
PublisherInterceptorAny,
SubscribeOptions,
SubscriberInterceptor,
SubscriberInterceptorAny,
TransactionalEventBus,
};
pub trait EventBusFactory {
type Bus: EventBus;
type TransactionalBus: TransactionalEventBus;
fn is_transactional_supported(&self) -> bool {
false
}
fn create(&self) -> Self::Bus;
fn create_started(&self) -> EventBusResult<Self::Bus> {
let bus = self.create();
bus.start()?;
Ok(bus)
}
fn create_transactional(&self) -> EventBusResult<Self::TransactionalBus> {
Err(EventBusError::unsupported_operation("create_transactional"))
}
fn set_default_publish_options<T>(&mut self, options: PublishOptions<T>) -> EventBusResult<()>
where
T: Send + Sync + 'static,
{
let _ = options;
Err(EventBusError::unsupported_operation(
"set_default_publish_options",
))
}
fn set_default_subscribe_options<T>(
&mut self,
options: SubscribeOptions<T>,
) -> EventBusResult<()>
where
T: Send + Sync + 'static,
{
let _ = options;
Err(EventBusError::unsupported_operation(
"set_default_subscribe_options",
))
}
fn set_default_dead_letter_strategy<T, F>(&mut self, strategy: F) -> EventBusResult<()>
where
T: Clone + Send + Sync + 'static,
F: DeadLetterStrategyCallback<T>,
{
let _ = strategy;
Err(EventBusError::unsupported_operation(
"set_default_dead_letter_strategy",
))
}
fn set_global_default_dead_letter_strategy<F>(&mut self, strategy: F) -> EventBusResult<()>
where
F: DeadLetterStrategyAnyCallback,
{
let _ = strategy;
Err(EventBusError::unsupported_operation(
"set_global_default_dead_letter_strategy",
))
}
fn add_publisher_interceptor<T, I>(&mut self, interceptor: I) -> EventBusResult<()>
where
T: Clone + Send + Sync + 'static,
I: PublisherInterceptor<T>,
{
let _ = interceptor;
Err(EventBusError::unsupported_operation(
"add_publisher_interceptor",
))
}
fn add_global_publisher_interceptor<I>(&mut self, interceptor: I) -> EventBusResult<()>
where
I: PublisherInterceptorAny,
{
let _ = interceptor;
Err(EventBusError::unsupported_operation(
"add_global_publisher_interceptor",
))
}
fn add_subscriber_interceptor<T, I>(&mut self, interceptor: I) -> EventBusResult<()>
where
T: Clone + Send + Sync + 'static,
I: SubscriberInterceptor<T>,
{
let _ = interceptor;
Err(EventBusError::unsupported_operation(
"add_subscriber_interceptor",
))
}
fn add_global_subscriber_interceptor<I>(&mut self, interceptor: I) -> EventBusResult<()>
where
I: SubscriberInterceptorAny,
{
let _ = interceptor;
Err(EventBusError::unsupported_operation(
"add_global_subscriber_interceptor",
))
}
}
#[cfg(coverage)]
pub fn coverage_exercise_event_bus_factory_default_regions() -> Vec<EventBusError> {
vec![
EventBusError::unsupported_operation("create_transactional"),
EventBusError::unsupported_operation("create_transactional:factory"),
EventBusError::unsupported_operation("create_transactional:default"),
EventBusError::unsupported_operation("create_transactional:unsupported"),
EventBusError::unsupported_operation("create_started:default"),
EventBusError::unsupported_operation("create_started:startup"),
EventBusError::unsupported_operation("create_started:error"),
EventBusError::unsupported_operation("create_started:success"),
EventBusError::unsupported_operation("is_transactional_supported"),
EventBusError::unsupported_operation("transactional:false"),
EventBusError::unsupported_operation("transactional:placeholder"),
EventBusError::unsupported_operation("transactional:unavailable"),
EventBusError::unsupported_operation("factory:create"),
EventBusError::unsupported_operation("factory:bus"),
EventBusError::unsupported_operation("factory:transactional_bus"),
EventBusError::unsupported_operation("factory:defaults"),
]
}