ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Spring AMQP
    spring 2019. 5. 13. 14:13

    개요


    Spring AMQP는 AMQP 기반의 메세징 솔루션이다. 메세지를 주고 받는 것과 관련한 추상화된 template을 제공한다. 이를 이해하기 위해서, Message Queue, AMQP를 우선 살펴본다.

    Message Queue


    MOM(Message Oriented Middleware)

    응용 스프트웨어 간의 메세지 교환을 비동기적으로 처리하기 위한 소프트웨어이다.

     

    Message Queue는 MOM을 구현하기 위해 주로 사용되는 방법이다. 이름에서 유추할 수 있듯이 메시징에 큐를 사용한다. sender와 receiver가 직접적으로 메시지를 교환하지 않고, 중간에 큐를 두어 비동기적으로 교환한다. publisher/subscriber model) 따라서, application과 분리가 가능하고, 메시지 전송이 보장되며(실패하면 큐에서 다시 전송하면 되므로), 많은 프로세스들이 하나의 메시지 큐에 붙을 수 있으므로 확장성을 제공할 수 있다.

    AMQP


    AMQP(Advanced Message Queuing Protocol)는 위에서 이야기한 Message Queue를 구현하기 위한 application layer의 openly standard protocol이다. 기존 메세지 큐 미들웨어(ex. JMS - Java Message Service)는 API level에서 구현되었다.

    이는 각기 다른 언어로 구현된 프로그램들 간에는 통신할 수 없는 제약사항을 야기한다. 이러한 문제를 해결하고자, AMQP는 wire level에서 프로토콜을 정의했다. wire level protocol이란, 바이트 스트림으로 네크워크를 통해 송수신되는 데이터의 protocol이다. 따라서, 구현 언어에 상관 없이 서로 다른 구현체가 메시지를 교환할 수 있다.

    Spring AMQP


    다시 Spring AMQP로 돌아오자. Spring AMQP는 spring-amqp와 spring-rabbit module로 구성되어 있다. spring-amqp는 AMQP 기반의 추상화된 기능을 제공한다. spring-rabbit은 RabbitMQ라는 message broker를 이용한 실제 구현 모듈이다.

    RabbitMQ

    RabbitMQ는 AMQP를 이용한 message broker이다.

    Producer(P): message를 생산

    Exchange(X): producer가 직접 queue에 message를 넣지 않고, Exchange가 message를 type에 맞게 적절한 queue에 보낸다.

    * type

    • 1) direct: 각 queue에 binding key가 존재, Producer가 routing key로 넣는 값이 binding key와 일치하는 queue에 전송한다.
    • 2) topic: direct와 비슷하다. 다만, binding key에 *(exactly one word)나 #(more than one word)를 사용할 수 있다.

    Queue(Q#): message queue

    Consumer(C#): message를 소비

    Connection factory: channel들을 생성해 RabbitMQ로의 connection threads를 관리

     

     

    참고


    https://docs.spring.io/spring-amqp/docs/current/reference/#_reference

    https://projects.spring.io/spring-amqp/#quick-start

    https://spring.io/understanding/AMQP

    https://www.rabbitmq.com/tutorials/tutorial-one-java.html

    https://www.rabbitmq.com/dlx.html

    https://ko.wikipedia.org/wiki/AMQP

    'spring' 카테고리의 다른 글

    Spring Webflux - Functional Endpoints  (0) 2019.07.25
    Spring Webflux - DispatcherHandler  (0) 2019.07.18
    Spring WebClient  (0) 2019.07.10
    Spring Webflux + Reactor  (0) 2019.05.13
    JDK Dynamic Proxy vs CGLib Proxy  (0) 2019.05.13

    댓글

Designed by Tistory.