Event Driven Architecture

Best practices for Kafka/RabbitMQ message brokering and event sourcing.

j4flmao Updated

File contents

Event Driven Architecture

Core Concepts

  • Message Brokering: Decouples producers and consumers.
  • Event Sourcing: State is determined by a sequence of events.

Diagram

%%{init: {"theme": "default", "flowchart": {"useMaxWidth": true}}}%%
flowchart TD
    A[Producer] --> B(Message Broker)
    B --> C[Consumer 1]
    B --> D[Consumer 2]
    B --> E[(Event Store)]

Go Example (Kafka Producer)

package main

import (
    "github.com/confluentinc/confluent-kafka-go/kafka"
    "log"
)

func produceEvent(topic, message string) {
    p, _ := kafka.NewProducer(&kafka.ConfigMap{"bootstrap.servers": "localhost"})
    defer p.Close()

    p.Produce(&kafka.Message{
        TopicPartition: kafka.TopicPartition{Topic: &topic, Partition: kafka.PartitionAny},
        Value:          []byte(message),
    }, nil)
    p.Flush(15 * 1000)
    log.Println("Event produced")
}

j4flmao/agent-skills/tree/main/skills/backend/event-driven-architecture commit 50c84f9401

Frequently asked questions

npx skillmds@latest add j4flmao/event-driven-architecture