KubeMQ
Client SDKsRustHow-to guidesQueues

Auto Ack

Automatically acknowledge KubeMQ queue messages on delivery using the simple receive API in Rust.

Overview

Auto-ack is the fire-and-forget receive mode for queues: the broker marks a message as consumed the instant it hands it to your client, instead of waiting for your code to settle it. Reach for it when the work is idempotent, low-value, or cheap to lose — a metrics ping, a cache warm, a best-effort notification — and you'd rather not carry the bookkeeping of explicit acknowledgment for every message.

It works by calling receive_queue_messages with is_peek set to false. With it enabled, delivery and acknowledgment happen as one atomic step on the broker side, so there's no separate ack call and no in-flight "pending" state for the message to sit in.

Gotchas: if your consumer crashes or panics after receive_queue_messages returns but before it finishes processing, that message is gone for good — auto-ack gives you no chance to nack or requeue it, unlike Ack & Reject. It's an at-most-once model, so never use it for messages where losing one silently would matter. And because acknowledgment happens on delivery, the max_messages and wait_timeout arguments are your only throttles — there's no visibility-timeout window to tune.

Prerequisites

  • KubeMQ server running on localhost:50000
  • Rust SDK installed (cargo add kubemq)

Code

main.rs
use kubemq::prelude::*;
use kubemq::QueueMessageBuilder;

#[tokio::main]
async fn main() -> kubemq::Result<()> {
    let client = KubemqClient::builder()
        .host("localhost")
        .port(50000)
        .build()
        .await?;

    let channel = "rust-queues.auto-ack";

    let msg = QueueMessageBuilder::new()
        .channel(channel)
        .body(b"auto-ack-message".to_vec())
        .build();
    client.send_queue_message(msg).await?;

    let messages = client.receive_queue_messages(channel, 10, 5, false).await?;
    for m in &messages {
        println!("Auto-acked: id={}, body={}", m.id, String::from_utf8_lossy(&m.body));
    }

    client.close().await?;
    Ok(())
}

How It Works

  • The simple receive API (is_peek=false) automatically acknowledges messages on delivery.
  • No explicit ack call is needed — the server marks messages as consumed.
  • Review timeouts, channel names, and client IDs before running against shared environments.
  • Run the program while the server from the prerequisites is available.

Was this page helpful?

On this page