pub struct Subscriber { /* private fields */ }Expand description
A Subscriber client for the Cloud Pub/Sub API.
Use this client to receive messages from a pull subscription on a topic.
§Example
let client = Subscriber::builder().build().await?;
let mut session = client
.streaming_pull("projects/my-project/subscriptions/my-subscription")
.start();
while let Some((m, h)) = session.next().await.transpose()? {
println!("Received message m={m:?}");
h.ack();
}§Configuration
To configure a Subscriber use the with_* methods in the type returned by
builder(). The default configuration should work for
most applications. Common configuration changes include:
- with_endpoint(): by default this client uses the global default endpoint
(
https://pubsub.googleapis.com). Applications using regional endpoints or running in restricted networks (e.g. a network configured with Private Google Access with VPC Service Controls) may want to override this default. - with_credentials(): by default this client uses Application Default Credentials. Applications using custom authentication may need to override this default.
§Pooling and Cloning
Subscriber holds a connection pool internally, it is advised to
create one and then reuse it. You do not need to wrap Subscriber in
an Rc or Arc to reuse it, because it already uses an Arc
internally.
Implementations§
Source§impl Subscriber
impl Subscriber
Sourcepub fn builder() -> ClientBuilder
pub fn builder() -> ClientBuilder
Sourcepub fn streaming_pull<T>(&self, subscription: T) -> StreamingPull
pub fn streaming_pull<T>(&self, subscription: T) -> StreamingPull
Receive messages from a subscription.
The subscription is the full name, in the format of
projects/*/subscriptions/*.
§Example
let mut session = client
.streaming_pull("projects/my-project/subscriptions/my-subscription")
.start();
while let Some((m, h)) = session.next().await.transpose()? {
println!("Received message m={m:?}");
h.ack();
}Trait Implementations§
Source§impl Clone for Subscriber
impl Clone for Subscriber
Source§fn clone(&self) -> Subscriber
fn clone(&self) -> Subscriber
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for Subscriber
impl !RefUnwindSafe for Subscriber
impl Send for Subscriber
impl Sync for Subscriber
impl Unpin for Subscriber
impl !UnwindSafe for Subscriber
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
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>
Wrap the input message
T in a tonic::Request