နားလည်ထားရမယ့် အချက်
Redis Stream က ordered entry IDs ပါသော append-only log ဖြစ်ပါတယ်။ Consumer group က messages ကို consumers များကြားခွဲပေးပြီး delivered-but-unacknowledged entries ကို Pending Entries List တွင်ထားပါတယ်။ `XACK`၊ `XPENDING`၊ `XAUTOCLAIM` နဲ့ failure recovery လုပ်နိုင်သော်လည်း handler ကို idempotent ထားရပါတယ်။
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
Tutorial publish jobs ကို `stream:tutorial-events` ထဲ `XADD` လုပ်ပြီး notification group က `XREADGROUP` ဖြင့်ဖတ်မယ်။ Email send success ပြီးမှ `XACK` လုပ်မယ်။ Crashed consumer pending jobs ကို idle threshold နောက် `XAUTOCLAIM` လုပ်ပြီး stream ကို `MAXLEN ~` ဖြင့် bounded ထားမယ်။
အတူတူ စမ်းရေးကြည့်မယ်
XGROUP CREATE stream:tutorial-events notifications $ MKSTREAM
XADD stream:tutorial-events MAXLEN ~ 100000 * type published tutorialId 42
XREADGROUP GROUP notifications worker-1 COUNT 10 BLOCK 5000 STREAMS stream:tutorial-events >
XPENDING stream:tutorial-events notifications
XACK stream:tutorial-events notifications 1787875200000-0
XAUTOCLAIM stream:tutorial-events notifications worker-2 60000 0-0 COUNT 10Group workers များ job ခွဲယူ၊ acknowledge နဲ့ stale pending recovery လုပ်နိုင်မည်။၅ မိနစ် စမ်းကြည့်
At-least-once email worker အတွက် idempotency key နဲ့ dead-letter policy ရေးပါ။
သတိလေးတစ်ချက်
`XREADGROUP` ရပြီးချင်း ACK လုပ်ရင် processing crash အချိန် job ပျောက်သွားပါတယ်။ Side effect success ပြီးမှ ACK လုပ်ပါ။
Redis — Streams — Redis