Post

RabbitMQ 주요 개념

RabbitMQ 주요 개념을 소개합니다.

Connection

  • RabbitMQ 와 어플리케이션 서버간 물리적 연결을 말함
  • 한 애플리케이션이 RabbitMQ에 연결할 때마다 하나의 connection이 생성

Channel

  • Connection 내부에서 생성되는 가상의 연결
  • 하나의 Connection에서 여러 개의 Channel 생성 가능

Exchange

  • 메시지를 받아서 Queue로 라우팅하는 역할
  • 메시지가 어떤 Queue로 전달될지 결정하는 타입을 가지고 있음
  • 주요 타입
    • Direct: 특정 라우팅 키로만 라우팅.
        graph LR
                  
            P[Producer] --> E[Direct Exchange]
            E -->|routing_key = error| Q1[Error Queue]
            E -->|routing_key = info| Q2[Info Queue]
            E -->|routing_key = warning| Q3[Warning Queue]
                  
            style P fill:#00000,stroke:#333,stroke-width:2px
            style E fill:#b37c07,stroke:#333,stroke-width:2px
            style Q1 fill:#076bb3,stroke:#333,stroke-width:2px
            style Q2 fill:#076bb3,stroke:#333,stroke-width:2px
            style Q3 fill:#076bb3,stroke:#333,stroke-width:2px
      
      
    • Fanout: 모든 큐에 메시지 전달.

        graph LR
            P[Producer] --> E[Fanout Exchange]
            E --> Q1[Queue 1]
            E --> Q2[Queue 2]
            E --> Q3[Queue 3]
                  
            style P fill:#0000,stroke:#333,stroke-width:2px
            style E fill:#b37c07,stroke:#333,stroke-width:2px
            style Q1 fill:#076bb3,stroke:#333,stroke-width:2px
            style Q2 fill:#076bb3,stroke:#333,stroke-width:2px
            style Q3 fill:#076bb3,stroke:#333,stroke-width:2px
      
    • Topic: 특정 패턴에 따라 라우팅.

        graph LR
            P[Producer] --> E[Topic Exchange]
            E -->|"korea.weather.*"| Q1[Weather Queue]
            E -->|"korea.#"| Q2[Korea All Queue]
            E -->|"*.error"| Q3[Error Queue]
                  
            style P fill:#00000,stroke:#333,stroke-width:2px
            style E fill:#b37c07,stroke:#333,stroke-width:2px
            style Q1 fill:#076bb3,stroke:#333,stroke-width:2px
            style Q2 fill:#076bb3,stroke:#333,stroke-width:2px
            style Q3 fill:#076bb3,stroke:#333,stroke-width:2px
                  
            note["'*' = one word<br/># = zero or more words"]
            style note fill:#00000,stroke:#333,stroke-width:2px
      
    • Headers: 메시지 헤더에 따라 라우팅.

        graph LR
            P[Producer] --> E[Headers Exchange]
            E -->|"format=pdf, type=report"| Q1[PDF Queue]
            E -->|"format=json, type=log"| Q2[JSON Queue]
            E -->|"format=xml, type=report"| Q3[XML Queue]
                  
            style P fill:#00000,stroke:#333,stroke-width:2px
            style E fill:#b37c07, stroke:#333, stroke-width:2px
            style Q1 fill:#076bb3,stroke:#333, stroke-width:2px
            style Q2 fill:#076bb3,stroke:#333, stroke-width:2px
            style Q3 fill:#076bb3,stroke:#333, stroke-width:2px
      

Queue

  • 실제 메시지가 저장되는 버퍼
  • Consumer가 메시지를 가져가기 전까지 메시지를 보관
  • FIFO(First In First Out) 방식
  • 다양한 속성 설정 가능
    • durable: 서버 재시작 후에도 유지
    • exclusive: 특정 connection에서만 사용
    • auto-delete: 마지막 consumer가 구독을 취소하면 자동 삭제
This post is licensed under CC BY 4.0 by the author.