Skip to content

Commit df84cdb

Browse files
committed
Reword channel publish sections
1 parent 972710b commit df84cdb

1 file changed

Lines changed: 22 additions & 74 deletions

File tree

src/pages/docs/guides/pub-sub/notifications-center.mdx

Lines changed: 22 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,18 @@ Key security considerations:
128128
* Use wildcard patterns in capabilities (like `inbox:*`) sparingly. Always scope tokens to the specific channels a client needs access to.
129129

130130
## Publishing notifications from your backend
131-
Your backend is responsible for processing notification requests and publishing them to Ably. For the notification center pattern, you have two main publishing approaches: publishing to inbox channels for realtime delivery (with optional push notifications for offline users), or sending push notifications directly to users via their `clientId`.
132131

133-
### Publishing to inbox channels
132+
Your backend is responsible for processing notification requests and publishing them to Ably. For the notification center pattern, you have two main publishing approaches: publishing to channels (inbox channels or general broadcast channel) for realtime delivery, with optional push notifications for offline users, or sending push notifications directly to specific users or devices via their `clientId` or `deviceId`.
134133

135-
Publishing to inbox channels delivers notifications in realtime to connected clients. You can optionally include push notification payloads in the `extras.push` field to ensure offline users also receive the notification via push.
134+
### Publishing to channels
135+
136+
Publishing to channels delivers notifications in realtime to connected clients. You can optionally include push notification payloads in the `extras.push` field to ensure offline users also receive the notification via push. This approach works for both individual inbox channels and the general broadcast channel.
136137

137138
#### REST API publishing
138139

139-
The simplest approach is to use Ably's [REST API](/docs/api/rest-api) directly from your backend. All Ably SDKs provide REST client libraries for various languages (JavaScript, Python, Go, Java, Ruby, and more).
140+
The simplest approach is to use Ably's [REST API](/docs/api/rest-api) directly from your backend. All Ably SDKs provide REST client libraries for various languages (JavaScript, Python, Go, Java, Ruby, and more). The REST API is recommended for most use cases as it's built into all Ably SDKs for ease of use and requires no additional infrastructure. Each publish is a synchronous HTTP request, and multiple requests can be batched together to reduce API calls.
140141

141-
#### Single channel publishing
142+
When using the REST API and making concurrent publish requests, ordering is not guaranteed. If you're publishing via the batch publish endpoint, messages within a single batch maintain order, but batches themselves may be processed out of order. This is a consequence of HTTP's stateless nature and network variability. To maintain ordering, publish related notifications sequentially rather than concurrently, and use [idempotency keys](/docs/platform/architecture/idempotency) to prevent duplicate processing if retries occur.
142143

143144
<Code>
144145
```javascript
@@ -171,61 +172,15 @@ await inbox.publish({
171172

172173
Including the `extras.push` field ensures that if the user is offline or the app is closed, they'll receive a push notification. Connected clients receive the message in realtime through their channel subscription.
173174

174-
#### Batch publishing
175-
176175
For notifications targeting multiple recipients, use the [batch publish REST endpoint](/docs/api/rest-api#batch-publish) to publish to multiple channels in a single HTTP request, reducing latency and improving efficiency.
177176

178-
<Code>
179-
```javascript
180-
const Ably = require('ably');
181-
const ably = new Ably.Rest({ key: process.env.ABLY_API_KEY });
182-
183-
// Publish to multiple inboxes at once
184-
const specs = [
185-
{
186-
channel: 'inbox:user123',
187-
messages: [{
188-
name: 'notification',
189-
data: { type: 'system-alert', message: 'Server maintenance scheduled' },
190-
extras: {
191-
push: {
192-
notification: {
193-
title: 'System Alert',
194-
body: 'Server maintenance scheduled'
195-
}
196-
}
197-
}
198-
}]
199-
},
200-
{
201-
channel: 'inbox:user456',
202-
messages: [{
203-
name: 'notification',
204-
data: { type: 'system-alert', message: 'Server maintenance scheduled' },
205-
extras: {
206-
push: {
207-
notification: {
208-
title: 'System Alert',
209-
body: 'Server maintenance scheduled'
210-
}
211-
}
212-
}
213-
}]
214-
},
215-
// ... up to 100 channels per request
216-
];
217-
218-
await ably.request('post', '/messages', null, specs, null);
219-
```
220-
</Code>
221-
222-
### Kafka Connector publishing
177+
#### Kafka Connector publishing
223178

224179
You can also publish directly from your existing Kafka infrastructure through [Ably's Kafka Connector](/docs/platform/integrations/kafka-connector). This allows your backend to produce messages to Kafka topics, which are then automatically published to Ably channels based on your [configured mappings](docs/platform/integrations/inbound/kafka-connector#mapping). The Kafka Connector supports dynamic channel routing, allowing you to determine the target Ably channel based on Kafka message attributes like topic, partition, key, or custom headers.
225180

226-
#### Publishing via Kafka
181+
The Kafka Connector should be used when you have existing Kafka infrastructure and want to integrate this directly with Ably. The Kafka Connector preserves Kafka's ordering guarantees, so messages in the same Kafka partition are published to Ably in order. Use consistent partition keys (e.g., clientId) for related client notifications, and configure appropriate partition counts for your throughput needs. Messages published to the same channel from the same partition maintain order, but this requires some [configuration](https://github.com/ably/kafka-connect-ably?tab=readme-ov-file#message-ordering).
227182

228-
To route messages to the correct inbox channel, you can use the Kafka message key or headers to specify the target client ID. For example, you could define a channel mapping such as `inbox:${key}` to route messages to the appropriate inbox based on the Kafka message key. To include push notification payloads for offline users, add a `com.ably.extras.push` header to your Kafka message with the push notification details as a JSON string.
183+
To route messages to the correct channel, you can use the Kafka message key or headers to specify the target client ID. For example, you could define a channel mapping such as `inbox:${key}` to route messages to the appropriate inbox based on the Kafka message key. To include push notification payloads for offline users, add a `com.ably.extras.push` header to your Kafka message with the push notification details as a JSON string.
229184

230185
<Code>
231186
```javascript
@@ -267,13 +222,13 @@ The Kafka Connector will automatically include the push payload from the `com.ab
267222

268223
### Direct push publishing
269224

270-
For notifications that only need to be delivered as push (without realtime channel delivery), you can publish push notifications directly to users via their `clientId`. This approach is useful when you want to send a notification exclusively as a push alert without publishing to inbox channels.
225+
For notifications that only need to be delivered as push (without realtime channel delivery), you can publish push notifications directly to specific users or devices using `clientId` or `deviceId`. This approach is useful when you want to send a notification exclusively as a push alert without publishing to channels.
271226

272227
<Code>
273228
```javascript
274229
const ably = new Ably.Rest({ key: process.env.ABLY_API_KEY });
275230

276-
// Send push notification directly to a user (all their devices)
231+
// Send push notification to all devices for a user
277232
await ably.push.admin.publish(
278233
{ clientId: 'user123' },
279234
{
@@ -287,29 +242,22 @@ await ably.push.admin.publish(
287242
}
288243
}
289244
);
245+
246+
// Or send to a specific device
247+
await ably.push.admin.publish(
248+
{ deviceId: 'device-abc123' },
249+
{
250+
notification: {
251+
title: 'New Friend Request',
252+
body: 'Jane Doe sent you a friend request'
253+
}
254+
}
255+
);
290256
```
291257
</Code>
292258

293259
Direct push publishing is most useful when notifications don't need to appear in a realtime feed or when you want to send different content to push vs. in-app notifications. For most notification center use cases, publishing to channels with `extras.push` is recommended because it provides both realtime delivery and push notifications with a single publish.
294260

295-
### Choosing your publishing approach
296-
297-
The right approach depends on your infrastructure and ordering requirements.
298-
299-
#### REST API
300-
301-
Ably's Rest API is the simplest option and is recommended for most use cases. It's built into all Ably SDKs for ease of use and requires no additional infrastructure. Each publish is a synchronous HTTP request, and multiple requests can be batched together to reduce API calls.
302-
303-
When using the REST API and making concurrent publish requests, ordering is not guaranteed. If you're publishing via the batch publish endpoint, messages within a single batch maintain order, but batches themselves may be processed out of order. This is a consequence of HTTP's stateless nature and network variability. To maintain ordering, publish related notifications sequentially rather than concurrently, and use [idempotency keys](/docs/platform/architecture/idempotency) to prevent duplicate processing if retries occur.
304-
305-
#### Kafka Connector
306-
307-
Ably's kafka connector should be used when you have existing Kafka infrastructure and want to integrate this directly with Ably. The Kafka Connector preserves Kafka's ordering guarantees, so messages in the same Kafka partition are published to Ably in order.
308-
309-
* Use consistent partition keys (e.g., clientId) for related client notifications.
310-
* Configure appropriate partition counts for your throughput needs.
311-
* Messages published to the same channel from the same partition maintain order, but this requires some [configuration](https://github.com/ably/kafka-connect-ably?tab=readme-ov-file#message-ordering).
312-
313261
## Receiving notifications on the client
314262

315263
Clients subscribe to their inbox channels using Ably's realtime SDKs. When your backend publishes a message to a client's inbox channel, the client will receive it in realtime provided they are attached and subscribed to the channel.

0 commit comments

Comments
 (0)