Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }

Implementations§

Source§

impl Client

Source

pub fn consume_with<H>( &self, topic: &str, options: &ConsumeOptions, handler: H, ) -> Result<usize, ConsumeError>
where H: FnMut(&mut Delivery<'_, ()>) -> Result<(), HandlerError>,

Reads from the queue and calls handler for each message (see the module). Returns how many were handled. If handler returns Err, the message is not deleted and the error propagates.

Source§

impl Client

Source

pub fn new(config: Config) -> Result<Client, Error>

Source

pub fn with_transport( config: Config, transport: Box<dyn Transport>, sleeper: Arc<dyn Fn(Duration) + Send + Sync>, ) -> Result<Client, Error>

To swap the network stack (and, in tests, the wait between attempts).

Source

pub fn config(&self) -> &Config

Source

pub fn call(&self, call: &Call) -> Result<Reply, Error>

Makes the call, retrying only what the contract says to retry (section 18.4): 429 and 503 (waiting for the Retry-After, or 1 s, 2 s, 4 s), 502 and 504 only with retry_gateway, and a network failure before sending. Never a 4xx (except 429), nor a failure after sending the body, nor a timeout.

Source§

impl Client

Source

pub fn create_topic(&self, request: &TopicRequest) -> Result<Topic, Error>

POST /topics.

Source

pub fn get_topic(&self, name: &str) -> Result<Topic, Error>

GET /topics/{topic}.

Source

pub fn list_topics( &self, limit: Option<u32>, cursor: Option<&str>, name: Option<&str>, ) -> Result<Page<Topic>, Error>

GET /topics. Parameters that are None do not go in the query.

Source

pub fn list_all_topics(&self, name: Option<&str>) -> Result<Vec<Topic>, Error>

All topics, page by page.

Source

pub fn update_topic( &self, name: &str, update: &TopicUpdate, ) -> Result<Topic, Error>

PATCH /topics/{topic}.

Source

pub fn delete_topic(&self, name: &str) -> Result<(), Error>

DELETE /topics/{topic}.

Source

pub fn publish( &self, topic: &str, body: &[u8], options: &PublishOptions, ) -> Result<PublishResponse, Error>

POST /topics/{topic}/messages. The body goes as bytes, without validation.

Source

pub fn publish_json( &self, topic: &str, json_text: &str, ) -> Result<PublishResponse, Error>

Source

pub fn publish_text( &self, topic: &str, text: &str, ) -> Result<PublishResponse, Error>

Source

pub fn consume( &self, topic: &str, options: &ConsumeOptions, ) -> Result<Vec<Message>, Error>

GET /topics/{topic}/messages. The read time is waitTime + 10 s, not the requestTimeout.

Source

pub fn consume_call(&self, topic: &str, options: &ConsumeOptions) -> Call

Source

pub fn ack( &self, topic: &str, message_id: &str, receipt_token: &str, ) -> Result<(), Error>

DELETE /topics/{topic}/messages/{id}?receiptToken=.

Source

pub fn change_visibility( &self, topic: &str, message_id: &str, receipt_token: &str, seconds: u32, ) -> Result<VisibilityResponse, Error>

PUT /topics/{topic}/messages/{id}/visibility?receiptToken=.

Source

pub fn subscribe<H, S>( &self, topic: &str, options: &ConsumeOptions, stop: S, handler: H, ) -> Result<(), Error>
where H: FnMut(&Message) -> Result<(), Box<dyn Error>>, S: FnMut() -> bool,

The consume loop (D71.1): long polling (waitTime 20 and one message at a time, if not set), calls the handler and acknowledges by itself only if it returns Ok. stop is checked before each consume and after each message; returning true, the loop ends. A server error while consuming or acknowledging propagates.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.