-->

How do I guarantee unique subscriptions in Orion C

2019-02-28 07:16发布

问题:

In my setup I have one application that should subscribe to a specific kind of context change. The application currently perform subscription at startup time. However if I restart the application, the subscription is duplicated. To overcome this issue I started to keep track of subscriptions in a database, so that I have an association between my application id and the latest subscription id.

Is there any way to achieve similar result in Orion (let's call it like "named subscriptions"), without using an external database?

回答1:

There is a planned subscription "browsing" operation in Orion development roadmap (see operation ID 45 in this document) that could help in your case.

However, while this operation get implemented, one alternative to the one you mention (i.e. to keep subscription info in an external DB) would be to access to the Orion DB itself to get the subscription information. The datamodel (described here) is pretty simple and getting the info is quite easy if you are familiar with MongoDB. Note that this solution requires access to the Orion DB (i.e. it is feasible if you control your own instance of Orion).

EDIT: Given that different subscriptions may use the same reference, I'd recommend to use _id field to identify each subscription (_id field values are unique). NGSI doesn't include metadata in subscription, but you may associated subscription IDs with application using Orion itself, e.g. SubscriptionAssociation entities with two attributes, one for the application name and another for the subscription ID being associated

EDIT: since Orion 0.25.0, the GET /v2/subscriptions operation allows you to browse existing subscriptions.