Event Bus
Content-based event routing — rules match a JSON pattern and forward events to targets, modelled on EventBridge, Event Grid, and Eventarc
aws EventBridgeazr Event Gridgcp Eventarc
Emulates a managed event bus — the router you publish events to and let rules decide where they go. You create a bus, attach rules that each carry a JSON event pattern, and point each rule at one or more targets; when a published event matches a rule's pattern, it's routed to that rule's targets.
Reach for it in tests when your code emits domain events (OrderCreated, UserSignedUp) and downstream handlers subscribe by shape rather than by name. Unlike the message queue, routing is content-based and there's no pull-and-ack — an event that matches no rule is simply not delivered anywhere.
| Provider | Service | Access |
|---|---|---|
| AWS | EventBridge | aws.EventBridge |
| Azure | Event Grid | azure.EventGrid |
| GCP | Eventarc | gcp.Eventarc |
Create an event bus#
The bus is the container rules and events live on — the equivalent of a custom EventBridge bus. Create one before adding rules; events without an explicit bus fall through to the provider's default bus.
import ebdriver "github.com/stackshy/cloudemu/v2/services/eventbus/driver"
bus, _ := aws.EventBridge.CreateEventBus(ctx, ebdriver.EventBusConfig{
Name: "app-events",
})Add a rule and its targets#
A rule's EventPattern is the filter: only events whose fields match the JSON pattern trigger it. PutRule upserts the rule (creating it, or updating its pattern while keeping existing targets), then PutTargets attaches the destinations that matched events are forwarded to.
aws.EventBridge.PutRule(ctx, &ebdriver.RuleConfig{
EventBus: bus.Name,
Name: "order-rule",
EventPattern: `{"source": ["orders"]}`,
})
aws.EventBridge.PutTargets(ctx, bus.Name, "order-rule", []ebdriver.Target{
{ID: "process-order", ARN: "arn:aws:lambda:...:function:process-order"},
})Publish events#
PutEvents takes a batch and routes each event through every rule on its bus. Each event's Source and DetailType classify it and Detail carries the JSON payload the pattern is matched against; the result reports how many events were accepted.
aws.EventBridge.PutEvents(ctx, []ebdriver.Event{
{
Source: "orders",
DetailType: "OrderCreated",
Detail: `{"orderId": "123"}`,
EventBus: bus.Name,
},
})Behavior & fidelity#
- Content-based routing. Every published event is matched against all rules on its bus; a rule fires only when the event satisfies its
EventPattern, and matched events are forwarded to that rule's targets — an event matching no rule is dropped, not queued. - Default bus fallback. An event or rule with an empty
EventBusis routed to the provider's default bus, matching EventBridge's default-bus behaviour. - Rule state and replay. Rules can be enabled/disabled without deletion, and published events are retained so
GetEventHistorycan replay what was sent to a bus. - SDK-compat status — Portable Go API only. Real
aws-sdk-go-v2/service/eventbridge,armeventgrid, and Eventarc REST clients can't talk to cloudemu yet; event-bus SDK-compat handlers will ship in lockstep across all three providers in a later phase. Buses, rules, targets, and pattern-based routing are fully available today through the Portable Go API shown above.