taba-client (Rust)
The Taba Rust connector. Documentation: Connectors, Rust.
Other languages: Português (Brasil) · all languages
- Its own HTTP/1.1 over
std::net::TcpStream(building the request and reading the response are pure functions inhttp), TLS 1.2 or later throughrustlswith the system roots (plus an optional CA of your own) and its own JSON and base64. The only dependencies arerustlsandrustls-native-certs(plusserde, only in the optionalserdefeature). - Thread-safe:
ClientisSend + Sync; a single one serves many. - Call retries of the common contract:
429and503(withRetry-After),502and504only on FIFO, a network failure before sending; never a4xxnor a timeout.
use ;
Consuming with a handler and objects (D140)
The simplest use: publish and consume objects, without serializing or deleting anything by hand. With the serde feature (taba-client = { features = ["serde"] }; without it the connector stays with rustls only):
client.publish_object?;
client.?;
consume_typed reads with long polling, hands over the body already deserialized, deletes the message if the handler returns Ok and renews the invisibility while it runs. The details and customizations follow.
If the body is not a T, consume_typed returns client.invalid-response before the handler and the message is not deleted. Run the tests with the feature: cargo test --workspace --all-features.
Without serde: consume_with
Besides consume, which returns the list, consume_with reads from the queue with long polling (20 s), one message at a time and 120 s of invisibility (this mode's defaults; pass a ConsumeOptions to change them), hands each message to a Delivery and deletes the message if the handler returns Ok (delivery.delete is true by default). While the handler runs, a second thread renews the invisibility every third of it, so no other consumer takes the message. If the handler returns Err, the message is not deleted and the error propagates as ConsumeError::Handler.
Minimal:
loop
Complete, annotated:
let stop = new; // elsewhere (a signal) sets true to end
while !stop.load
Client::call and Call are the lower layer (route, query, body): it is what taba-cli uses to print the responses as the server returned them. taba_client::testing is a fake transport for the tests of whoever uses the connector.
Still missing: the async form (async feature, tokio) and a Transport the application can swap.
Declaring a topic
create_or_update_topic(&TopicRequest, Recreate) (PUT /topics/{topic}) creates the topic or brings it to the declared state, and returns a TopicPut with the topic and the outcome (TopicOutcome::Created, Updated or Recreated). What is left out goes back to the server default (a full replacement, unlike the update); another type, fifo or volatile is the error 409 topic.immutable-mismatch unless recreate is if-empty (only when the queue and its dead-letter are empty, 409 topic.not-empty otherwise) or always (drops the messages; new id). After a 503 the call is repeated like the others. delete_topic_if_empty(name) only removes a queue with no message. create_topic does not change (409 when it exists). Details: Create or update a topic.
Batches
Many messages in one request, next to the single calls (optional): publish_batch(topic, &[BatchMessage]), ack_batch(topic, &messages) and change_visibility_batch(topic, &messages, seconds) return one BatchResult per item (is_ok(), status, id, error_code). Each item is answered as its single call, in order, and an item that failed comes back with its status and error code instead of throwing. The bodies go in base64, so any type fits. Details: Messages in batch.
License
Apache-2.0. The Taba server is AGPL-3.0-only; the connectors are Apache-2.0 so any application, open or closed, can embed them.