Microservice Subscription issue

Hi,

we have deployed a eventListener service which is developed using cumulocity sdk as spring boot app in management tenant and from management tenant we are subscribing to other many tenants.

But encountering an issue every now and than that, suppose i have 10 tenants and i am subscribing my service to all the tenants from management tenant,
But after few hours or few days, service stops listening to few tenants automatically, i,e. out of 10 subscribed tenants it listenes only 4 5 after initial subscrption.
In order to make service to listen again for the tenants it stopped listening, i need to manually re-subscribe it again for those tenants.

is there anything i need to be awared in this case?
Not getting what exaclty going wrong, need info on this.

Can you give more details please? Which “EventListener” are you talking about? What do you mean with “stop listening to tenants”?
To my knowledge there are only SubscriptionAdded and SubscriptionRemoved EventListener which are only called if that event occur (which should not happen very often) and is nothing which is executed periodically or listening afterwards.

Hi @Stefan_Witschel ,

We have a service which subscribes to realtime measurements for the deployed tenant.
MeasurementRealtimeNotificationSubscriber subscriber = new MeasurementRealtimeNotificationSubscriber(platform);

Event listener used is:
@EventListener
private void onMicroserviceSubscriptionAddedEvent(final MicroserviceSubscriptionAddedEvent event) {},

when i say it stops,
we are not deploying this service directly in individual tenants, we have a management tenant, where will first deploy the service, from management tenant we will subscribe this service to all other production tenants ex, prod1,prod2, prod3.

At initial few hours or a day, service will be active and in all subscribed tenants and listenes to measurements, of subscribed tenant, but it is observed that after few hours or days, service stops listening to some of the subscribed tenants automatically. but service status shows active in the tenant which it is not listening.

To make the service listen in tenants which it stopped listening, i need to manually resubscribe it again from management tenant.

That are two total different things and has nothing to do with the EventListener. If a tenant is successfully subscribed to a microservice of course everything is fine and “active”. What happens next is part of your programming logic is should be separated from the microservice subscription status.

In your case:
The “old” Subscription API is not very reliable and it could happen that messages/connections are dropped or lost under load which you might recognized in your described case.

Please use the “new” Notification API 2.0 which is much more reliable: Microservice SDK for Java - Cumulocity IoT documentation
Cumulocity IoT - OpenAPI Specification

Hi @Stefan_Witschel ,

Can you provide any reference , on how to susbcribe to realTime measurements using new API.

I did already, check my links posted above cumulocity-examples/notification2-examples/hello-world-microservice/src/main/java/c8y/example/notification/microservice/NotificationExample.java at 71a92055319c72ae9a8d437203b3411dc44cc015 · SoftwareAG/cumulocity-examples · GitHub

Thank you @Stefan_Witschel

Hi @Stefan_Witschel

As Jaya Kumar already explained our problem statement in detail. Let me rephrase it again.

We have developed custom C8Y microservice subscribed to measurements by using C8Y SDK Notification1.0 (Long polling) for the following requirements

  1. MS can be subscribed to one tenant or more than one tenants. At present we have 52 dedicated tenants in production.
  2. MS would be deployed in management tenant first than from there it subscribed to all the dedicated tenants.
  3. When MS up and running in all the tenants, MS start listening to all devices and receiving the measurements.
  4. When 1, 2 and 3 executed successfully, then application performs business logic.

As you confirmed that there Notification1.0 API is not reliable and has messages/connections are dropped or lost.

As you recommended this issue is fixed in notification2.0. But when gone through its documentation which says, it does not yet support all of the notifications available from the Real-time notification API, so it is not yet a complete replacement for the older API.
However, Notification2.0 supports two types of contexts and API support.

  1. Mo: This support notification type measurements for only predefined/existing devices. After we did a small POC with help of your notification2.0 example, MS started receiving the measurements for all predefined/existing devices subscription created. However, we have another use case where new devices can be commissioned at any point of time in any tenant. We observed that devices added later. their measurements not getting received onNotification method.
  @Override
			public void onNotification(String tenantId, Notification notification) {
				try {
					final MeasurementRepresentation measurement = jsonParser.parse(MeasurementRepresentation.class, notification.getMessage());
					String deviceId= measurement.getSource().getId().getValue();
					log.info("TenantId - {}  DeviceID -{}",tenantId,deviceId);
					subscriptionsService.runForTenant(tenantId, () -> {
						alarmFlowService.processRecievedMeasurements(tenantId,deviceId,measurement);
					});
				} catch (Exception ex) {
					log.error("Error in onNotification :: {}",ex);
					log.error(ex.getMessage());
				}
			}

Is this use case implemented or supported in notification2.0 version of SDK?

  1. Tenant: This doesn’t support notification type measurements which is the perquisites of our requirement.
    In which future version of C8Y SDK, Software AG planning to implement measurements APIs support?

Based on all above facts, it seems that notification2.0 doesn’t fulfill our requirement.
Please advice

Hi @nbohra

sorry for the late response (I was on vacation).

Actually Notification 2.0 does cover all your requirements but you need to implement it differently.

For each (old and new) device you need to create a subscription. In your use case you should subscribe on tenant context to detect if new devices are created and secondly create a new subscription for the created device (with mo context). Tip: If you share the subscription name you only need one WebSocket connection for all devices in mo context.

You are right about some APIs which are not supported yet in the tenant context but can still implement the logic I mentioned above to cover this but I agree it would be much easier if all of it would be available just in the tenant context.

I don’t have any timeline or roadmap but maybe @Scott_Mitchell1 or @Jane_Porter can give more details.