0Pricing
RabbitMQ Messaging & Async Systems · Ders

HA için Yansıtılmış Kuyruklar

Mesajları birden çok küme düğümünde çoğaltmak için yansıtılmış kuyrukları uygulayın. Düğümlerin arızalanması durumunda mesajların korunmasını sağlayarak kuyruklarınız için yüksek kullanılabilirlik elde edin.

HA için Yansıtılmış Kuyruklar, CoddyKit'te ücretsiz bir RabbitMQ Messaging & Async Systems dersidir. Bu, 4 dersinin 3. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, RabbitMQ Messaging & Async Systems öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. RabbitMQ Messaging & Async Systems kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

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.

Sıkça Sorulan Sorular

“HA için Yansıtılmış Kuyruklar” dersi ücretsiz mi?

Evet — “HA için Yansıtılmış Kuyruklar” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve RabbitMQ Messaging & Async Systems kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. RabbitMQ Messaging & Async Systems kursu toplamda 4 dersten oluşur.

“HA için Yansıtılmış Kuyruklar” dersinde ne öğreneceğim?

Mesajları birden çok küme düğümünde çoğaltmak için yansıtılmış kuyrukları uygulayın. Düğümlerin arızalanması durumunda mesajların korunmasını sağlayarak kuyruklarınız için yüksek kullanılabilirlik el… RabbitMQ Messaging & Async Systems ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

RabbitMQ Messaging & Async Systems öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te RabbitMQ Messaging & Async Systems, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 3. dersidir.

“HA için Yansıtılmış Kuyruklar” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu RabbitMQ Messaging & Async Systems dersinde kod yazıp çalıştırabilir miyim?

Evet. Her RabbitMQ Messaging & Async Systems dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. RabbitMQ Kümeleme Kavramları
  2. Kümelenmiş Ortam Kurulumu
  3. HA için Yansıtılmış Kuyruklar
  4. Modern HA için Çoğunluk Kuyrukları
← RabbitMQ Messaging & Async Systems Sayfasına Dön