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 stream = client
.subscribe("projects/my-project/subscriptions/my-subscription")
.build();
while let Some((m, h)) = stream.next().await.transpose()? {
println!("Received message m={m:?}");
h.ack();
}§Ordered Delivery
The subscriber returns messages in order if ordered delivery is enabled on the subscription. The client provides the same guarantees as the service.
For more details on how the service works, see:
§Exactly-once Delivery
The subscriber does not support exactly-once delivery yet.
If you subscribe to a subscription with exactly-once delivery enabled, the subscriber will deliver you messages with at-least-once semantics. There is no way for you to confirm the acknowledgements from the server. Messages may get redelivered.
Adding support for exactly-once delivery is planned. You can track the progress in google-cloud-rust#3964.
§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 subscribe<T>(&self, subscription: T) -> Subscribe
pub fn subscribe<T>(&self, subscription: T) -> Subscribe
Receive messages from a subscription.
The subscription is the full name, in the format of
projects/*/subscriptions/*.
§Example
let mut stream = client
.subscribe("projects/my-project/subscriptions/my-subscription")
.build();
while let Some((m, h)) = stream.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
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
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 UnsafeUnpin 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
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