pub struct RedisEventBus { /* private fields */ }Expand description
Redis-backed transient event publisher and reconnecting subscriber.
Implementations§
Source§impl RedisEventBus
impl RedisEventBus
Sourcepub fn from_url(
url: &str,
topic: impl Into<String>,
) -> Result<Self, RedisEventBusError>
pub fn from_url( url: &str, topic: impl Into<String>, ) -> Result<Self, RedisEventBusError>
Creates a bus from a Redis URL and logical topic.
§Errors
Returns an error when the topic is blank or the Redis client rejects url.
Sourcepub fn from_credentials(
base_url: &str,
username: Option<&str>,
password: Option<&str>,
topic: impl Into<String>,
) -> Result<Self, RedisEventBusError>
pub fn from_credentials( base_url: &str, username: Option<&str>, password: Option<&str>, topic: impl Into<String>, ) -> Result<Self, RedisEventBusError>
Creates a bus from a base Redis URL and raw credentials.
The base URL must not contain userinfo. username = None with a password creates the
password-only URL form used by Redis deployments without ACL usernames.
§Errors
Returns an error when the topic is blank, the base URL or credential combination is invalid, or the Redis client rejects the resulting URL.
Sourcepub fn from_client(client: Client, topic: impl Into<String>) -> Self
pub fn from_client(client: Client, topic: impl Into<String>) -> Self
Creates a bus from an existing Redis client.
Sourcepub fn with_reconnect_policy(self, policy: RedisEventReconnectPolicy) -> Self
pub fn with_reconnect_policy(self, policy: RedisEventReconnectPolicy) -> Self
Overrides the reconnect policy.
Sourcepub async fn publish(
&self,
payload: impl Into<String>,
) -> Result<(), RedisEventBusError>
pub async fn publish( &self, payload: impl Into<String>, ) -> Result<(), RedisEventBusError>
Publishes one opaque payload. Payload interpretation belongs to the product layer.
§Errors
Returns an error when a Redis connection cannot be opened or the publish command fails.
Sourcepub async fn subscribe(
&self,
) -> Result<RedisEventSubscription, RedisEventBusError>
pub async fn subscribe( &self, ) -> Result<RedisEventSubscription, RedisEventBusError>
Opens one Redis subscription attempt.
§Errors
Returns an error when the Pub/Sub connection cannot be opened or the topic subscription command fails.
Sourcepub async fn run_subscription<F, Fut>(
&self,
shutdown: CancellationToken,
observer: Option<&dyn EventConnectionObserver>,
on_payload: F,
)
pub async fn run_subscription<F, Fut>( &self, shutdown: CancellationToken, observer: Option<&dyn EventConnectionObserver>, on_payload: F, )
Runs a reconnecting subscription until shutdown is cancelled.
Malformed Redis payloads are logged and skipped. The callback is responsible for decoding the product payload and deciding whether an event belongs to the current runtime.
Trait Implementations§
Source§impl Clone for RedisEventBus
impl Clone for RedisEventBus
Source§fn clone(&self) -> RedisEventBus
fn clone(&self) -> RedisEventBus
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more