Dart - topic.subscribe()

Subscribe a handler to a topic and receive new events for processing.

import 'package:nitric_sdk/nitric.dart';
final updates = Nitric.topic("updates");
updates.subscribe((ctx) async {
// Log the provided message
print(ctx.req.json());
return ctx;
});

Parameters

  • Name
    handler
    Required
    Required
    Type
    MessageHandler
    Description

    The middleware (code) to be triggered by the topic.

Examples

Subscribe to a topic

import 'package:nitric_sdk/nitric.dart';
final updates = Nitric.topic("updates");
updates.subscribe((ctx) async {
// Log the provided message
print(ctx.req.json());
return ctx;
});

Notes

  • A service may only subscribe to a topic once, if multiple subscribers are required, create them in different service.
  • A service may subscribe to OR publish to a topic but not both
Last updated on Oct 22, 2024