Skip to content

Quick Start

This page gets you from zero to a working publish-and-consume round trip against a local RobustMQ instance in a few minutes.

1. Start the Broker

Follow the build/run instructions in the repository root to start a single-node RobustMQ instance (see the project README for exact build and startup steps). Confirm the port under the [amqp_runtime] section in your config file (default 5672):

toml
[amqp_runtime]
tcp_port = 5672

2. Add the Dependency (Java)

xml
<dependency>
    <groupId>com.rabbitmq</groupId>
    <artifactId>amqp-client</artifactId>
    <version>5.21.0</version>
</dependency>

3. Connect, Declare, Publish, Consume

java
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("127.0.0.1");
factory.setPort(5672);
factory.setUsername("app_user");     // this user must already exist in RobustMQ
factory.setPassword("app_password");

try (Connection connection = factory.newConnection();
     Channel channel = connection.createChannel()) {

    // Declare an exchange and queue, and bind them
    channel.exchangeDeclare("demo-exchange", BuiltinExchangeType.DIRECT, true);
    channel.queueDeclare("demo-queue", true, false, false, null);
    channel.queueBind("demo-queue", "demo-exchange", "demo-key");

    // Publish a message (with confirms enabled for reliable delivery)
    channel.confirmSelect();
    channel.basicPublish("demo-exchange", "demo-key", null, "hello robustmq".getBytes());
    channel.waitForConfirms(3000);

    // Consume it
    GetResponse resp = channel.basicGet("demo-queue", true);
    if (resp != null) {
        System.out.println("received: " + new String(resp.getBody()));
    }
}

Expected output:

text
received: hello robustmq

Next Steps

🎉 既然都登录了 GitHub,不如顺手给我们点个 Star 吧!⭐ 你的支持是我们最大的动力 🚀