0Pricing
Advanced Spring Boot 4: Event-Driven Architecture (Kafka) · บทเรียน

เหตุการณ์ ผู้ผลิต และผู้บริโภค

เจาะลึกองค์ประกอบพื้นฐานของ EDA ได้แก่ เหตุการณ์ในฐานะข้อเท็จจริงที่เปลี่ยนแปลงไม่ได้ ผู้ผลิตที่สร้างเหตุการณ์ และผู้บริโภคที่ตอบสนองต่อเหตุการณ์

เหตุการณ์ ผู้ผลิต และผู้บริโภค เป็นบทเรียน Advanced Spring Boot 4: Event-Driven Architecture (Kafka) ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Advanced Spring Boot 4: Event-Driven Architecture (Kafka) และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Advanced Spring Boot 4: Event-Driven Architecture (Kafka) มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Welcome to the Core!

Time for EDA's building blocks: events, producers, and consumers. Get these and you can build scalable, reactive systems.

What is an Event?

An event is a notification that something significant happened — an immutable, past-tense fact like 'OrderCreated'. It states facts, never commands.

Event Characteristics

Events behave like historical records: immutable once published, atomic (one complete occurrence), and decoupled — the event never knows who will process it.

Anatomy of an Event

An event typically carries a timestamp, an event type, a unique ID, and a payload — just enough data for consumers to react meaningfully.

Event Data Example

An event is really just a data structure. This snippet shows a simple Java OrderCreatedEvent POJO holding the facts — run it to see one created.

public class Main {
  // Define an 'Event' as a simple data holder
  static class OrderCreatedEvent {
    String orderId;
    String customerId;
    double amount;
    long timestamp;

    public OrderCreatedEvent(String orderId, String customerId, double amount) {
      this.orderId = orderId;
      this.customerId = customerId;
      this.amount = amount;
      this.timestamp = System.currentTimeMillis();
    }

    @Override
    public String toString() {
      return "OrderCreatedEvent{" +
             "orderId='" + orderId + '\'' +
             ", customerId='" + customerId + '\'' +
             ", amount=" + amount +
             ", timestamp=" + timestamp +
             '}';
    }
  }

  public static void main(String[] args) {
    // Create an instance of our event
    OrderCreatedEvent event = new OrderCreatedEvent("ORD-12345", "CUST-67890", 99.99);

    // Print the event details
    System.out.println("New Event Created:");
    System.out.println(event);
  }
}

What is a Producer?

A producer is any service that generates and publishes events. When something happens — say a user places an order — the producer emits the event for it.

Producer's Role

A producer just announces facts: it creates an event and publishes it to a broker like Kafka. It's fully decoupled — it has no idea who's listening.

What is a Consumer?

A consumer subscribes to events and reacts to them. When an event is published, any interested consumer picks it up and runs its own logic.

Consumer's Role

Consumers are the reactive side: they subscribe to event types, run business logic in response, and work independently of one another.

The Event Flow

The flow is simple: Producer → Event → Consumer. One OrderCreated event can trigger a Notification service and an Inventory service at once — fully decoupled.

Quick Check

Let's test your understanding of events in EDA.

Recap & Next Steps

You've got EDA's core: events (immutable facts), producers (emit them), and consumers (react). Next: where EDA truly shines.

คำถามที่พบบ่อย

บทเรียน “เหตุการณ์ ผู้ผลิต และผู้บริโภค” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “เหตุการณ์ ผู้ผลิต และผู้บริโภค” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Advanced Spring Boot 4: Event-Driven Architecture (Kafka) ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Advanced Spring Boot 4: Event-Driven Architecture (Kafka) มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “เหตุการณ์ ผู้ผลิต และผู้บริโภค”

เจาะลึกองค์ประกอบพื้นฐานของ EDA ได้แก่ เหตุการณ์ในฐานะข้อเท็จจริงที่เปลี่ยนแปลงไม่ได้ ผู้ผลิตที่สร้างเหตุการณ์ และผู้บริโภคที่ตอบสนองต่อเหตุการณ์ คุณปฏิบัติ Advanced Spring Boot 4: Event-Driven Architecture (Kafka) ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Advanced Spring Boot 4: Event-Driven Architecture (Kafka) หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Advanced Spring Boot 4: Event-Driven Architecture (Kafka) บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน

บทเรียน “เหตุการณ์ ผู้ผลิต และผู้บริโภค” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Advanced Spring Boot 4: Event-Driven Architecture (Kafka) นี้ได้ไหม

ได้ บทเรียน Advanced Spring Boot 4: Event-Driven Architecture (Kafka) ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. ทำความเข้าใจหลักการของ EDA
  2. เหตุการณ์ ผู้ผลิต และผู้บริโภค
  3. ประโยชน์และกรณีใช้งานของ EDA
  4. การแจ้งเตือนเหตุการณ์ปะทะการถ่ายโอนสถานะ
← กลับไปที่ Advanced Spring Boot 4: Event-Driven Architecture (Kafka)