Skip to content

Quickstart

This guide gets you from zero to producing and consuming messages in under a minute.

Download the latest danube-broker and danube-cli binaries from the releases page, or pull the container image.

  1. Start the broker

    Terminal 1
    danube-broker --mode standalone --data-dir ./danube-data

    Broker ready on 127.0.0.1:6650, admin on 127.0.0.1:50051. No config file needed.

  2. Produce messages

    Terminal 2
    danube-cli produce \
    -s http://127.0.0.1:6650 \
    -t /default/quickstart \
    -c 10 \
    -m "Hello, Danube!"
  3. Consume messages

    Terminal 3
    danube-cli consume \
    -s http://127.0.0.1:6650 \
    -t /default/quickstart \
    -m my-subscription

    You should see the 10 messages arrive at the consumer.

  1. The broker started in standalone mode, a single-node setup with zero configuration.
  2. danube-cli produce created a topic /default/quickstart and published 10 messages.
  3. danube-cli consume created a subscription my-subscription and received the messages via best-effort dispatch.
examples/quickstart.rs
use danube_client::{DanubeClient, SubType};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = DanubeClient::builder()
.service_url("http://127.0.0.1:6650")
.build()
.await?;
// Producer
let mut producer = client
.new_producer()
.with_topic("/default/quickstart")
.with_name("my-producer")
.build()?;
producer.create().await?;
producer.send("Hello from Rust!".as_bytes().to_vec(), None).await?;
// Consumer
let mut consumer = client
.new_consumer()
.with_topic("/default/quickstart")
.with_consumer_name("my-consumer")
.with_subscription("my-sub")
.with_subscription_type(SubType::Exclusive)
.build()?;
consumer.subscribe().await?;
let mut stream = consumer.receive().await?;
while let Some(message) = stream.recv().await {
println!("Received: {}", String::from_utf8_lossy(&message.payload));
consumer.ack(&message).await?;
}
Ok(())
}