๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Cloud

[GCP] Pub/Sub ์ •์˜์™€ Push& Pull ์ฐจ์ด | LIM

by forestlim 2023. 1. 7.
728x90
๋ฐ˜์‘ํ˜•

๐Ÿง Cloud Pub/Sub ์ด๋ž€

๋Œ€์šฉ๋Ÿ‰ ๋ถ„์‚ฐ ํ ์„œ๋น„์Šค์ด๋ฉฐ ๋ฉ”์‹œ์ง• ์‹œ์Šคํ…œ์ด๋‹ค. ๋ฉ”์‹œ์ง€๋ฅผ Queue์— ์Œ“์•„๋‘๋Š” ํ† ํ”ฝ์„ ์ƒ์„ฑํ•˜๊ณ  ๊ทธ ํ† ํ”ฝ์„ ๊ตฌ๋…ํ•˜๋Š” ๊ตฌ๋…์ž๋ฅผ ๋งŒ๋“ค์–ด ๋ฉ”์‹œ์ง€๋ฅผ ์†Œ๋น„ํ•˜๋Š” ์‹œ์Šคํ…œ์ด๋‹ค. Pub/Sub์„ ํ†ตํ•ด ์„œ๋น„์Šค๋Š” ๋น„๋™๊ธฐ์ ์œผ๋กœ 100๋ฐ€๋ฆฌ ์ดˆ์˜ ์ง€์—ฐ ์‹œ๊ฐ„์œผ๋กœ ํ†ต์‹ ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

๐Ÿ“ Cloud Pub/Sub ์˜ ํ•ต์‹ฌ ๊ฐœ๋…

Topic: ๊ฒŒ์‹œ์ž๊ฐ€ ๋ฉ”์‹œ์ง€๋ฅผ ์ „์†กํ•˜๋Š” ๋ฆฌ์†Œ์Šค

 

Message: ๊ฒŒ์‹œ์ž๊ฐ€ Topic ์— ์ „๋‹ฌํ•ด ๊ฒฐ๊ณผ์ ์œผ๋กœ ๊ตฌ๋…์ž์—๊ฒŒ ์ „๋‹ฌ๋˜๋Š” ๋ฐ์ดํ„ฐ์™€ ์†์„ฑ์˜ ์กฐํ•ฉ

 

Subscriber: ๋‹จ์ผ ๋˜๋Š” ๋‹ค์ค‘ ์ฃผ์ œ์— ๋Œ€ํ•œ ๊ตฌ๋…์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฉ”์‹œ์ง€๋ฅผ ์ˆ˜์‹ ํ•˜๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜

 

Acknowledgement(or "Ack"): Subscriber ๊ฐ€ ๋ฉ”์‹œ์ง€๋ฅผ ์ •์ƒ์ ์œผ๋กœ ์ˆ˜์‹ ํ•œ ํ›„ ๊ตฌ๋…์ž๊ฐ€ Pub/Sub ์— ๋ณด๋‚ด๋Š” ์‹ ํ˜ธ. ์ด Ack์„ ๋ฐ›์•„ ํ™•์ธ๋œ ๋ฉ”์‹œ์ง€๋Š” ๊ตฌ๋…๋ฉ”์‹œ์ง€ ํ์—์„œ ์‚ญ์ œ๋œ๋‹ค. 

 

Push and Pull: ๋‘ ๊ฐ€์ง€ ๋ฉ”์‹œ์ง€ ์ „์†ก๋ฐฉ๋ฒ•. Push์˜ ๊ฒฝ์šฐ ๊ตฌ๋…์ž๊ฐ€ ์„ ํƒํ•œ ์—”๋“œํฌ์ธํŠธ๋กœ Pub/Sub ์ด ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋‚ด๋Š”๊ฒƒ. Pull์˜ ๊ฒฝ์šฐ ๊ตฌ๋…์ž๊ฐ€ ๋ฉ”์‹œ์ง€๋ฅผ Pull ํ•˜๋Š” ๊ฒƒ

 

๊ทธ์ค‘ ๋‚˜๋Š” Push์™€ Pull์˜ ๊ฐœ๋…์ด ์กฐ๊ธˆ ํ—ท๊ฐˆ๋ ธ๋‹ค. 

 

โœ”๏ธ Push/Pull ๊ตฌ๋… ๋ฐฉ๋ฒ•

์•„๋ž˜ ํ•˜์ด๋ผ์ดํŠธํ•œ ๋ถ€๋ถ„์ด ํ•ต์‹ฌ์ธ ๊ฒƒ ๊ฐ™๋‹ค. 

 

Pull: Subscriber ๊ฐ€ Message ๋ฅผ ์š”์ฒญํ•  ๋•Œ ์ „๋‹ฌ๋ฐ›๋Š” ๊ตฌ๋… ๋ฐฉ์‹

์ฆ‰, ๊ทธ๋ฆผ๊ณผ ๊ฐ™์ด Pull ๋ฐฉ์‹์€ ์‚ฌ์šฉ์ž๊ฐ€ ๋ฐ์ดํ„ฐ๋ฅผ ์š”์ฒญํ•˜๋ฉด Pub/Sub ์—์„œ ๋ณด๋‚ด์ฃผ๋Š” ํ˜•์‹์ด๊ณ  Subscriber ์—๊ฒŒ์„œ Ack์„ ๋ฐ›์œผ๋ฉด ๋ฉ”์‹œ์ง€๋Š” ์‚ญ์ œ๋œ๋‹ค. 

 

 

Push: Message ๊ฐ€ ์˜ค๋ฉด ๋ฐ”๋กœ Subscriber ์—๊ฒŒ ์ „๋‹ฌ๋˜๋Š” ๋ฐฉ์‹

 

Push ๋ฐฉ์‹์€ Topic ์œผ๋กœ ๋ฐ์ดํ„ฐ๊ฐ€ ์ „์†ก๋˜์ž๋งˆ์ž Subscriber์—๊ฒŒ ๋ฐ”๋กœ ๋ณด๋‚ด์ฃผ๊ณ  Subscriber ๊ฐ€ Ack์„ ์ „์†กํ•˜๋ฉด ๋ฉ”์‹œ์ง€๋Š” ์‚ญ์ œ๋œ๋‹ค. 

GCP์˜ EventArc ์„œ๋น„์Šค๊ฐ€ ์žˆ๋Š”๋ฐ ์ด ์„œ๋น„์Šค๊ฐ€ ๋ฐ”๋กœ Push ๋ฐฉ์‹์œผ๋กœ ์ž‘๋™๋œ๋‹ค. 

๋ฐ”๋ผ๋ณด๊ณ  ์žˆ๋Š” ํŠน์ • cloud ์„œ๋น„์Šค์— ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ํ•ด๋‹น ์ด๋ฒคํŠธ์— ๋Œ€ํ•œ ๋ฉ”์‹œ์ง€๋ฅผ Subscriber์—๊ฒŒ ๋ณด๋‚ธ๋‹ค. 

 

EventArc์— ๋Œ€ํ•ด ๊ถ๊ธˆํ•˜๋‹ค๋ฉด ์ด ํฌ์ŠคํŠธ๋ฅผ ์ฝ์–ด๋ณด๋ฉด ์ข‹๋‹ค. ๊ฐœ์ธ์ ์œผ๋กœ ๊ตฌ๊ธ€ ์„œ๋น„์Šค๋Š” ์ด ๋ถ„ ๋ธ”๋กœ๊ทธ๋ฅผ ๋ณด๋ฉด์„œ ๋งŽ์ด ๋ฐฐ์› ๋‹ค. ํ˜„์žฌ EventArc๋ฅผ ์‚ฌ์šฉํ•ด ์ฃผ๊ธฐ์ ์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ณ  ์žˆ๋Š”๋ฐ ํ•ด๋‹น ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋ฉด์„œ ์‚ฌ์šฉํ–ˆ๋˜ EventArc์— ๋Œ€ํ•œ ๊ธ€์„ ๋” ์ž์„ธํžˆ ์จ๋ด์•ผ๊ฒ ๋‹ค.

https://medium.com/google-cloud-apac/gcp-serverless-%EC%84%9C%EB%B9%84%EC%8A%A4%EC%9D%B8-cloud-run-%EC%95%8C%EC%95%84%EB%B3%B4%EA%B8%B0-5%EB%B6%80-eventarc-%EB%A5%BC-%ED%86%B5%ED%95%9C-%EC%9D%B4%EB%B2%A4%ED%8A%B8-%EB%B0%9B%EA%B8%B0-f0771b656c4f

 

[GCP]Serverless ์„œ๋น„์Šค์ธ Cloud Run ์•Œ์•„๋ณด๊ธฐ 5๋ถ€โ€Š—โ€ŠEventarc ๋ฅผ ํ†ตํ•œ ์ด๋ฒคํŠธ ๋ฐ›๊ธฐ

์•ˆ๋…•ํ•˜์„ธ์š” ์ด์ •์šด ์ž…๋‹ˆ๋‹ค.

medium.com

 

๐Ÿ“Cloud Pub/Sub ์„ค์ • ์š”์†Œ

๋งˆ์ง€๋ง‰์œผ๋กœ Pub/Sub์˜ setting ์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด์ž.

 

โœ”๏ธ Ack Deadline

  • How long Pub/Sub waits for the subscriber to acknowledge receipt before resending the message
  • Pub/Sub ์ด subscriber ์˜ ack message๋ฅผ ์–ผ๋งˆํผ๊นŒ์ง€ ๊ธฐ๋‹ค๋ฆฌ๊ฒŒ ํ•  ๊ฑด์ง€์— ๋Œ€ํ•œ ์„ค์ •์ด๋‹ค.
  • 10s ~ 600s(10m) ๊นŒ์ง€ ์„ค์ • ๊ฐ€๋Šฅํ•˜๋‹ค.
  • 10s๋กœ ๋„ˆ๋ฌด ์งง์œผ๋ฉด ๊ทธ ์‚ฌ์ด ack์„ ๋ฐ›์ง€ ๋ชปํ•ด ์ค‘๋ณต๋œ ๋ฉ”์‹œ์ง€๊ฐ€ ์—ฌ๋Ÿฌ ๋ฒˆ ๋ฐœํ–‰๋  ์ˆ˜ ์žˆ์œผ๋‹ˆ ๊ตฌํ˜„ํ•œ ์„œ๋น„์Šค์— ๋งž๊ฒŒ ์ž˜ ์กฐ์ ˆํ•˜๋„๋ก ํ•ด์•ผ ํ•œ๋‹ค.

โœ”๏ธ Dead Letter

  • Pub/Sub ์„œ๋น„์Šค๊ฐ€ ๋ฉ”์‹œ์ง€๋ฅผ ์ „๋‹ฌํ•˜๋ ค๊ณ  ํ•˜์ง€๋งŒ ๊ตฌ๋…์ž๊ฐ€ ์ด๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์—†๋Š” ๊ฒฝ์šฐ Pub/Sub๋Š” ์ „๋‹ฌํ•  ์ˆ˜ ์—†๋Š” ๋ฉ”์‹œ์ง€๋ฅผ ๋ฐ๋“œ ๋ ˆํ„ฐ ์ฃผ์ œ๋กœ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๋‹ค.

โœ”๏ธ Retention

  • Retain unacknowledged messages for a specified duration. If retain acknowledged messages is enabled, acknowledged messages are retained for the same duration.
  • subscriber๋กœ๋ถ€ํ„ฐ ์ •์ƒ์ ์ธ ack์„ ๋ฐ›์ง€ ๋ชปํ•œ ๋ฉ”์‹œ์ง€๋“ค(์ฆ‰ ์ „์†ก๋˜์ง€ ์•Š์•˜๋‹ค๊ณ  ์—ฌ๊ฒจ์ง€๋Š” ๋ฉ”์‹œ์ง€๋“ค)์„ ์–ผ๋งˆํผ ๋™์•ˆ ๋ณด๊ด€ํ•˜๊ณ  ์žˆ์„ ๊ฒƒ์ธ๊ฐ€์— ๋Œ€ํ•œ ์„ค์ •์ด๋‹ค.

โœ”๏ธ Backoff(Retry Policy)

  • ์žฌ์‹œ๋„ ์ •์ฑ… ์ค‘ ํ•˜๋‚˜๋กœ, ์žฌ์‹œ๋„์— ๋Œ€ํ•œ ํ…€์„ ์„ค์ •ํ•˜๋Š” ์š”์†Œ๋กœ ๋ณด๋ฉด ๋œ๋‹ค.
  • ์ง€์ˆ˜ ๋ฐฑ์˜คํ”„๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์žฌ์‹œ๋„ ์‚ฌ์ด์— ์ ์ง„์ ์œผ๋กœ ์ข€ ๋” ๊ธด ์ง€์—ฐ ์‹œ๊ฐ„์„ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ฒซ ๋ฒˆ์งธ ์ „์†ก ์‹คํŒจ ํ›„ Pub/Sub๋Š” ์ตœ์†Œ ๋ฐฑ์˜คํ”„ ์‹œ๊ฐ„์„ ๊ธฐ๋‹ค๋ฆฐ ํ›„ ์žฌ์‹œ๋„ํ•ฉ๋‹ˆ๋‹ค. ๋ฉ”์‹œ์ง€๊ฐ€ ์—ฐ์†ํ•ด์„œ ์‹คํŒจํ•  ๋•Œ๋งˆ๋‹ค ์ง€์—ฐ ์‹œ๊ฐ„์— ๋” ๋งŽ์€ ์‹œ๊ฐ„์ด ์ตœ๋Œ€ ์ง€์—ฐ ์‹œ๊ฐ„(0~600์ดˆ)๊นŒ์ง€ ์ถ”๊ฐ€๋ฉ๋‹ˆ๋‹ค.

 

์ฐธ๊ณ )

https://cloud.google.com/pubsub/docs/handling-failures

 

๋ฉ”์‹œ์ง€ ์ฒ˜๋ฆฌ ์‹คํŒจ  |  Cloud Pub/Sub  |  Google Cloud

์˜๊ฒฌ ๋ณด๋‚ด๊ธฐ ๋ฉ”์‹œ์ง€ ์ฒ˜๋ฆฌ ์‹คํŒจ ์ปฌ๋ ‰์…˜์„ ์‚ฌ์šฉํ•ด ์ •๋ฆฌํ•˜๊ธฐ ๋‚ด ํ™˜๊ฒฝ์„ค์ •์„ ๊ธฐ์ค€์œผ๋กœ ์ฝ˜ํ…์ธ ๋ฅผ ์ €์žฅํ•˜๊ณ  ๋ถ„๋ฅ˜ํ•˜์„ธ์š”. ๊ตฌ๋…์ž๋Š” ๋‹ค์–‘ํ•œ ์ด์œ ๋กœ ๋ฉ”์‹œ์ง€๋ฅผ ์ฒ˜๋ฆฌํ•˜์ง€ ๋ชปํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ๋ฉ”

cloud.google.com

https://jhryu1208.github.io/gcp/2021/06/29/Cloud_Pub_Sub/

 

[GCP] Cloud Pub/Sub

Contents Cloud Pub/Sub์ด๋ž€? Pub/Sub์˜ ๊ตฌ์„ฑ Pub/Sub ๋ฉ”์‹œ์ง€ ํ๋ฆ„ Pull(๊ฐ€์ ธ์˜ค๊ธฐ)/Push(๋‚ด๋ณด๋‚ด๊ธฐ) ๊ตฌ๋… ๋ฐฉ๋ฒ• ๋ฉ”์‹œ์ง€ ์„œ๋น„์Šค์˜ ์„ฑ๋Šฅ ํŒ๋‹จ Pub/Sub ํ†ตํ•ฉ

jhryu1208.github.io

 

๋‹ค์Œ์—” ๋ฉ”์‹œ์ง€ ํ ํ”Œ๋žซํผ์ธ ์นดํ”„์นด๋กœ ๋ฏธ๋‹ˆ ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•ด๋ด์•ผ๊ฒ ๋‹ค!

728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€