Connection-lifecycle

#rabbitmq

What is the [[Connection]] lifecycle?

Content

Application configures the client library it uses to use a certain connection endpoint (e.g. hostname and port)

  1. ํด๋ผ์ด์–ธํŠธ(์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜)๊ฐ€ ์‚ฌ์šฉํ•  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์„ค์ •. (ํ˜ธ์ŠคํŠธ๋„ค์ž„, ํฌํŠธ๋“ฑ์˜ ์ •๋ณด๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ)

The library resolves the hostname to one or more IP addresses

  1. ํ•ด๋‹น ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ํ˜ธ์ŠคํŠธ๋ฅผ ํ•˜๋‚˜ ์ด์ƒ์˜ IP๋กœ ํ™•์ธ (Health check?)

The library opens a TCP connection to the target IP address and port

  1. ํ•ด๋‹น ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ทธ TCP ์ปค๋„ฅ์…˜์„ ์˜คํ”ˆ.

After the server has accepted the TCP connection, protocol-specific negotiation procedure is performed

  1. ํด๋ผ์ด์–ธํŠธ์—์„œ ์˜คํ”ˆํ•œ ์ปค๋„ฅ์…˜์ด ์„œ๋ฒ„๊ฐ€ ๋ฐ›์•„์ง„๋‹ค์Œ์—, ํŠน์ • ํ”„๋กœํ† ์ฝœ ์ ˆ์ฐจ๊ฐ€ ์‹คํ–‰๋จ.

    • AMQP 0-9-1, AMQP 1.0

The server then authenticates the client

  1. ๊ทธ๋ฆฌ๊ณ  ์„œ๋ฒ„๋Š” ํด๋ผ์ด์–ธํŠธ๋ฅผ ์‹ ๋ขฐํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ์ธ์ฆํ•จ.

The client now can perform operations, each of which involves an authorisation check by the server.

  1. ์ธ์ฆ์ด ๋๋‚˜๋ฉด, ํด๋ผ์ด์–ธํŠธ๋Š” ์ž‘์—…(e.g. publish, consume..) ์„ ํ•  ์ˆ˜ ์žˆ๊ณ  ๊ฐ ์ž‘์—…์— ์„œ๋ฒ„๊ฐ€ ๊ถŒํ•œ์„ ํ™•์ธํ•˜๊ณ  ์žˆ์Œ.

The client retains the connections for as long as it needs to communicate with RabbitMQ

  1. ํด๋ผ์ด์–ธํŠธ๋Š” rabbitmq์™€ ํ†ต์‹ ์ด ํ•„์š”ํ• ๋•Œ๊นŒ์ง€ ์ปค๋„ฅ์…˜์„ ๊ณ„์† ์œ ์ง€ํ•จ

extra..

  • ์ปค๋„ฅ์…˜ ๋ผ์ดํ”„์‚ฌ์ดํด์˜ ๊ฒฝ์šฐ, ํ”„๋กœํ† ์ฝœ๋ณ„๋กœ ์•ฝ๊ฐ„์˜ ๋ณ€ํ™”๋Š” ์žˆ์ง€๋งŒ, ํฐ ๋ณ€ํ™”๋Š” ์—†์Œ.

Extra

๋ฌธ์ œ์ƒํ™ฉ

  • RabbitMQ Queue ์ƒ์„ฑ -> Spring boot application ์‹คํ–‰(ํด๋ผ์ด์–ธํŠธ)

  • ํด๋ผ์ด์–ธํŠธ์—์„œ ๋ฉ”์„ธ์ง€๋ฅผ publish ํ•˜๋ ค ํ•  ๋•Œ ์‹œ๋„ํ•˜๋Š” ์ปค๋„ฅ์…˜์ด ๋งบ์–ด์ง€์ง€ ์•Š์•˜์Œ. ์™œ?

  • ๊ทธ๋Ÿฐ๋ฐ rabbitmq cli๋ฅผ ํ†ตํ•ด ์ž„์˜๋กœ ํ•ด๋‹น queue ๋ฉ”์„ธ์ง€๋ฅผ ์ƒ์„ฑ ํ›„, ํด๋ผ์ด์–ธํŠธ์™€ ์ปค๋„ฅ์…˜์ด ๋งบ์–ด์ง.

  • ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ๋กœ๋”ฉ ์‹œ์ ์— ์ปค๋„ฅ์…˜์ด rabbitmq node์™€ ์ž๋™์œผ๋กœ ๋งบ์–ด์ง€์ง€ ์•Š๋‚˜?

  • ์žฌ๋ฐœ์ƒํ•˜๋ฉด ๋กœ๊ทธ๋ฅผ ์ž์„ธํžˆ ๋ด์•ผํ• ๋“ฏ.

    • ์–ด๋–ค ํ”„๋กœํ† ์ฝœ์„ ์‚ฌ์šฉํ•˜๋Š” ์ง€

    • ํด๋ผ์ด์–ธํŠธ์—์„œ ์ปค๋„ฅ์…˜์„ ๋งบ์œผ๋ ค๊ณ  ํ•  ๋•Œ, ์–ด๋–ค ๋กœ๊ทธ๊ฐ€ ๋‚˜์˜ค๋Š”์ง€ (์„ฑ๊ณต, ์‹œ๋„, ์‹คํŒจ..)

References

  • https://www.rabbitmq.com/connections.html#lifecycle

  • https://en.wikipedia.org/wiki/Polling_(computer_science)

Last updated