Thuta Learning
ရှာဖွေရန်
Redis
IntermediateData & Databasesbeginner

Pub/Sub Messaging

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Pub/Sub Messaging concept ကို နားလည်ရှင်းပြနိုင်ရန်
  • နမူနာ Redis command/code ကို ကိုယ်တိုင် run ပြီး output စစ်နိုင်ရန်
  • Tutorial Platform project နှင့် production scenario တွင် မှန်ကန်စွာအသုံးချနိုင်ရန်

နားလည်ထားရမယ့် အချက်

Redis Pub/Sub က publishers ကို subscribers များနှင့် channel ဖြင့်ချိတ်ပေးပါတယ်။ Message history၊ acknowledgement၊ replay မရှိဘဲ subscriber disconnect ဖြစ်နေချိန် message ပျောက်ပါတယ်။ ဒါကြောင့် presence၊ live UI hint နဲ့ disposable notifications အတွက်ကောင်းပြီး reliable jobs/audit events အတွက် Streams သုံးသင့်ပါတယ်။

လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်

Tutorial publish ဖြစ်တဲ့အခါ `tutorial:published` channel သို့ small event ID ပို့ပြီး websocket gateways က subscribe လုပ်မယ်။ Gateway က event ID ဖြင့် durable API data ကိုပြန်ဖတ်မယ်။ Subscriber connection ကို command connection နဲ့သီးခြားထားမယ်။

အတူတူ စမ်းရေးကြည့်မယ်

shell
SUBSCRIBE tutorial:published
PSUBSCRIBE tutorial:*

PUBLISH tutorial:published '{"tutorialId":42,"version":3}'
PUBSUB NUMSUB tutorial:published
You should see
Online subscribers များ event ချက်ချင်းရပြီး offline subscriber အတွက် replay မရှိပါ။

၅ မိနစ် စမ်းကြည့်

Presence indicator နဲ့ payment event နှစ်ခုထဲ ဘယ်ဟာ Pub/Sub သုံးသင့်ကြောင်း reason ရေးပါ။

သတိလေးတစ်ချက်

Pub/Sub message ရောက်တာကို job completed အဖြစ်မယူဆပါနှင့်—acknowledgement မရှိပါ။

Redis — Pub/SubRedis

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Pub/Sub message ရောက်တာကို job completed အဖြစ်မယူဆပါနှင့်—acknowledgement မရှိပါ။
  • နမူနာ command ကို production Redis ပေါ် တိုက်ရိုက်မစမ်းဘဲ local/test instance နဲ့ recoverable data ပေါ်တွင် အရင်အတည်ပြုပါ။

လေ့ကျင့်ခန်း

Presence indicator နဲ့ payment event နှစ်ခုထဲ ဘယ်ဟာ Pub/Sub သုံးသင့်ကြောင်း reason ရေးပါ။

You'll know it worked when: Online subscribers များ event ချက်ချင်းရပြီး offline subscriber အတွက် replay မရှိပါ။

Pub/Sub Messaging | Thuta Learning