Thuta Learning
Redis
IntermediateData & Databasesအခြေခံ

Pub/Sub Messaging

Redisသင်ခန်းစာ 15

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

  • 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/Sub — Redis

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

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

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

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

အလုပ်ဖြစ်ကြောင်း ဒီလိုသိမယ်: Online subscribers များ event ချက်ချင်းရပြီး offline subscriber အတွက် replay မရှိပါ။

နောက်ဆုံးပြင်ဆင်ရက်

Progress ကို ဤ browser (ဤစက်) တွင်သာ သိမ်းထားပါသည်။ အခြားစက်များနှင့် sync မလုပ်ပါ။

ဤသင်ခန်းစာတွင် အမှားတွေ့ပါက အကြောင်းကြားရန်သင့် email app ကို ဤသင်ခန်းစာလိပ်စာ ဖြည့်ပြီးသားဖြင့် ဖွင့်ပေးပါမည် — သင်ကိုယ်တိုင် ပို့မှသာ ပို့မည်ဖြစ်သည်။

Pub/Sub Messaging | Thuta Learning