RabbitMQ Concept & How to work
High Availability in RabbitMQ
- Clustering & Mirrored Queue
HAProxy
Spring Cloud Stream Sample & configuration: Spring Boot App with Rabbit
Understanding of Apache kafka metrics for monitoring
Message Queue 가용성, 신뢰성을 위한 RabbitMQ Server, Client 구성
1. 1
Message Queue 가용성, 신뢰성을
위한 RabbitMQ Server, Client 구성
Chloe
2018.01.26
RabbitMQ Concept & How to work
High Availability in RabbitMQ
Clustering & Mirrored Queue
HAProxy
Spring Cloud Stream Sample & configuration: Spring Boot App with Rabbit
2. 2
Message Broker:RabbitMQ
1 Message queueing
2 Delivery acknowledgement
- Acknowledgements and Confirms
- Clustering and High Availability
-Mirrored queue
3 Flexible routing to queues
4 Multiple exchange type
RabbitMQ – 특징
4. 4
Message Broker:RabbitMQ
RabbitMQ 기본 – 성공적인 메시지 전달을 위한 Broker 구성요소
Exchange
publish된 메시지를 받는 곳
-> Queue
consume가 일어나는 곳
Bindings
Exchange와 Queue 매핑정보
Queue 결정방식
exchange type + routing key
Queue 동작방식
메시지 도착 → 메시지 전송
→ Acknowlegement from Consumer
→ Queue에서 메시지 삭제
7. 7
RabbitMQ High Availability
High Availability
Wiki
고가용성(HA)이란 서버와 네트워크, 프로그램 등의 정보 시스템이 상당히 오랜 기간 동안
지속적으로 정상 운영이 가능한 성질을 말한다.
고(高)가용성이란 "가용성이 높다"는 뜻으로서, "절대 고장 나지 않음"을 의미한다.
만약 클러스터로 묶인 2개의 서버 중 1대의 서버에서 장애가 발생할 경우,
다른 서버가 즉시 그 업무를 대신 수행하므로, 시스템 장애를 불과 몇 초만에 복구할 수 있다.
8. 8
RabbitMQ High Availability
1 Clustering – 의미와 특징
Clustering 설계 목표
1 하나의 Node가 죽더라도 Producer와 Consumer가 계속 메시지를 교환할 수 있도록 한다
2 메시지 처리량이 많아지면 클러스터에 노드를 새로 추가하여 처리 성능을 높일 수 있다
Cluster
rabbit3 Node
rabbit2 Node
rabbit1 Node
Producer Consumer
11. 11
RabbitMQ High Availability
1 Clustering – Producer/Consumer App 실행/결과 확인
Cluster
Producer Consumer
localhost:5673
localhost:5672
Case1 – 큐를 선언하지 않은 노드를 중단
Producer: 5 message publish to 5673
5673 down
Consumer: connection consume from 5674
결과: Consumer receives 5 messages
Case2 – 큐를 선언한 노드를 중단
Producer: 5 message publish to 5673
5672 down
Consumer: connection consume from 5674
결과: Consumer ? 5 messages
localhost:5674
rabbit3 Node
rabbit2 Node
rabbit1 Node
12. 12
RabbitMQ High Availability
1 Clustering – 왜 rabbit1에 선언한 Queue에 접근하지 못할까?
Cluster
localhost:5673
localhost:5672 localhost:5674
rabbit3 Node
rabbit2 Node
rabbit1 Node
Queue 위치
Queue는 특정 노드에만 위치한다
다른 노드들은 실제 Queue가 아닌 Queue 메타데이터만 복제하고 있다
13. 13
RabbitMQ High Availability
2 Mirrored Queue – 모든 노드에 메시지 동기화
Cluster
rabbit3 Node
rabbit2 Node
rabbit1 Node
Master Slave (Mirror) Slave (Mirror)
Mirrored Queue 선언
ha-policy 설정
$ sbin/rabbitmqctl -n rabbit1 set_policy ha-all “Queue1” ‘{“ha-mode”:”all”}’
Producer
15. 15
RabbitMQ High Availability
2 Mirrored Queue – Master 중단, 새로운 Node 추가 시 동작
Cluster
rabbit3 Node
rabbit2 Node
rabbit1 Node
Master Master Slave (Mirror)
Master queue가 있는 Node가 중단 되었을 때
가장 오래된 Slave가 Master로 전환
새로운 노드가 Cluster에 추가 되었을 때
추가된 시점부터 들어온 메시지만 Mirroring, 이전 메시지는 복사하지 않는다
과거 데이터를 모두 복사하려면 ha-sync-mode 설정
16. 16
RabbitMQ High Availability
2 Mirrored Queue – ha-all 설정 테스트 실행/결과 확인
Producer Consumer
localhost:5673
localhost:5672
Case1 – Mirrored Queue 선언 전
Producer: 5 message publish to 5673
5673 down (Queue 선언 노드)
Consumer: connection consume from 5674
결과: Consumer can’t receives 5 messages
Case2 – Mirrored Queue 선언 전
Producer: 5 message publish to 5673
5672 down (Master)
Consumer: connection consume from 5674
결과: Consumer receives messages
localhost:5674
Cluster
rabbit3 Node
rabbit2 Node
rabbit1 Node
Master Slave (Mirror) Slave (Mirror)
18. 18
RabbitMQ High Availability
HAProxy – 특징
http://seokjun.kr/haproxy-and-nginx-load-balancing/일부 요약
Haproxy 는 L4, L7 과 같은 하드웨어 로드밸런서를 대체하기 위한 오픈소스 소프트에어
Reverse Proxy를 기반으로 로드밸런싱을 하기에 매우 강력하고 가벼움
HA (High Availability) 라는 이름처럼 고가용성을 위하여 설계됨
Nginx 로드밸런싱과 다른 점은 헬스체크라고 볼 수 있는데,
특정 API 에 접근하여 서버 상태를 점검하고, 문제가 있으면 다른 node 로 트래픽을 넘겨줄 수 있는 기능을 함
Nginx 자체의 로드밸런싱도 훌륭하지만, 굳이 웹 서버로서의 역할이 필요가 없다면
HAProxy 로드 밸런싱이 헬스체크가 가능하기도 하고 좀 더 가벼우니 필요에 따라 선택하면 좋을 것이다.
Stats 페이지 기본 제공, 어떤 서버에 접속되고 작동하고 있는지 확인하기 편리
간단하게 Nginx 와 HAProxy 의 로드밸런싱에 대해서 알아보았다.
19. 19
RabbitMQ High Availability
HAProxy – 테스트 확인
Case1 – Mirrored Queue 선언 전
Consumer: connection consume from 5674
5674 down (Queue 선언 노드)
결과: Connection failed
Case2 – Mirrored Queue 선언 전
Consumer: connection consume from 5670
Node which connected with consumer down
결과: Re-connected automatically
Producer Consumer
localhost:5670
Cluster
HAProxy
Producer Consumer
Cluster
localhost:567x localhost:567x
20. 20
RabbitMQ High Availability
HAProxy – haproxy.cfg
… (중략)
listen rabbitmq_local_cluster
bind *:5670
mode tcp
balance roundrobin
server rabbit1 127.0.0.1:5672 check inter 5000 rise 2 fall 3
server rabbit2 127.0.0.1:5673 check inter 5000 rise 2 fall 3
server rabbit3 127.0.0.1:5674 check inter 5000 rise 2 fall 3
listen private_monitoring
bind *:8100
mode http
option httplog
stats enable
stats uri /stats
stats refresh 5s
22. 22
Spring Cloud Stream& Sleuth
Message-driven microservices with Rabbit
Mission 2 // Message queue를 통해 서비스간 커뮤니케이션 하는 경우에도
Sleuth가 trace Id, span Id를 전달하는지 확인할 것
관련 Spring Cloud Framework
Spring cloud Stream
Spring cloud stream-binder rabbit
Spring Sleuth