pub struct PubSubHandler<A: Authenticator> {
pub schema_cache: SchemaCache,
/* private fields */
}Expand description
Entry point for all Salesforce Pub/Sub operations.
Obtained by calling PubSubHandler::connect with a Session and PubSubConfig.
The handler is cheaply cloneable — clones share the same gRPC channel and schema cache.
Fields§
§schema_cache: SchemaCacheShared schema cache, populated during subscribe/publish operations in later tasks.
Implementations§
Source§impl<A: Authenticator> PubSubHandler<A>
impl<A: Authenticator> PubSubHandler<A>
Sourcepub async fn connect(
session: Arc<Session<A>>,
config: PubSubConfig,
) -> Result<Self>
pub async fn connect( session: Arc<Session<A>>, config: PubSubConfig, ) -> Result<Self>
Connect to the Pub/Sub gRPC endpoint and return a handler.
Validates configuration and establishes the gRPC channel. This is async because channel creation involves a DNS lookup and TLS handshake.
§Errors
Returns PubSubError::Config if batch_size is out of range (1–100).
Returns PubSubError::Connect if the gRPC channel cannot be established.
Sourcepub async fn get_topic(&self, topic_name: &str) -> Result<TopicInfo>
pub async fn get_topic(&self, topic_name: &str) -> Result<TopicInfo>
Fetch metadata about a Pub/Sub topic.
§Errors
Returns PubSubError::Transport if the gRPC call fails.
Sourcepub async fn get_schema(&self, schema_id: &str) -> Result<SchemaInfo>
pub async fn get_schema(&self, schema_id: &str) -> Result<SchemaInfo>
Fetch an Avro schema by its ID.
Results are not automatically cached here — call SchemaCache::parse_and_insert
with the returned schema_json to cache it.
§Errors
Returns PubSubError::Transport if the gRPC call fails (including schema not found).
Source§impl<A: Authenticator + Send + Sync + 'static> PubSubHandler<A>
impl<A: Authenticator + Send + Sync + 'static> PubSubHandler<A>
Sourcepub async fn publish<T: Serialize + Send>(
&self,
topic: &str,
events: Vec<T>,
) -> Result<PublishResponse>
pub async fn publish<T: Serialize + Send>( &self, topic: &str, events: Vec<T>, ) -> Result<PublishResponse>
Publish events to a topic via the unary Publish RPC.
Automatically resolves the Avro schema for topic by calling GetTopic
to obtain the schema ID, then fetching the schema via GetSchema if it
is not already cached.
§Errors
Returns PubSubError::Transport if the GetTopic or GetSchema RPC fails.
Returns PubSubError::Avro if encoding fails.
Sourcepub async fn subscribe(
&self,
topic: &str,
replay: ReplayPreset,
) -> Result<Pin<Box<dyn Stream<Item = Result<PubSubEvent<Value>>> + Send>>>
pub async fn subscribe( &self, topic: &str, replay: ReplayPreset, ) -> Result<Pin<Box<dyn Stream<Item = Result<PubSubEvent<Value>>> + Send>>>
Subscribe to a topic, yielding decoded events as serde_json::Value.
The returned stream emits PubSubEvent<Value> items. Use ReplayPreset
to control where playback starts.
§Errors
Returns PubSubError::Config if the tenant ID cannot be fetched from userinfo.
Sourcepub async fn subscribe_typed<T>(
&self,
topic: &str,
replay: ReplayPreset,
) -> Result<Pin<Box<dyn Stream<Item = Result<PubSubEvent<T>>> + Send>>>where
T: DeserializeOwned + Send + 'static,
pub async fn subscribe_typed<T>(
&self,
topic: &str,
replay: ReplayPreset,
) -> Result<Pin<Box<dyn Stream<Item = Result<PubSubEvent<T>>> + Send>>>where
T: DeserializeOwned + Send + 'static,
Subscribe to a topic, yielding typed events deserialized as T.
§Errors
Returns PubSubError::Config if the tenant ID cannot be fetched from userinfo.
Sourcepub async fn publish_stream<T: Serialize + Send + 'static>(
&self,
topic: &str,
) -> Result<PublishSink<T>>
pub async fn publish_stream<T: Serialize + Send + 'static>( &self, topic: &str, ) -> Result<PublishSink<T>>
Open a bidirectional streaming PublishStream RPC and return a PublishSink.
The returned sink allows callers to send multiple batches of events to
topic without the per-call overhead of the unary Self::publish RPC.
The server streams back PublishResponse acknowledgements, which are
accessible via PublishSink::responses.
§Errors
PubSubError::Configif the tenant ID cannot be fetched.PubSubError::Transportif the gRPC stream cannot be opened.
Trait Implementations§
Source§impl<A: Clone + Authenticator> Clone for PubSubHandler<A>
impl<A: Clone + Authenticator> Clone for PubSubHandler<A>
Source§fn clone(&self) -> PubSubHandler<A>
fn clone(&self) -> PubSubHandler<A>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<A> Freeze for PubSubHandler<A>
impl<A> !RefUnwindSafe for PubSubHandler<A>
impl<A> Send for PubSubHandler<A>
impl<A> Sync for PubSubHandler<A>
impl<A> Unpin for PubSubHandler<A>
impl<A> UnsafeUnpin for PubSubHandler<A>
impl<A> !UnwindSafe for PubSubHandler<A>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request