Messaging - Topics

1. System Context

Developers use Nitric to declare topics to enable event-driven communication within their application.

  • App code interacts with the Topic resource through defined topics and subscriptions.
  • Developers configure topics and implement application logic to publish and consume messages.

Operations use default or overridden Terraform modules to provision the necessary resources for their target cloud.

Example AWS Provider
  • AWS SNS (Simple Notification Service) serves as the messaging and event notification service.
  • AWS Lambda functions are subscribed to SNS topics to process incoming messages.
  • AWS IAM manages roles and policies for secure access to SNS topics and Lambda functions.
  • AWS Step Functions make it possible to delay or schedule notifications, batch jobs, or any process that requires a timed pause before continuing with a task.
Code
Terraform
Create SNS Topic
Configure Subscriptions
Publish Messages
Invoke Lambda
Manage Permissions
Delayed Messages
Developer
Operations
nitric up
AWS SNS Topic
AWS Lambda Functions
AWS IAM
AWS Step Functions
Example GCP Provider
  • Google Pub/Sub serves as the messaging and event notification service.
  • Google Cloud Run services are subscribed to Pub/Sub topics to process incoming messages.
  • Google IAM manages roles and policies for secure access to Pub/Sub topics and Cloud Run services.
  • Retry Policy and Push Configuration ensure reliable delivery and handling of messages to Cloud Run services.
Code
Terraform
Create Pub/Sub Topic
Configure Subscriptions
Publish Messages
Push to Services
Manage Permissions
Retry Delivery
Developer
Operations
nitric up
Google Pub/Sub Topic
Google Cloud Run Services
Google IAM
Retry Policy & Push Config

2. Sequence

ClientNitric SDKNitric RuntimeCloud Topic Service (e.g., AWS SNS, GCP Pub/Sub)Subscriber (e.g., Queue, Function)alt[Successful Publish][Publish Failure]Publish message to topicForward topic API callPublish message to topicConfirm message deliveryReturn success confirmationReturn success to clientDistribute message to subscribersAcknowledge receipt of messageReturn errorForward errorReturn error responseClientNitric SDKNitric RuntimeCloud Topic Service (e.g., AWS SNS, GCP Pub/Sub)Subscriber (e.g., Queue, Function)

3. Component

Topic Module

  • Dynamically creates unique topics for messaging and event-driven communication, ensuring consistent naming and avoiding conflicts.
  • Configures metadata or tags for resource identification, governance, and lifecycle management.
  • Supports subscribing various endpoints (e.g., functions, services, queues) to the topic, enabling scalable publish-subscribe patterns.
  • Automates the assignment of permissions to ensure secure publishing and subscription handling, following the principle of least privilege.
  • Provides configurable retry policies and message delivery options to ensure reliable and fault-tolerant communication between services.
  • Abstracts the underlying cloud messaging infrastructure, offering a unified interface for event-driven architectures across different providers.
  • Optionally integrates with workflows or scheduling systems for advanced scenarios like delayed notifications or batched processing.

4. Code

Developers write application code that imports and declares the Topic resource from the SDK, and implements the application logic to publish and subscribe to topics.

SDK Reference by language -

Operations will use or extend the Nitric Terraform reference modules:

Last updated on Jan 24, 2025