I saw in the documentation that if my document has an attribute called “channels”, Ex:
{
“channels”: [“myChannel1”, “myChannel2”]
}
Then sync gateway will understand that this is a channel without any channel config. So in theory, I could also dynamically subscribe users via mobile:
ReplicatorConfiguration config = new ReplicatorConfiguration(database, new URLEndpoint(url));
config.setReplicatorType(ReplicatorConfiguration.ReplicatorType.PUSH_AND_PULL);
config.setContinuous(true);
config.setChannels(Arrays.asList("myChannel1", "myChannel2", "myChannel3")
config.setAuthenticator(new BasicAuthenticator(username, password));
Is it a valid approach? Is there any limit on the number of channels? Because I might have up to 100k channels using this approach.
There are no hard-limits to channels, but there are a couple of things you need to be aware of for larger numbers of channels.
Per-document channel limitations are related to the amount of metadata we have available to use in Couchbase Server for documents. With enable_shared_bucket_access=true, this is around 1MB of data. When enable_shared_bucket_access=false, this is 20MB minus the size of your document in bytes.
If you have a large number of channels that are split between a lot of documents, then you can avoid hitting the above limitation, but still hit memory-usage limits on Sync Gateway, as we maintain a cache per channel. These can be tuned using these config parameters depending on how much RAM you have available for Sync Gateway: https://docs.couchbase.com/sync-gateway/current/config-properties.html#databases-foo_db-cache