Producers

A producer is any service that generates and publishes notifications to Notiway. It can be written in any language. All it needs to do is publish a JSON message in the standard notification format to the configured broker (SNS, Redis, RabbitMQ, etc.).

Notiway handles everything after that: routing, persistence, and delivery to connected clients.

Notification Structure

Every notification is a JSON object with five top-level fields. Here is the simplest possible example for broadcasting to all connected clients:

{
  "id": "order-service-order-placed-2025-01-01T10:00:00Z",
  "type": "order-placed",
  "body": {
    "orderId": "abc-123",
    "total": 59.99
  },
  "routing": {
    "audienceType": 1,
    "audienceValue": "global"
  },
  "metadata": {
    "producer": "order-service",
    "timeStamp": "2025-01-01T10:00:00Z",
    "isPersisted": false
  }
}

Fields

FieldTypeRequiredDescription
idstringYesUnique identifier for the notification. Recommended format: {producer}-{type}-{timestamp}
typestringYesFree-form event name (e.g. order-placed, alert). Clients receive a notification only when they have subscribed to this notification type.
bodyobjectNoAny JSON payload. The schema is defined entirely by you.
routingobjectYesDetermines who receives the notification. See Routing below.
metadataobjectYesContextual information about the notification origin and persistence. See Metadata below.

Routing

The routing object controls which connected clients receive the notification. audienceType is an integer enum — see the Audience Types table below for all possible values.

FieldTypeRequiredDescription
audienceTypenumberYesInteger enum defining the target audience scope.
audienceValuestringYes*The target identifier (user ID, tenant ID, group name, or connection ID). *Required for all audience types except Global.
tenantIdstringNoRequired when targeting a tenant-scoped group. For Tenant audience, either audienceValue or tenantId must be populated with the tenant identifier.

Audience Types

ValueNameWho receives the notificationaudienceValue
1GlobalAll connected clientsSet to "global"
2TenantAll clients in the specified tenantThe tenant ID
3GroupAll clients that are members of the named groupThe group name
4UserAll clients connected as the specified userThe user ID
5ConnectionThe single client with the specified connection IDThe connection ID

Group + Tenant scoping: When targeting a group within a specific tenant, set audienceValue to the group name and tenantId to the tenant. Without tenantId, the group is global across all tenants.


Metadata

FieldTypeRequiredDescription
producerstringYesName of the service sending the notification (e.g. "order-service"). Used for tracing and logging.
timeStampstring (ISO 8601)YesUTC timestamp of when the notification was created.
isPersistedbooleanNoIf true, Notiway stores the notification so offline users receive it on reconnect. Defaults to false.
persistedTTLstring (ISO 8601)NoExpiry time for the persisted notification. Defaults to 30 minutes from creation if not set.

Routing Examples

The routing field shown in each example below can be dropped into a full notification alongside id, type, body, and metadata.

Broadcast to all connected clients.

{
  "routing": {
    "audienceType": 1,
    "audienceValue": "global"
  }
}

All clients in a specific tenant. Use either audienceValue or tenantId — both refer to the tenant identifier.

{
  "routing": {
    "audienceType": 2,
    "audienceValue": "acme-corp"
  }
}

All clients in a named group, across all tenants.

{
  "routing": {
    "audienceType": 3,
    "audienceValue": "admins"
  }
}

All clients in a named group, scoped to a specific tenant.

{
  "routing": {
    "audienceType": 3,
    "audienceValue": "admins",
    "tenantId": "acme-corp"
  }
}

All clients connected as a specific user. A single user may have multiple active connections (e.g. browser + mobile).

{
  "routing": {
    "audienceType": 4,
    "audienceValue": "user-42"
  }
}

A single specific client connection. Use when you need to target one exact device or tab.

{
  "routing": {
    "audienceType": 5,
    "audienceValue": "connectionId-789"
  }
}

Persistence

When isPersisted is true, Notiway stores the notification using the configured Storage plugin. If a user is offline when the notification is sent, they will receive it immediately upon reconnecting, as long as the TTL has not expired.

  • Default TTL is 30 minutes if persistedTTL is not provided
  • Once expired, the notification is no longer delivered on reconnect
  • Use persistence for important events where guaranteed delivery matters (alerts, account changes, etc.)
  • A client will only receive a persisted notification on reconnect if it is part of the correct audience (based on routing) and has subscribed to the matching notification type

Sending to Notiway

Producers never communicate directly with the Notiway gateway. Instead, the producer publishes to a broker (SNS, Redis, RabbitMQ, etc.) and Notiway’s Buffer plugin consumes from it. This decouples your services from the gateway. your service doesn’t need to know how many gateway instances are running or where they are.

See Sending Notifications for broker-specific examples (SNS, Redis, RabbitMQ, Azure Service Bus, and more).


Related Docs