Dart - topic.publish()

Publish an event (push based message) to a topic.

import 'package:nitric_sdk/nitric.dart';
final updates = Nitric.topic("updates").allow([
TopicPermission.publish,
]);

Parameters

  • Name
    payload
    Required
    Required
    Type
    Map<String, dynamic>
    Description

    The payload to publish to the topic.

  • Name
    delay
    Optional
    Optional
    Type
    int
    Description

    A number of seconds to delay the delivery of this message.

Examples

Publish a message

Publishing messages to a topic will push a copy of the message to each of the topic's subscribers. By default, delivery occurs without a delay.

import 'package:nitric_sdk/nitric.dart';
final updates = Nitric.topic("updates").allow([
TopicPermission.publish,
]);
await updates.publish({
"something": "amazing happened",
});

Delaying message delivery

You can delay the delivery of messages sent to a topic. The current maximum delay is 7 days (604800 seconds).

import 'package:nitric_sdk/nitric.dart';
final updates = Nitric.topic("updates").allow([
TopicPermission.publish,
]);
// 10 minute delay
await updates.publish({
"something": "amazing happened",
}, delay: 600);

Notes

  • A service may subscribe to OR publish to a topic but not both.
Last updated on Oct 15, 2024