Subscribing to measurement and operation notifications for all managedobjects

I’d like to subscribe to measurement and operation notifications for all managedobjects. Unfortunately, notifications2.0 subscriptions with a tenant context only support alarms, events, and managedobjects. I could user subscriptions with an mo context, but they would require a separate token, subscription, and ws connection for each managedobject.

Do you recommend using real-time notifications, or would it be better to poll the REST API for new/updated measurements and operations?

Thanks!

Hi there,

It’s not necessary to have a separate token and WS connection for each MO notification subscription. You can have many subscriptions all feeding their notifications into the same “topic”, with a single WebSocket consumer attached to that topic receiving the notifications from all the subscriptions. See https://www.cumulocity.com/api/core/#section/Overview/Topics-and-subscriptions in the API guide for more details - the basic trick is to reuse the same subscription name when creating subscriptions and tokens. Yes, you still do need to manage a subscription per MO and that can be difficult/annoying, but it is possible.

Tenant context subscriptions for all message types is probably the most frequent feature request we get for Notifications 2.0. I’m not able to share specific details of the schedule, but I can say that we are working on this and these subscription types will become available at some point - probably initially as a controlled preview to ensure that high-volume measurement subscriptions (for example) don’t have any negative impact for other tenants on the same environment.

Ah, the “subscription” field description threw me off, I thought the names had to be unique. (“The subscription name. Each subscription is identified by a unique name within a specific context.”)

So a subscription for each MO with the same name, and a single token + ws connection for all of them. I’ll try it out, thanks!

What if I wanted to unsubscribe from all notifications? Does something like this sound right:

  • call delete /notification2/subscriptions for each mo subscription
  • call post /notification2/unsubscribe endpoint with the active token (Is this required if the subscriptions were already deleted? Also, if I have multiple tokens with the same subscriber name, does it have to be called for each token, or just one of them?)

Hi there,

Yes, there is some unfortunate overloading of the term “subscription” in the API and as you’ve noticed, the documentation can always be improved. I’ve made a note to fix the specific statement you quoted - that is certainly misleading.

WRT unsubscribing, as you say you will need to delete all the MO subscriptions individually. As for consumers, you’ll want to post to /notification2/unsubscribe for each unique value of the subscriber field (not subscription) that you used to create a token, to remove that named subscriber from the underlying topic. This is necessary even if all the “subscriptions” have been deleted. Multiple tokens with the same subscriber name are essentially equivalent to each other - all the token really does is grant permission to attach a named subscriber to a topic - so it is the number of unique subscriber names that matters, not the number of tokens that were generated.

I hope that is somewhat clear!

Thanks,

Scott

Thanks @Scott_Mitchell1 , that makes sense!

I’m having some trouble connecting to the REST API when ssl is enabled. Were there any additional steps required to set up an ssl connection? Non-ssl connections, and ssl connections to non-c8y endpoints are working.