Skip to content
cloudemu
Services

Notification

Pub/sub topics with fan-out to multiple subscribers and attribute filtering, modelled on SNS, Notification Hubs, and FCM

aws SNSazr Notification Hubsgcp FCM

Emulates a managed pub/sub notification service — the topic you publish one message to and have it fanned out to every subscriber at once. You create a topic, attach subscriptions that each point at an endpoint (an email address, an HTTP webhook, an SQS queue), then publish; the message is delivered to all matching subscriptions.

Reach for it in tests when your code announces an event to several independent consumers and you don't want a queue's pull-and-ack cycle — publish is fire-and-forget fan-out. Unlike the message queue, there's no per-consumer acknowledgement: a subscriber either matches the message or it doesn't.

ProviderServiceSDK-compatDriver
AWSSNS✓ Liveaws.SNS
AzureNotification Hubs✓ Liveazure.NotificationHubs
GCPFCM✓ Livegcp.FCM

Create a topic and subscribe endpoints#

A topic is the fan-out point; subscriptions are the endpoints it delivers to. Create the topic first, then attach one subscription per consumer — each names a Protocol (email, sms, http, https, sqs, lambda) and the Endpoint to reach it at.

import notifdriver "github.com/stackshy/cloudemu/v2/services/notification/driver"

topic, _ := aws.SNS.CreateTopic(ctx, notifdriver.TopicConfig{
    Name: "order-events",
})

sub, _ := aws.SNS.Subscribe(ctx, notifdriver.SubscriptionConfig{
    TopicID:  topic.ID,
    Protocol: "email",
    Endpoint: "team@example.com",
})

Publish a message#

Publish fans one message out to every subscription on the topic. The Attributes map rides along with the message so subscribers can filter on it — a subscription with a matching filter policy receives the message, others are skipped.

aws.SNS.Publish(ctx, notifdriver.PublishInput{
    TopicID: topic.ID,
    Message: "New order received",
    Attributes: map[string]string{"orderType": "express"},
})

Behavior & fidelity#

BehaviorWhat happens
Fan-out deliveryOne Publish reaches every subscription on the topic; adding or removing a subscription changes the recipient set for later publishes with no change to the producer.
Attribute filteringMessage Attributes are matched against each subscription's filter policy, so one topic can route to different subscribers by attribute — mirroring SNS message-attribute filtering.
Subscription statusNew subscriptions carry a confirmed/pending status, matching the SNS confirmation handshake rather than assuming every endpoint is immediately live.

SDK-compat — Live#

Real SNS, Notification Hubs, and FCM clients drive it end-to-end. See SDK-Compat for the full operation list.

On this page

On this page