0Pricing
RabbitMQ Messaging & Async Systems · 강의

클러스터링을 위한 Federation 플러그인

복잡한 네트워킹 없이 여러 RabbitMQ 브로커를 논리적 클러스터로 연결하는 Federation 플러그인을 살펴봅니다. 여러 데이터 센터에 걸친 분산 메시징 시스템을 구축합니다.

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

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

What is RabbitMQ Federation?

Imagine you have RabbitMQ brokers in different data centers or cloud regions. How do they share messages without complex network setups?

The Federation plugin allows you to loosely connect these brokers. It enables messages to flow between them, creating a distributed messaging system across geographical boundaries.

Federation vs. Traditional Clustering

It's important to distinguish Federation from traditional RabbitMQ clustering:

  • Clustering: Tightly couples nodes, sharing state and data. Best for high availability within a single, low-latency network (e.g., a data center).
  • Federation: Loosely connects brokers by replicating messages. Ideal for spanning wide area networks (WANs) or connecting brokers managed by different teams. It doesn't share state like a cluster.

Key Components: Upstreams & Policies

Federation relies on two main concepts:

  • Upstreams: These define the source broker from which messages will be pulled. An upstream specifies the connection details (like URI) of the remote RabbitMQ instance.
  • Policies: These rules determine which exchanges or queues on your downstream broker should connect to which upstream broker. They use regular expressions to match names.

Enabling the Federation Plugin

Before you can use federation, you need to enable the plugin on all participating RabbitMQ brokers. This is done using the RabbitMQ command-line tool.

Run this command on each broker:

rabbitmq-plugins enable rabbitmq_federation rabbitmq_federation_management

Configuring an Upstream Link

An 'upstream' tells your local broker where to pull messages from. You define it using the rabbitmqctl set_parameter command.

This example sets up an upstream named 'my-upstream' pointing to a remote broker:

rabbitmqctl set_parameter federation-upstream my-upstream \
'{"uri":"amqp://guest:guest@remote-host:5672","expires":3600000}'

Creating a Federation Policy for Exchanges

Once an upstream is defined, you apply it to exchanges using a policy. This policy tells your local broker to federate messages for matching exchanges from the specified upstream.

This policy federates all exchanges starting with 'fed.' from 'my-upstream':

rabbitmqctl set_policy --apply-to exchanges \
fed-exchanges ".^fed\\..*" \
'{"federation-upstream":"my-upstream"}'

How Federated Exchanges Work

With a federated exchange:

  • A producer publishes messages to an exchange on the upstream broker.
  • The federation plugin on the downstream broker pulls these messages from the upstream exchange.
  • The messages then arrive at the corresponding federated exchange on the downstream broker, where local consumers can receive them.

The consumer only interacts with its local (downstream) broker.

Client Example: Consuming from Federated Exchange

Here's a Python consumer that connects to a downstream broker and receives messages from a federated exchange. It doesn't need to know the messages originated from an upstream broker.

To run this, ensure you have pika installed (pip install pika).

import pika
import sys
import os

def main():
    # Connect to the local (downstream) RabbitMQ broker
    connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
    channel = connection.channel()

    # Declare the exchange that is federated from an upstream broker
    # (e.g., using the policy created in previous steps for 'fed_logs')
    channel.exchange_declare(exchange='fed_logs', exchange_type='fanout', durable=True)

    result = channel.queue_declare(queue='', exclusive=True)
    queue_name = result.method.queue

    channel.queue_bind(exchange='fed_logs', queue=queue_name)

    print(' [*] Waiting for federated messages. To exit press CTRL+C')

    def callback(ch, method, properties, body):
        print(f" [x] Received: {body.decode()}")

    channel.basic_consume(queue=queue_name, on_message_callback=callback, auto_ack=True)
    channel.start_consuming()

if __name__ == '__main__':
    try:
        main()
    except KeyboardInterrupt:
        print(' Interrupted')
        try:
            sys.exit(0)
        except SystemExit:
            os._exit(0)

Federating Queues

You can also federate queues. When a queue is federated, messages published to that queue on the upstream broker will be pulled and added to the corresponding queue on the downstream broker.

The policy setup is very similar, just specify --apply-to queues:

rabbitmqctl set_policy --apply-to queues \
fed-queues ".^fed\\..*" \
'{"federation-upstream":"my-upstream"}'

Quick Check on Federation

Which of the following best describes the primary use case for RabbitMQ Federation?

Recap: Federation for Distributed Messaging

In this lesson, you learned about the RabbitMQ Federation plugin:

  • It allows you to connect RabbitMQ brokers across different locations.
  • It uses upstreams to define source brokers and policies to apply federation rules.
  • Federation differs from clustering by offering loose coupling, suitable for WANs.
  • You can federate both exchanges and queues, enabling flexible message distribution in a distributed system.

This powerful plugin helps you build robust, geographically distributed messaging architectures.

자주 묻는 질문

“클러스터링을 위한 Federation 플러그인” 강의는 무료인가요?

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

“클러스터링을 위한 Federation 플러그인”에서 뭘 배우나요?

복잡한 네트워킹 없이 여러 RabbitMQ 브로커를 논리적 클러스터로 연결하는 Federation 플러그인을 살펴봅니다. 여러 데이터 센터에 걸친 분산 메시징 시스템을 구축합니다. 브라우저에서 직접 실행하는 실습 코드로 RabbitMQ Messaging & Async Systems을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

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

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

“클러스터링을 위한 Federation 플러그인” 강의는 얼마나 걸리나요?

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

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

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

이 강의의 모든 강의

  1. 지연 메시지 플러그인
  2. 페더레이션을 위한 Shovel 플러그인
  3. 클러스터링을 위한 Federation 플러그인
  4. 메시지 중복 제거 및 일관된 해시 익스체인지 플러그인
← RabbitMQ Messaging & Async Systems(으)로 돌아가기