When I use the subscribeToCloudMessage() function with CloudBackendMessaging.TOPIC_ID_BROADCAST as the topicId as is done in CloudBackendFragment.java everything works fine
This error message means that property SubscriptionIDs
(you can find it under the _DeviceSubscription
Kind in your datastore) value exceeds 500 Unicode characters limit. Read docs for the reference.
From the docs:
For text strings and unencoded binary data (byte strings), the Datastore supports two value types:
- Short strings (up to 500 Unicode characters or bytes) are indexed and can be used in query filter conditions and sort orders.
- Longstrings (up to 1 megabyte) are not indexed and cannot be used in query filters and sort orders.
The reason for this happening is that MBS trying to write all subscriptions into one property.
So to overcome this issue we need to use Text
instead of String
type in MBS backend source code for the SubscriptionIDs
property. To do so you need to make following changes in DeviceSubscription.java
class:
To set Text
property replace this line of code:
deviceSubscription.setProperty(PROPERTY_SUBSCRIPTION_IDS, this.gson.toJson(subscriptions));
with this line:
deviceSubscription.setProperty(PROPERTY_SUBSCRIPTION_IDS, new Text(this.gson.toJson(subscriptions)));
To get Text
property from the datastore:
Replace this line:
String subscriptionString = (String) deviceSubscription.getProperty(PROPERTY_SUBSCRIPTION_IDS);
with this:
Text text = (Text) deviceSubscription.getProperty(PROPERTY_SUBSCRIPTION_IDS);
String subscriptionString = text.getValue();
Replace this line:
String ids = (String) deviceSubscription.getProperty(PROPERTY_SUBSCRIPTION_IDS);
with this:
Text text = (Text) deviceSubscription.getProperty(PROPERTY_SUBSCRIPTION_IDS);
String ids = text.getValue();
Replace this line:
String[] ids = new Gson().fromJson((String) entity.getProperty(PROPERTY_SUBSCRIPTION_IDS),
String[].class);
with this:
Text text = (Text) entity.getProperty(PROPERTY_SUBSCRIPTION_IDS);
String[] ids = new Gson().fromJson(text.getValue(), String[].class);
Seems to be valid solution. I have not noticed negative influence on my project so far.
NOTE: As docs stated Text
is not indexed and cannot be used in query filters and sort orders. So this limitation could have cause another issues if the property SubscriptionIDs
required to be indexed.