صندوق الصادر المعاملاتي (Transactional Outbox)
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
make "change state" and "record the event" one atomic step.
الموضوعات المخطط لها
- Write the business row and an outbox row in the same local transaction. Either both exist or neither.
- A separate relay reads unsent outbox rows and publishes them, then marks them sent.
- Delivery becomes at-least-once: the relay may publish, crash, and publish again. Consumers must cope (L04).
- Keep the outbox row small: event id, aggregate id, type, JSON payload, created time, sent flag.
- Use the aggregate id as the Kafka key so one order's events stay ordered.
تفاصيل المخطط المبدئي
عرض عملي
CREATE TABLE outbox (
id UUID PRIMARY KEY, aggregate_id BIGINT NOT NULL,
type TEXT NOT NULL, payload JSONB NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(), sent_at TIMESTAMPTZ);@Transactional
void place(Order o) { repo.save(o); outbox.save(OutboxEvent.of("OrderPlaced", o)); }اختبر فهمك
Why is the outbox write safe where kafka.send was not?
أظهر الإجابة
It is in the same database transaction as the order.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.