pub struct PulsarTopic { /* private fields */ }Expand description
A validated Pulsar topic name.
§Examples
use ruststream_pulsar::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Outgoing, Serialize)]
struct Order {
tenant: String,
id: u64,
}
#[derive(OutSlot)]
#[publishes(Order)]
struct TenantOrders;
/// Fans orders out to their tenant's own topic. The tenant comes off the wire, so its topic
/// is parsed, and an order naming a tenant Pulsar would refuse is dropped here.
#[subscriber(PulsarSubscription::new("orders", "router"))]
async fn route(order: &Order, Out(tenants): Out<impl Publisher, TenantOrders>) -> HandlerOutcome {
let Ok(topic) = PulsarTopic::parse(&format!("{}/orders/created", order.tenant)) else {
return HandlerOutcome::drop();
};
match tenants.message(order).to(topic.as_str()).publish().await {
Ok(()) => HandlerOutcome::ack(),
Err(_) => HandlerOutcome::retry(),
}
}Implementations§
Source§impl PulsarTopic
impl PulsarTopic
Sourcepub fn persistent(tenant: &str, namespace: &str, topic: &str) -> Self
pub fn persistent(tenant: &str, namespace: &str, topic: &str) -> Self
Sourcepub fn non_persistent(tenant: &str, namespace: &str, topic: &str) -> Self
pub fn non_persistent(tenant: &str, namespace: &str, topic: &str) -> Self
Sourcepub fn parse(name: &str) -> Result<Self, PulsarError>
pub fn parse(name: &str) -> Result<Self, PulsarError>
Parses a fully qualified name (persistent://t/ns/topic), a tenant/namespace/topic
triple (defaulting to persistent), or a bare topic name (defaulting to
persistent://public/default/).
§Errors
Returns PulsarError::Invalid when the shape or a component is invalid.
Sourcepub fn persistence(&self) -> &str
pub fn persistence(&self) -> &str
The persistence of the topic: "persistent" or "non-persistent".
§Examples
#[ruststream::app]
fn app() -> impl App {
let orders = orders();
// Spent orders land beside the topic they came from, as durable as it is.
let dead_letters = format!(
"{}://{}/{}/{}-dlq",
orders.persistence(),
orders.tenant(),
orders.namespace(),
orders.name(),
);
RustStream::new(AppInfo::new("orders", "0.1.0")).with_broker(
PulsarBroker::new("pulsar://localhost:6650"),
|b| {
b.include(handle).max_attempts(nonzero!(5)).dead_letter(dead_letters);
},
)
}Sourcepub fn tenant(&self) -> &str
pub fn tenant(&self) -> &str
The tenant the topic belongs to; public for a bare name.
§Examples
#[ruststream::app]
fn app() -> impl App {
let orders = orders();
// Every service of the tenant parks its spent messages in one namespace.
let dead_letters = PulsarTopic::persistent(orders.tenant(), "dead-letters", orders.name())
.as_str()
.to_owned();
RustStream::new(AppInfo::new("orders", "0.1.0")).with_broker(
PulsarBroker::new("pulsar://localhost:6650"),
|b| {
b.include(handle).max_attempts(nonzero!(5)).dead_letter(dead_letters);
},
)
}Sourcepub fn namespace(&self) -> &str
pub fn namespace(&self) -> &str
The namespace the topic lives in; default for a bare name.
§Examples
#[ruststream::app]
fn app() -> impl App {
let orders = orders();
// The namespace keeps one dead-letter topic for all of its topics.
let dead_letters = PulsarTopic::persistent(orders.tenant(), orders.namespace(), "dlq")
.as_str()
.to_owned();
RustStream::new(AppInfo::new("orders", "0.1.0")).with_broker(
PulsarBroker::new("pulsar://localhost:6650"),
|b| {
b.include(handle).max_attempts(nonzero!(5)).dead_letter(dead_letters);
},
)
}Sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
The topic’s own name, without tenant, namespace or scheme.
§Examples
#[ruststream::app]
fn app() -> impl App {
let orders = orders();
// Spent orders go to a topic named after the one they came from.
let dead_letters = format!("{}-dlq", orders.name());
RustStream::new(AppInfo::new("orders", "0.1.0")).with_broker(
PulsarBroker::new("pulsar://localhost:6650"),
|b| {
b.include(handle).max_attempts(nonzero!(5)).dead_letter(dead_letters);
},
)
}Trait Implementations§
Source§impl Clone for PulsarTopic
impl Clone for PulsarTopic
Source§impl Debug for PulsarTopic
impl Debug for PulsarTopic
Source§impl Display for PulsarTopic
impl Display for PulsarTopic
impl Eq for PulsarTopic
Source§impl Hash for PulsarTopic
impl Hash for PulsarTopic
Source§impl PartialEq for PulsarTopic
impl PartialEq for PulsarTopic
impl StructuralPartialEq for PulsarTopic
Auto Trait Implementations§
impl Freeze for PulsarTopic
impl RefUnwindSafe for PulsarTopic
impl Send for PulsarTopic
impl Sync for PulsarTopic
impl Unpin for PulsarTopic
impl UnsafeUnpin for PulsarTopic
impl UnwindSafe for PulsarTopic
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more