# Peek Messages (/sdks/rust/how-to/queues/peek-messages)



## Overview [#overview]

Peeking lets you look at what's sitting in a queue without touching it — the messages stay exactly where they are, still waiting for whichever consumer eventually receives them. It's the tool you reach for when you need visibility into queue state — checking backlog depth, inspecting payloads while debugging a stuck pipeline, or building an operational dashboard — without risking a collision with real consumers competing for the same work.

`receive_queue_messages(channel, max_messages, wait_timeout_seconds, is_peek)` is the same call your consumers use, just with the `is_peek` flag set to `true`: the broker returns a snapshot of messages currently queued but never marks them as delivered, locks them, or starts a visibility timeout — so no acknowledgment is needed or even possible.

**Gotchas:** peeked messages aren't reserved for you — a consumer calling with `is_peek=false` can remove them the instant after you peek, so treat the count as a point-in-time estimate, not a guarantee. Peek also won't surface messages already locked inside another consumer's in-flight receive, and it's not a substitute for receiving when you actually intend to process what you see.

## 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::QueueMessageBuilder;

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

    let channel = "rust-queues.peek-messages";

    let msg = QueueMessageBuilder::new()
        .channel(channel)
        .body(b"peek-at-me".to_vec())
        .build();
    client.send_queue_message(msg).await?;

    let peeked = client.receive_queue_messages(channel, 10, 5, true).await?;
    println!("Peeked {} messages (still in queue)", peeked.len());

    for m in &peeked {
        println!("  id={}, body={}", m.id, String::from_utf8_lossy(&m.body));
    }

    let consumed = client.receive_queue_messages(channel, 10, 5, false).await?;
    println!("Consumed {} messages", consumed.len());

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

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

* Pass `is_peek=true` to `receive_queue_messages` to read without consuming.
* Peeked messages remain in the queue and can be received again.
* Pass `is_peek=false` to consume and acknowledge the messages.
* 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)
