SDK
SDK Dart v2.x
2

Subscribe #

Subscribes by providing a set of filters: messages, document changes and, optionally, user events matching the provided filters will generate real-time notifications, sent to you in real-time by Kuzzle.

Arguments #

Future<String> subscribe(String index, String collection,
      Map<String, dynamic> filters, SubscribeListener callback,
      {String scope,
      String state,
      String users,
      Map<String, dynamic> volatile,
      bool subscribeToSelf,
      bool autoResubscribe})
ArgumentTypeDescription
index
String
Index name
collection
String
Collection name
filters
Map<String, dynamic>
Map representing a set of filters following Koncorde syntax
callback
SubscribeListener
Handler function to handle notifications
scope
String

(all)
Subscribes to document entering or leaving the scope
Possible values: all, in, out, none
users
Users

(none)
Subscribes to users entering or leaving the room
Possible values: all, in, out, none
subscribeToSelf
boolean

(true)
Subscribes to notifications fired by our own queries
autoResubscribe
boolean

(false)
Automatically resubscribe after connection loss
volatile
Map<String, dynamic>

(null)
ConcurrentHashMap representing subscription information, used in user join/leave notifications

handler #

Handler function that will be called each time a new notification is received. The hanlder will receive a KuzzleResponse as its only argument.

Return #

The room ID.

Usage #

Simple subscription to document notifications

await kuzzle
  .realtime
  .subscribe(
    'nyc-open-data',
    'yellow-taxi',
    {
      'exists': 'name',
    },
    (notification) {
      if (notification.scope == 'out') {
        print('Document left the scope');
      } else {
        print('Document moved in the scope');
      }
    });
await kuzzle
  .document
  .create('nyc-open-data', 'yellow-taxi', 
  {
    'name': 'nina-vkote',
  }, id: 'nina-vkote');

Subscription to document notifications with scope option

await kuzzle
  .realtime
  .subscribe(
    'nyc-open-data',
    'yellow-taxi',
    {
      'range': {
        'age': {
          'lte': 20
        }
      }
    },
    (notification) {
      if (notification.scope == 'out') {
        print('Document left the scope');
      } else {
        print('Document moved in the scope');
      }
    });
await kuzzle
  .document
  .create('nyc-open-data', 'yellow-taxi', 
  {
    'age': 19,
  }, id: 'nina-vkote');
await kuzzle
  .document
  .update('nyc-open-data', 'yellow-taxi', 'nina-vkote',
  {
    'age': 42,
  });