0Pricing
RabbitMQ Messaging & Async Systems · 강의

HA를 위한 미러링 큐

여러 클러스터 노드에 걸쳐 메시지를 복제하도록 미러링 큐를 구현합니다. 노드 장애가 발생해도 메시지가 유지되도록 큐의 고가용성을 확보합니다.

HA를 위한 미러링 큐은(는) CoddyKit의 무료 RabbitMQ Messaging & Async Systems 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 RabbitMQ Messaging & Async Systems 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. RabbitMQ Messaging & Async Systems 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Intro to Mirrored Queues

In a RabbitMQ cluster, queues are by default located on a single node. If that node fails, any messages in its queues (and the queues themselves) become unavailable until the node recovers.

Mirrored queues solve this by replicating queue contents across multiple nodes. This ensures high availability (HA) and fault tolerance for your messages.

Why Use Mirrored Queues?

Imagine a critical application where losing messages or experiencing downtime is unacceptable. Mirrored queues provide:

  • High Availability: If the node hosting the primary queue fails, a replica can take over seamlessly.
  • Data Durability: Messages are stored on multiple nodes, protecting against single-node failures.
  • Fault Tolerance: The system can continue operating even if some nodes go offline.

They are essential for robust, production-grade RabbitMQ deployments.

Master & Replica Architecture

When a queue is mirrored, one node hosts the master (or primary) queue. All other nodes hosting mirrors run replicas.

All operations for a mirrored queue (publishing, consuming, adding messages) are first handled by the master. The master then replicates these operations to all its replicas.

Configuring Mirroring with Policies

You don't configure mirroring directly on individual queues. Instead, you use policies. A policy is a set of rules that apply to queues whose names match a specific pattern.

This allows you to define mirroring behavior for many queues at once, or for queues created in the future, without modifying client code.

Policy Example: Mirror All Queues

Here's how to create a policy named ha-all that mirrors all queues (matching ".*") to all nodes in the cluster ("ha-mode":"all").

You'd typically run this command on one of your RabbitMQ cluster nodes via the command line.

rabbitmqctl set_policy ha-all ".*" '{"ha-mode":"all"}' --apply-to queues

Understanding ha-mode Options

The ha-mode argument in a policy defines how mirroring should behave:

  • all: The queue will be mirrored to all nodes in the cluster.
  • exactly: The queue will be mirrored to a specific number of nodes (e.g., {"ha-mode":"exactly", "ha-params":2}).
  • nodes: The queue will be mirrored to a specific list of named nodes (e.g., {"ha-mode":"nodes", "ha-params":["rabbit@node1", "rabbit@node2"]}).

Producers & Mirrored Queues

From a producer's perspective, interacting with a mirrored queue is no different than a non-mirrored one. The client connects to any node in the cluster, and RabbitMQ handles routing the message to the master queue for mirroring.

Try running this simple Java producer:

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class Producer {
  private final static String QUEUE_NAME = "my_mirrored_queue";

  public static void main(String[] argv) throws Exception {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost"); // Connect to any cluster node
    try (Connection connection = factory.newConnection();
         Channel channel = connection.createChannel()) {
      // Declare a durable queue (important for mirrored queues)
      channel.queueDeclare(QUEUE_NAME, true, false, false, null);
      String message = "Hello, Mirrored Queue!";
      channel.basicPublish("", QUEUE_NAME, null, message.getBytes("UTF-8"));
      System.out.println(" [x] Sent '" + message + "'");
    }
  }
}

Consumers & Mirrored Queues

Similarly, consumers don't need special logic to consume from a mirrored queue. They simply connect to a node and subscribe to the queue.

If the master queue fails, RabbitMQ automatically promotes a replica to master, and consumers transparently switch to the new master (though a brief reconnect might be needed).

Run this consumer example:

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.DeliverCallback;

public class Consumer {
  private final static String QUEUE_NAME = "my_mirrored_queue";

  public static void main(String[] argv) throws Exception {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost("localhost"); // Connect to any cluster node
    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.queueDeclare(QUEUE_NAME, true, false, false, null);
    System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

    DeliverCallback deliverCallback = (consumerTag, delivery) -> {
      String message = new String(delivery.getBody(), "UTF-8");
      System.out.println(" [x] Received '" + message + "'");
    };
    // Basic consume with auto-acknowledgement
    channel.basicConsume(QUEUE_NAME, true, deliverCallback, consumerTag -> {});
  }
}

Failover & Replica Sync

When a master node fails, RabbitMQ elects a new master from the available replicas. This new master takes over, and message processing continues without data loss.

If a node with a replica rejoins the cluster, or a new node is added, the replica will synchronize its contents with the current master. This ensures all messages are consistent across the mirrored queue instances.

Quick Check: Mirrored Queues

You've learned about the importance and mechanics of mirrored queues. Let's test your understanding.

Recap: Mirrored Queues for HA

We've explored mirrored queues, a crucial feature for ensuring high availability and data durability in RabbitMQ clusters.

  • Mirrored queues replicate messages across master and replica nodes.
  • They are configured using policies, allowing flexible control over mirroring behavior.
  • Client applications (producers/consumers) interact with mirrored queues transparently.
  • In case of a master node failure, a replica is promoted, ensuring continuous service and message safety.

This mechanism is vital for building robust, fault-tolerant messaging systems.

자주 묻는 질문

“HA를 위한 미러링 큐” 강의는 무료인가요?

네 — “HA를 위한 미러링 큐” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 RabbitMQ Messaging & Async Systems 강의 전체를 잠금 해제할 수 있습니다. RabbitMQ Messaging & Async Systems 강의에는 총 4개의 강의가 포함되어 있습니다.

“HA를 위한 미러링 큐”에서 뭘 배우나요?

여러 클러스터 노드에 걸쳐 메시지를 복제하도록 미러링 큐를 구현합니다. 노드 장애가 발생해도 메시지가 유지되도록 큐의 고가용성을 확보합니다. 브라우저에서 직접 실행하는 실습 코드로 RabbitMQ Messaging & Async Systems을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

RabbitMQ Messaging & Async Systems을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 RabbitMQ Messaging & Async Systems은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.

“HA를 위한 미러링 큐” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 RabbitMQ Messaging & Async Systems 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 RabbitMQ Messaging & Async Systems 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. RabbitMQ 클러스터링 개념
  2. 클러스터 환경 설정
  3. HA를 위한 미러링 큐
  4. 최신 HA를 위한 쿼럼 큐
← RabbitMQ Messaging & Async Systems(으)로 돌아가기