Events

Configuration

Config structs, YAML examples, and option helpers for Events

YAML Configuration Example

config.yaml
extensions:
  events:
    bus:
      defaultBroker: "memory"       # default broker for Publish()
      maxRetries: 3
      retryDelay: "5s"
      enableMetrics: true
      enableTracing: false
      bufferSize: 1000              # event channel buffer
      workerCount: 10               # concurrent event workers
      processingTimeout: "30s"

    store:
      type: "memory"                # "memory", "postgres", "mongodb"
      database: ""                  # database connection name (for postgres/mongodb)
      table: "events"               # events table/collection name

    brokers:
      - name: "memory"
        type: "memory"
        enabled: true
        priority: 1

      - name: "nats"
        type: "nats"
        enabled: true
        priority: 2
        config:
          url: "nats://localhost:4222"
          clusterID: "my-cluster"

      - name: "redis"
        type: "redis"
        enabled: false
        priority: 3
        config:
          url: "redis://localhost:6379"

    metrics:
      enabled: true
      publishInterval: "30s"
      enablePerType: true
      enablePerHandler: true

The extension loads config from extensions.events first, falling back to events.

Programmatic Configuration

ext := events.NewExtensionWithConfig(events.Config{
    Bus: events.BusConfig{
        DefaultBroker: "memory",
        WorkerCount:   20,
        BufferSize:    5000,
    },
    Store: events.StoreConfig{
        Type:  "memory",
        Table: "events",
    },
    Brokers: []events.BrokerConfig{
        {Name: "memory", Type: "memory", Enabled: true, Priority: 1},
    },
})

Config Struct Reference

Config

FieldTypeDefaultDescription
BusBusConfigSee belowEvent bus configuration
StoreStoreConfigSee belowEvent store configuration
Brokers[]BrokerConfigMemory brokerMessage broker definitions
MetricsMetricsConfigSee belowMetrics collection settings

BusConfig

FieldTypeDefaultDescription
DefaultBrokerstring"memory"Default broker for Publish()
MaxRetriesint3Retry attempts for failed publishes
RetryDelaytime.Duration5sDelay between retries
EnableMetricsbooltrueEmit bus metrics
EnableTracingboolfalseEnable distributed tracing
BufferSizeint1000Internal event channel buffer size
WorkerCountint10Number of concurrent event workers
ProcessingTimeouttime.Duration30sTimeout per event processing

StoreConfig

FieldTypeDefaultDescription
Typestring"memory"Store backend: "memory", "postgres", "mongodb"
Databasestring""Database connection name
Tablestring"events"Table or collection name

BrokerConfig

FieldTypeDescription
NamestringUnique broker identifier
TypestringBroker type: "memory", "nats", "redis"
EnabledboolWhether this broker is active
PriorityintSelection priority (lower = higher priority)
Configmap[string]anyBroker-specific settings

MetricsConfig

FieldTypeDefaultDescription
EnabledbooltrueEnable metrics collection
PublishIntervaltime.Duration30sMetrics publishing interval
EnablePerTypebooltruePer-event-type metrics
EnablePerHandlerbooltruePer-handler metrics

How is this guide?

On this page