Hi Yannick,
some thoughts on it…
Firstly, do i even need this trigger-service or is this possible with something like a smart-rule? Secondly…)
Currently you can’t achieve your use case via Smart Rules. However, you could definitely look into Apama. The EPL App examples have a sample on how to invoke Microservices (link to docs).
There are other people with more Apama Knowledge here, they could give you additional pointers on how to achieve your use case via Analytics Builder or EPL App.
Are there any best practices to create and maintain the subscription? Many guides tell me to be careful not to create&keep too many inactive subscriptions.
Notification 2.0 allows you to create subscriptions and register subscribers to such subscriptions. If your subscriber loses connection (e.g. due to bad network or service restarts) & the subscription is configured to be persistent, this subscriber will receive all notifications that it missed on its first successful reconnect. To make this possible, the platform has to buffer all data from a subscription for a certain subscriber. So you really have to to use stable subscription and subscriber names in your service, otherwise a) you’ll lose the functionality to get notifications delivered that happened while your service was offline and b) you’re creating lots of orphaned “data buffers” on platform-side that will never be consumed. If you do not need this buffering, you can configure your subscription to be non-persistent.
Worth a note: When you’re not using a subscription anymore, you should not only delete the subscription (this will stop the platform from sending notifications towards your subscriptions), you should also unsubscribe all subscribers of this subscription. This way the platform knows “this subscriber won’t reconnect” and cleans up it’s potential backlog.
Should the service be able to create subscriptions & tokens by itself (having ROLE_NOTIFICATION_2_ADMIN)
Yes. I would implement it within the Service and not create the subscriptions upfront/manually. This way the Service is more portable. Rather than “blindly” creating the subscription, you may want to implement a logic to check if the subscription of name X is existing, if yes re-use it, if not create it.
For hardcoding the subscription name vs. making it configurable via tenant options: I would either hardcode it or use the “settings” property in cumulocity.json. This way you can deploy the service to other tenants (potentially done by other people) without the hidden-knowledge to create specific tenant options upfront.
For tokens: I wouldn’t see a reason to store them as tenant option, you can simply request a new one on service-restart. Just make sure to use the same subscription/subscriber names in your token requests.
Does the service need to monitor when to re-issue a token?
You can set the expiry time when creating your token. I think yes, your service should make sure to re-issue a new token in case yours expired.
Links