DataSyncEntity
A handle for subscribing to DataSync realtime events about an Entity by its ref/id.
A DataSync handle is a channel filter on the ref, not a type filter: subscribing to dataSyncEntity(id) delivers the mix of events routed to that ref-channel — the entity's own create/update/delete, the relationships where the entity is an endpoint, and propagated events for entities joined to it. Branch on the sealed com.pubnub.api.models.consumer.pubsub.datasync.PNDataSyncEventResult.extractedMessage.
This handle is a convenience over pubnub.channel(id).subscription(); a plain channel subscription on the same ref also delivers these events. The handle additionally resolves projection channels.
PAM: because subscribing is a plain PubSub read of the ref-channel, an authorized client needs a channel read grant on the resolved ref-channel name. Use com.pubnub.api.models.consumer.access_manager.v3.DataSyncGrant.subscribe (subscribe(id) for the default projection, subscribe(id, projection) for a non-default one) or com.pubnub.api.models.consumer.access_manager.v3.DataSyncGrant.subscribePattern for many refs. This is separate from the DataSync CRUD permission on the entity record (com.pubnub.api.models.consumer.access_manager.v3.DataSyncGrant.entity): the record grant does not authorize the subscribe, and the subscribe grant does not authorize record CRUD.
The two projection parameters differ: on entity(...) it sets the REST read view (meta.pn-projections); on subscribe(...) it only selects the ref-channel name (__{projection}__{id}) and adds nothing to the meta. To read through and subscribe to a projection, grant both:
DataSyncGrant.entity("capy-001", get = true, projection = "admin")
DataSyncGrant.subscribe("capy-001", projection = "admin")Use com.pubnub.api.PubNub.dataSyncEntity to create instances.
Functions
Returns a Subscription to this entity's default-projection ref-channel.
Returns a Subscription to this entity's events for the given projection.