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 | SDK-compat | Driver |
|---|---|---|---|
| AWS | EventBridge | ✓ Live | aws.EventBridge |
| Azure | Event Grid | ✓ Live | azure.EventGrid |
| GCP | Eventarc | ✓ Live | 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#
| Behavior | What happens |
|---|---|
| Content-based routing | Each published event is matched against all rules on its bus; a rule fires only when the event satisfies its EventPattern, and an event matching no rule is dropped, not queued. |
| Default bus fallback | An event or rule with an empty EventBus routes to the provider's default bus, matching EventBridge's default-bus behaviour. |
| Rule state and replay | Rules can be enabled or disabled without deletion, and published events are retained so GetEventHistory can replay what was sent to a bus. |
SDK-compat — Live#
Real EventBridge, Event Grid, and Eventarc clients drive it end-to-end. See SDK-Compat for the full operation list.