RabbitMQ

오민석·2021년 8월 31일
0

https://www.rabbitmq.com/tutorials/tutorial-six-python.html

MSA 비동기 방식 사용 이유

https://docs.microsoft.com/ko-kr/dotnet/architecture/microservices/architect-microservice-container-applications/communication-in-microservice-architecture

https://engineering-skcc.github.io/microservice%20outer%20achitecture/inner-architecture-conn/

https://velog.io/@dnjscksdn98/Spring-Boot-MSA-Communication-between-Microservices

http://34.117.35.195/operation/integration/integration-three/

corr_id
https://www.rapid7.com/blog/post/2016/12/23/the-value-of-correlation-ids/

RestAPI vs Messaging

RestAPI: 동기적 처리 필요, public API
Messaging: 비동기, Decoupling BUT, error handling + Logging 힘듬

장점

  • 유연한 라우팅
  • 언어에 상관 없음
  • 메세지 전달 보장, 저장 등 안정성

구조

Exchange 종류

Direct Exchange: 특정 큐를 대상으로

Fanout Exchange: 전체 큐를 대상으로

Topic Exchange: 하나 이상 큐에 pattern지정 ex. image.#

Headers Exchange: 메세지 속성 중 headers 테이블 사용해 특정 규칙

RPC -> Callback & corr_id

https://www.rabbitmq.com/tutorials/tutorial-six-python.html

Client의 request를 Server에 전달하고 , Server가 처리한 결과를 알맞은 Client 요청에 대한 응답으로 전달 할 수 있는 방법

ReplyTo : Callback Queue의 이름
CorrelationID : 요청을 구분할 수 있는 유일값

출처: https://skarlsla.tistory.com/15 [개발 스토리]

When the Client starts up, it creates an anonymous exclusive callback queue.
For an RPC request, the Client sends a message with two properties: reply_to, which is set to the callback queue and correlation_id, which is set to a unique value for every request.
The request is sent to an rpc_queue queue.
The RPC worker (aka: server) is waiting for requests on that queue. When a request appears, it does the job and sends a message with the result back to the Client, using the queue from the reply_to field.
The client waits for data on the callback queue. When a message appears, it checks the correlation_id property. If it matches the value from the request it returns the response to the application.

메세지 전달 보장

ack

ture로 되어 있을때는 queue에 message가 들어오면 해당 queue를 바라보고 있는 Consumer에 전달이 되고 이때 Consumer에서 message에 대해 처리 여부(이 테스트에서는 화면에 출력)와 상관없이 자동으로 queue에 받았다는 ack를 리턴하기 때문에 queue에서는 지워지게 된다. 만약 처리 안되었다면 mq가 re-queue한다

durable

ack써도 mq 서버자체가 죽으면 메세지 잃을 수 있어서 queue, message 둘 다 durable 디스크에 저장

https://colinch4.github.io/2021-01-15/602_Work_Queues/

Fair Dispatch

여러 개의 consumer가 있을 때 round robin 방식이 아니라 prefetchCount = 1 설정으로 BasicQos 메서드를 사용한다. 한 번에 두 개 이상의 메시지를 주지 않는다. 이전 메시지를 처리하고 승인할 때까지 작업자에게 새 메시지를 발송하지 않고, 바쁘지 않은 다음 작업자에게 발송

0개의 댓글

관련 채용 정보