๊ฐœ๋ฐœ.log/rabbitMQ

[RabbitMQ] ์ฒ˜์Œ ๋งŒ๋‚˜๋Š” rabbitMq + springboot + stomp : ํ™˜๊ฒฝ์„ค์ •

๊ฐœ๋ฐœํ•˜๋Š” ์ฃผ๋””์”จ 2023. 4. 18. 13:50

 

์ด๋ฒˆ ํฌ์ŠคํŒ…์€ ๋ณธ๊ฒฉ์ ์œผ๋กœ rabbitMq ํ™˜๊ฒฝ์„ค์ •๊ณผ ๊ตฌํ˜„ํ•  ์•„ํ‚คํ…์ฒ˜๋ฅผ ๋ฏธ๋ฆฌ ์ •์˜ํ•˜๊ณ ์ž ํ•œ๋‹ค.

 

๋จผ์ € ํด๋ผ์ด์–ธํŠธ๋Š” react, angular ๊ฐ™์€ SPA๋ฅผ ์‚ฌ์šฉํ•  ์˜ˆ์ •์ด๋ฉฐ, ์„œ๋ฒ„๋Š” springboot๋กœ ๊ตฌํ˜„ํ•œ๋‹ค. ์ด ์•„ํ‚คํ…์ฒ˜์—์„œ rabbitMq๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ™œ์šฉํ•˜๊ณ ์ž ํ•œ๋‹ค.

 

 

ํฐ ํ๋ฆ„์€ Springboot์—์„œ Publish ๋œ ๋ฉ”์‹œ์ง€๋ฅผ rabbitMq๋กœ send ํ•˜๊ณ , Consumer๋Š” rabbitMq๋กœ๋ถ€ํ„ฐ ๋ฉ”์‹œ์ง€๋ฅผ ์ „๋‹ฌ๋ฐ›์•„ ๋ผ์šด๋“œ๋กœ๋นˆ ๋ฐฉ์‹์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๊ฒŒ ๋œ๋‹ค. ์ด๋•Œ rabbitMq์™€ TCP ํ†ต์‹ ํ•˜๋Š” ํ”„๋กœํ† ์ฝœ์€ AMQP์™€ STOMP๋ฅผ ํ˜ผ์šฉํ•ด์„œ ์‚ฌ์šฉํ•  ๊ฒƒ์ด๋‹ค. ๊ทธ ์ด์œ ๋Š” Springboot์—์„œ rabbitmq์™€ ์—ฐ๋™ํ•  ๋•Œ ์ง€์›๋˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์— STOMP๊ฐ€ ์ง€์›๋˜์ง€ ์•Š์•„ AMQP์™€ ํ˜ผ์šฉํ•˜๊ฒŒ ๋˜์—ˆ๋‹ค. ํ˜น์‹œ ์ง€์›๋˜๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์žˆ๋‹ค๋ฉด ๋Œ“๊ธ€๋กœ ๊ผญ ์•Œ๋ ค์ฃผ์„ธ์š”๐Ÿ˜ข(๋ฉฐ์น ์„ ์‚ฝ์งˆํ•ด๋„ ์—†๋‹ค๋Š” ๊ฒฐ๋ก ์ด ๋‚˜์˜ด.)

 

๐Ÿ”” ๋ผ์šด๋“œ ๋กœ๋นˆ(Round Robin)
RabbitMQ์—์„œ ๋ผ์šด๋“œ ๋กœ๋นˆ์€ ์—ฌ๋Ÿฌ ์ปจ์Šˆ๋จธ ์ค‘์—์„œ ๋ฉ”์‹œ์ง€๋ฅผ ๊ท ๋“ฑํ•˜๊ฒŒ ๋ถ„๋ฐฐํ•˜์—ฌ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐฉ์‹์„ ๋งํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ํ์— ์—ฌ๋Ÿฌ ๋ฉ”์‹œ์ง€๊ฐ€ ์žˆ๊ณ  ๋‘ ๊ฐœ์˜ ์ปจ์Šˆ๋จธ๊ฐ€ ๋ฉ”์‹œ์ง€๋ฅผ ์ฒ˜๋ฆฌํ•œ๋‹ค๊ณ  ๊ฐ€์ •ํ•ด ๋ณด๋ฉด, ๋ผ์šด๋“œ ๋กœ๋นˆ ๋ฐฉ์‹์—์„œ๋Š” ๋ฉ”์‹œ์ง€๋ฅผ ์ˆœ์ฐจ์ ์œผ๋กœ ์ปจ์Šˆ๋จธ์—๊ฒŒ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ๋‘ ์ปจ์Šˆ๋จธ ๋ชจ๋‘ ๋ฉ”์‹œ์ง€๋ฅผ ๊ณตํ‰ํ•˜๊ฒŒ ์ฒ˜๋ฆฌํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

๋ผ์šด๋“œ ๋กœ๋นˆ ๋ฐฉ์‹์€ ๊ธฐ๋ณธ์ ์œผ๋กœ RabbitMQ์—์„œ ์‚ฌ์šฉ๋˜๋Š” ๋ฉ”์‹œ์ง€ ์ „๋‹ฌ ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ๋ณ„๋„์˜ ์„ค์ •์ด๋‚˜ ์ฝ”๋“œ ๋ณ€๊ฒฝ ์—†์ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ์ปจ์Šˆ๋จธ์˜ ์ฒ˜๋ฆฌ ๋Šฅ๋ ฅ์— ๋”ฐ๋ผ ๋ฉ”์‹œ์ง€ ์ฒ˜๋ฆฌ ์†๋„๊ฐ€ ์ฐจ์ด๊ฐ€ ์žˆ์„ ๊ฒฝ์šฐ์—๋Š” ํ•œ ์ชฝ ์ปจ์Šˆ๋จธ์—๊ฒŒ ๋ฉ”์‹œ์ง€๊ฐ€ ๋ชฐ๋ฆฌ๋Š” ํ˜„์ƒ์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฐ ๊ฒฝ์šฐ์—๋Š” RabbitMQ์—์„œ ์ œ๊ณตํ•˜๋Š” ๋‹ค๋ฅธ ๋ฐฉ์‹์˜ ๋ฉ”์‹œ์ง€ ์ „๋‹ฌ ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜, ์ปจ์Šˆ๋จธ ์ธก์—์„œ ์ฒ˜๋ฆฌ ๋Šฅ๋ ฅ์„ ๋†’์ด๋Š” ๋Œ€์•ˆ์„ ๊ณ ๋ คํ•ด ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 


RabbitMq ์„ค์น˜

์„ค์น˜๊ณผ์ •์—์„œ Erlang๊ณผ RabbitMq ๊ทธ๋ฆฌ๊ณ  Springboot์˜ ๋ฒ„์ „๋•Œ๋ฌธ์— ๊ฝค ์˜ค๋žœ์‹œ๊ฐ„ ์‚ฝ์งˆ์„ ํ–ˆ๋‹ค;;; ๋ฒ„์ „์ด ๋งž์ง€ ์•Š์œผ๋ฉด ์•„์–˜ ๋™์ž‘ํ•˜์ง€ ์•Š์œผ๋‹ˆ ๋ฒ„์ „์— ์œ ์˜ํ•ด์„œ ํ™˜๊ฒฝ์„ค์ •์„ ํ•ด์•ผํ•œ๋‹ค.

 

RabbitMQ๋Š” Erlang OTP ํ”Œ๋žซํผ ์œ„์— ๊ตฌ์ถ•๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— RabbitMQ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋จผ์ € Erlang์„ ์„ค์น˜ํ•ด์•ผ ํ•œ๋‹ค. Springboot ๋ฒ„์ „์— ๋”ฐ๋ผ ํ˜ธํ™˜๋˜๋Š” Erlang๊ณผ RabbitMQ ๋ฒ„์ „์ด ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์— ๊ผญ ํ™•์ธ์ด ํ•„์š”ํ•˜๋‹ค. ๋‚˜๋Š” Springboot 2.7.7 ๊ธฐ์ค€์œผ๋กœ ์ž‘์„ฑ๋˜์—ˆ๋‹ค. Erlang์— ํ˜ธํ™˜๋˜๋Š” RabbitMQ ๋ฒ„์ „์€ RabbitMQ ํ™ˆํŽ˜์ด์ง€์—์„œ ํ™•์ธ ๊ฐ€๋Šฅํ•˜๋‹ค.


* RabbitMQ Erlang Version Requirements :
https://www.rabbitmq.com/which-erlang.html

 

RabbitMQ Erlang Version Requirements — RabbitMQ

RabbitMQ Erlang Version Requirements This guide covers Erlang/OTP version requirements, Erlang version support policy, a RabbitMQ/Erlang compatibility matrix, version-specific notes and ways of provisioning recent Erlang/OTP releases. RabbitMQ supports up

www.rabbitmq.com

๐Ÿ””Erlang
Erlang์€ Ericsson์—์„œ ๊ฐœ๋ฐœํ•œ ํ•จ์ˆ˜ํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์ด๋ฉฐ, ๋ถ„์‚ฐ ์‹œ์Šคํ…œ๊ณผ ์‹ค์‹œ๊ฐ„ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์— ์ ํ•ฉํ•œ ์–ธ์–ด๋กœ ์•Œ๋ ค์ ธ ์žˆ์Šต๋‹ˆ๋‹ค. ํŠนํžˆ, ๋งŽ์€ ์‚ฌ์šฉ์ž๊ฐ€ ๋™์‹œ์— ์ ‘์†ํ•˜๋Š” ๋Œ€๊ทœ๋ชจ ์„œ๋ฒ„ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์— ์ ํ•ฉํ•˜๋ฉฐ, ์•ˆ์ •์„ฑ๊ณผ ํ™•์žฅ์„ฑ์ด ๋›ฐ์–ด๋‚˜๋‹ค๋Š” ํŠน์ง•์ด ์žˆ์Šต๋‹ˆ๋‹ค. Erlang์€ OTP(Open Telecom Platform)๋ผ๋Š” ํ”„๋ ˆ์ž„์›Œํฌ์™€ ํ•จ๊ป˜ ์‚ฌ์šฉ๋˜์–ด ๋„คํŠธ์›Œํฌ ํ†ต์‹ , ๋ถ„์‚ฐ ์ฒ˜๋ฆฌ, ๋ณ‘๋ ฌ ์ฒ˜๋ฆฌ ๋“ฑ์„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

1. Erlang ์„ค์น˜

Next ๋ˆŒ๋Ÿฌ ๊ธฐ๋ณธ์œผ๋กœ ์„ค์น˜ํ•ด์ค€๋‹ค. ๊ผญ C ๋“œ๋ผ์ด๋ธŒ์— ์„ค์น˜ํ•ด์ค€๋‹ค..! ์™ ๋งŒํ•˜๋ฉด D ๋“œ๋ผ์ด๋ธŒ์— ์„ค์น˜ํ•˜๋Š” ๊ฒƒ์„ ์„ ํ˜ธํ•˜๋Š” ํŽธ์ด์ง€๋งŒ Erlang, Java์™€ ๊ฐ™์€ Develop Kit๋“ค์€ C ๋“œ๋ผ์ด๋ธŒ์— ์„ค์น˜ํ•œ๋‹ค. ๋‚˜์ค‘์— ๊ณ ์ƒํ•˜๊ณ  ์‹ถ์ง€ ์•Š์œผ๋ฉด,.. C ๋“œ๋ผ์ด๋ธŒ์— ์„ค์น˜ํ•˜์ž.

 

2. ํ™˜๊ฒฝ๋ณ€์ˆ˜

์œˆ๋„์šฐ CMD์—์„œ Erlang์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ์‹œ์Šคํ…œ ํ™˜๊ฒฝ๋ณ€์ˆ˜ Path๋ฅผ \bin ๊ฒฝ๋กœ๋กœ ์žก์•„์ค€๋‹ค. 

 

3. RabbitMq ์„ค์น˜

* rabbitMq install : https://www.rabbitmq.com/download.html

 

Downloading and Installing RabbitMQ — RabbitMQ

Downloading and Installing RabbitMQ The latest release of RabbitMQ is 3.11.13. See change log for release notes. See RabbitMQ support timeline to find out what release series are supported. Experimenting with RabbitMQ on your workstation? Try the community

www.rabbitmq.com

์›ํ•˜๋Š” ๋ฒ„์ „์„ ์„ ํƒํ•ด install ํ•ด์ค€๋‹ค. Erlang ์„ค์น˜์™€ ๋™์ผํ•˜๊ฒŒ Next ๋กœ ์„ค์น˜ํ•ด์ค€๋‹ค. ์„ค์น˜๊ฐ€ ๋๋‚˜๋ฉด server๊ฐ€ ์ž๋™์‹คํ–‰๋œ๋‹ค.

 

rabbitMQ Command๋ฅผ ์—ด์–ด rabbitMq์— ๋Œ€ํ•œ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค. ์•ž์œผ๋กœ CMD๋ผ๊ณ  ์นญํ•˜๋Š” ๊ฒƒ์ด Command Prompt๋ผ๊ณ  ์ƒ๊ฐํ•˜๋ฉด ๋œ๋‹ค. 

 

4. rabbitMq Manager UI ํ”Œ๋Ÿฌ๊ทธ์ธ ์„ค์น˜

rabbitMq๋Š” ctl ๋ฐฑ๊ทธ๋ผ์šด๋“œ์—์„œ ์„œ๋น„์Šค ๋˜๋ฏ€๋กœ ๋ˆˆ์œผ๋กœ ํ™•์ธ์ด ์–ด๋ ต๋‹ค. ๋”ฐ๋ผ์„œ ํ”Œ๋Ÿฌ๊ทธ์ธ ์„ค์น˜ํ•ด Manager ๋Œ€์‹œ๋ณด๋“œ๋กœ ํŽธ๋ฆฌํ•˜๊ฒŒ ์‚ฌ์šฉํ•œ๋‹ค. ์œ„์—์„œ ๋งํ–ˆ๋˜ Command Prompt ๋ฅผ ์‹คํ–‰ํ•ด ์•„๋ž˜ ๋ช…๋ น์–ด๋กœ ์„ค์น˜ํ•˜์ž.

rabbitmq-plugins enable rabbitmq_management

์„ค์น˜๋ฅผ ์™„๋ฃŒํ–ˆ์œผ๋ฉด http://localhost:15672/๋ฅผ ํ†ตํ•ด ๋กœ๊ทธ์ธ ํ™”๋ฉด์œผ๋กœ ์ ‘์†ํ•œ๋‹ค. ๋งŒ์•ฝ, ์ด ํ™”๋ฉด์ด ์ •์ƒ์ ์œผ๋กœ ๋‚˜์˜ค์ง€ ์•Š๋Š”๋‹ค๋ฉด? Erlang ๋ฒ„์ „๊ณผ RabbitMq ๋ฒ„์ „์ด ๋งž์ง€ ์•Š์•„ ์ œ๋Œ€๋กœ ์„œ๋น„์Šค๊ฐ€ ์‹คํ–‰๋˜์ง€ ์•Š์•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. ์ •์ƒ์ ์œผ๋กœ ์„ค์น˜๊ฐ€ ๋˜์—ˆ์ง€๋งŒ ๋ฒ„์ „์ด ๋งž์ง€ ์•Š์œผ๋ฉด localhost๊ฐ€ ์‹คํ–‰๋˜์ง€ ์•Š์œผ๋‹ˆ ๋ฐ˜๋“œ์‹œ RabbitMq ํ™ˆํŽ˜์ด์ง€์—์„œ ๋ฒ„์ „ ์ฒดํฌ๋ฅผ ํ•ด์•ผํ•œ๋‹ค.

 

๋‚˜๋Š” ์ด๊ฑธ๋กœ ์ผ์ฃผ์ผ์„ ์‚ฝ์งˆํ•˜๊ณ  ์•ฝ 8๋ฒˆ์˜ ์„ค์น˜๊ณผ์ •์„ ๋ฐ˜๋ณตํ–ˆ๋‹ค;;; ๋ฒ„์ „์„ ๋งž์ถ”์—ˆ๋Š”๋ฐ๋„ localhost๋กœ ์ ‘์†๋˜์ง€ ์•Š๋Š”๋‹ค๋ฉด ์„œ๋ฒ„๊ฐ€ ์‹คํ–‰์ค‘์ธ์ง€ ์ฒดํฌํ•ด๋ณด๊ณ  ์„œ๋ฒ„ ์žฌ๊ธฐ๋™๊ณผ ์ปดํ“จํ„ฐ ์žฌ๋ถ€ํŒ… ๋“ฑ๋“ฑ ๋‹ค์–‘ํ•œ ๋ฐฉ๋ฒ•์œผ๋กœ ์‹œ๋„ํ•ด๋ด์•ผ ํ•œ๋‹ค. RabbitMq์— ๋Œ€ํ•œ ์ž๋ฃŒ๊ฐ€ ์นœ์ ˆํ•˜๊ฑฐ๋‚˜ ๊ต๋ณด์žฌ๊ฐ€ ๋งŽ๋‹ค๋ฉด ์ด๋Ÿฐ ์‚ฝ์งˆ์„ ํ•˜์ง€ ์•Š์•˜๊ฒ ์ง€๋งŒ ๋งŽ์€ ๊ตฌ๊ธ€๋ง๊ณผ ํฌ์ŠคํŒ…์„ ๋ด๋„ ์˜ˆ์ƒ์น˜๋ชปํ•œ ๋ฌธ์ œ๊ฐ€ ๋งŽ์•˜๋‹ค. ๋‚˜๋„ ์ด๋ฒˆ์— RabbitMq๋ฅผ ์ œ๋Œ€๋กœ ๋ชจ๋ฅด๊ณ  ๊ณต๋ถ€ํ•˜๋ฉด์„œ ์‚ฝ์งˆํ•œ ๊ณผ์ •์„ ํฌ์ŠคํŒ…ํ•˜๋Š” ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— ์ด๊ฒƒ์ด ๋ฌด์กฐ๊ฑด ์ •๋‹ต์€ ์•„๋‹ ๊ฑฐ๋ผ๊ณ  ์ƒ๊ฐํ•œ๋‹ค. ๋”ฐ๋ผ์„œ ์ข‹์€ ์˜๊ฒฌ์ด ์žˆ๋‹ค๋ฉด ์–ธ์ œ๋“  ๋Œ“๊ธ€๋กœ ๋‹ฌ์•„์ฃผ์„ธ์š” :)

 

 

์ด ํ™”๋ฉด์„ ๋ณด์•˜๋‹ค๋ฉด RabbitMq ์„ค์น˜ ํ›„ ๊ธฐ๋ณธ ๊ณ„์ •์ธ guest/guest ๋กœ ๋กœ๊ทธ์ธํ•  ์ˆ˜ ์žˆ๋‹ค.