# Ack All (/sdks/rust/how-to/queues/ack-all)



## Overview [#overview]

`ack_all_queue_messages` acknowledges **every pending message on a channel in a single broker-side call**, without receiving them first. Reach for it when you want to *drain* a queue rather than *process* it — clearing a backlog of stale work after a bad deploy, resetting a channel between test runs, or discarding messages that are no longer relevant — where pulling and acking each message individually would be slow and wasteful.

Because it settles the whole channel at once, it is far cheaper than a receive-then-ack loop: the broker confirms all in-flight messages atomically and reports how many were affected via `affected_messages` on the response, using `wait_time_seconds` on the request to bound how long it waits for in-flight transactions to settle before counting.

**Gotchas:** this is a blunt, irreversible instrument — it acknowledges *all* currently-pending messages, not a selected subset, so anything unprocessed is discarded, not redelivered. A busy channel may need a larger `wait_time_seconds` to catch messages still landing. For routine, per-message cleanup use ordinary acks, an expiration policy, or a [dead-letter policy](/sdks/rust/how-to/queues/dead-letter-policy) instead — save ack-all for deliberate, wholesale purges.

## Prerequisites [#prerequisites]

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

## Code [#code]

```rust title="main.rs"
use kubemq::prelude::*;
use kubemq::{AckAllQueueMessagesRequest, QueueMessageBuilder};

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

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

    for i in 0..5 {
        let msg = QueueMessageBuilder::new()
            .channel(channel)
            .body(format!("msg-{}", i).into_bytes())
            .build();
        client.send_queue_message(msg).await?;
    }
    println!("Sent 5 messages");

    let req = AckAllQueueMessagesRequest {
        request_id: String::new(),
        client_id: String::new(),
        channel: channel.to_string(),
        wait_time_seconds: 5,
    };

    let resp = client.ack_all_queue_messages(&req).await?;
    println!("Acknowledged {} messages", resp.affected_messages);

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

## How It Works [#how-it-works]

* `ack_all_queue_messages` acknowledges all pending messages in the specified queue.
* Returns the count of affected messages in `AckAllQueueMessagesResponse`.
* Review timeouts, channel names, and client IDs before running against shared environments.
* Run the program while the server from the prerequisites is available.

## Related [#related]

* [Queues overview](/learn/queues)
* [Rust SDK Reference](/sdks/rust/reference/queues)
* [Send & Receive](/sdks/rust/tutorials/send-receive)
