What a message broker actually buys you

RabbitMQ Course · lesson 1 of 15 · 4 min read

A broker trades a synchronous answer for decoupled uptime, load levelling and retries.

Open this lesson in the learning hub

Key points

  • A direct HTTP call couples availability: if the callee is down, the caller fails right now.
  • A broker accepts the message, stores it, and hands it over when a consumer is ready to work.
  • That buffer levels load - 5000 orders a second can drain into a worker that handles 200.
  • RabbitMQ is an Erlang broker speaking AMQP 0-9-1 on port 5672, or 5671 with TLS.
  • The price is real: another service to operate, at-least-once delivery, and no synchronous answer.
  • Reach for a broker when the caller does not need the result now, not as a default for every call.

Example

ConnectionFactory cf = new ConnectionFactory();
cf.setHost("localhost");          // port 5672 by default
cf.setUsername("app");            // guest only works over loopback

try (Connection conn = cf.newConnection();
     Channel ch = conn.createChannel()) {

    ch.exchangeDeclare("orders", BuiltinExchangeType.TOPIC, true);
    ch.basicPublish("orders", "order.created", null,
                    json.getBytes(StandardCharsets.UTF_8));
}
// returns as soon as the broker has the bytes - the invoice service
// may still be starting up, and that is now fine

A broker buys decoupling, buffering and retry - and charges you the synchronous answer.

This is a reading copy. The full lesson — with the visual explainer, the interactive lab and a Run button for the code — lives in the RabbitMQ Course course, and every lesson in it is listed on the RabbitMQ Course contents page.