pub struct Client { /* private fields */ }Implementations§
Source§impl Client
impl Client
Sourcepub fn consume_with<H>(
&self,
topic: &str,
options: &ConsumeOptions,
handler: H,
) -> Result<usize, ConsumeError>
pub fn consume_with<H>( &self, topic: &str, options: &ConsumeOptions, handler: H, ) -> Result<usize, ConsumeError>
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
impl Client
pub fn new(config: Config) -> Result<Client, Error>
Sourcepub fn with_transport(
config: Config,
transport: Box<dyn Transport>,
sleeper: Arc<dyn Fn(Duration) + Send + Sync>,
) -> Result<Client, Error>
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).
pub fn config(&self) -> &Config
Sourcepub fn call(&self, call: &Call) -> Result<Reply, Error>
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
impl Client
Sourcepub fn create_topic(&self, request: &TopicRequest) -> Result<Topic, Error>
pub fn create_topic(&self, request: &TopicRequest) -> Result<Topic, Error>
POST /topics.
Sourcepub fn list_topics(
&self,
limit: Option<u32>,
cursor: Option<&str>,
name: Option<&str>,
) -> Result<Page<Topic>, Error>
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.
Sourcepub fn list_all_topics(&self, name: Option<&str>) -> Result<Vec<Topic>, Error>
pub fn list_all_topics(&self, name: Option<&str>) -> Result<Vec<Topic>, Error>
All topics, page by page.
Sourcepub fn update_topic(
&self,
name: &str,
update: &TopicUpdate,
) -> Result<Topic, Error>
pub fn update_topic( &self, name: &str, update: &TopicUpdate, ) -> Result<Topic, Error>
PATCH /topics/{topic}.
Sourcepub fn create_or_update_topic(
&self,
request: &TopicRequest,
recreate: Recreate,
) -> Result<TopicPut, Error>
pub fn create_or_update_topic( &self, request: &TopicRequest, recreate: Recreate, ) -> Result<TopicPut, Error>
PUT /topics/{topic}: brings the topic to the declared state, creating it if it does not exist. What is
left out goes back to the server default (a full replacement, unlike update_topic); request.name is the
topic of the path. Another type, fifo or volatile is 409 topic.immutable-mismatch unless recreate
says otherwise. Repeated after a 503 like the other calls: the route is idempotent.
Sourcepub fn delete_topic_if_empty(&self, name: &str) -> Result<(), Error>
pub fn delete_topic_if_empty(&self, name: &str) -> Result<(), Error>
DELETE /topics/{topic}?ifEmpty=true: removes the queue only if it and its dead-letter hold no message on
any node (409 topic.not-empty otherwise; a distributor holds none).
Sourcepub fn publish(
&self,
topic: &str,
body: &[u8],
options: &PublishOptions,
) -> Result<PublishResponse, Error>
pub fn publish( &self, topic: &str, body: &[u8], options: &PublishOptions, ) -> Result<PublishResponse, Error>
POST /topics/{topic}/messages. The body goes as bytes, without validation.
pub fn publish_json( &self, topic: &str, json_text: &str, ) -> Result<PublishResponse, Error>
pub fn publish_text( &self, topic: &str, text: &str, ) -> Result<PublishResponse, Error>
Sourcepub fn publish_batch(
&self,
topic: &str,
messages: &[BatchMessage],
) -> Result<Vec<BatchResult>, Error>
pub fn publish_batch( &self, topic: &str, messages: &[BatchMessage], ) -> Result<Vec<BatchResult>, Error>
POST /topics/{topic}/messages/batch: publishes many messages in one request (1 to the server’s
api.batch.max-messages, 1000 by default). Each item is answered as its single publication and one that fails
does not undo the others (see BatchResult::is_ok). On a FIFO queue the items of a group are published in
the order of the list. A failure of the network is not retried (it could duplicate).
Sourcepub fn ack_batch(
&self,
topic: &str,
messages: &[Message],
) -> Result<Vec<BatchResult>, Error>
pub fn ack_batch( &self, topic: &str, messages: &[Message], ) -> Result<Vec<BatchResult>, Error>
POST /topics/{topic}/messages/ack: acknowledges many delivered messages in one request. Each item is answered
as its single ack and one that fails does not stop the others.
Sourcepub fn change_visibility_batch(
&self,
topic: &str,
messages: &[Message],
seconds: u32,
) -> Result<Vec<BatchResult>, Error>
pub fn change_visibility_batch( &self, topic: &str, messages: &[Message], seconds: u32, ) -> Result<Vec<BatchResult>, Error>
POST /topics/{topic}/messages/visibility: sets the invisibility of many delivered messages to seconds from
now, in one request.
Sourcepub fn consume(
&self,
topic: &str,
options: &ConsumeOptions,
) -> Result<Vec<Message>, Error>
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.
pub fn consume_call(&self, topic: &str, options: &ConsumeOptions) -> Call
Sourcepub fn ack(
&self,
topic: &str,
message_id: &str,
receipt_token: &str,
) -> Result<(), Error>
pub fn ack( &self, topic: &str, message_id: &str, receipt_token: &str, ) -> Result<(), Error>
DELETE /topics/{topic}/messages/{id}?receiptToken=.
Sourcepub fn change_visibility(
&self,
topic: &str,
message_id: &str,
receipt_token: &str,
seconds: u32,
) -> Result<VisibilityResponse, Error>
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=.
Sourcepub fn subscribe<H, S>(
&self,
topic: &str,
options: &ConsumeOptions,
stop: S,
handler: H,
) -> Result<(), Error>
pub fn subscribe<H, S>( &self, topic: &str, options: &ConsumeOptions, stop: S, handler: H, ) -> Result<(), Error>
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.