How to listen all MeasurementFragment in microservice

I wanted to listen all measurement in my microservices. I am able to get the values in EPL but my EPL implementation is taking too much memory from the available memory.

on all MeasurementFragment(type=“xyz”,valueFragment=“xyz”, valueSeries = “ABC”) as mf {


do some calculation

Two options to achieve that.

  1. Pulling the information periodically using the REST API and (date) filters Cumulocity IoT - OpenAPI Specification
  2. Using Notification API to subscribe on all devices with measurements and filter the relevant one: Cumulocity IoT - OpenAPI Specification

Hint: Don’t use the realTimeAPI but only Notification 2.0

Thanks a lot Stefan,

If possible for you , Can you explain me little me more with sample code . It would be great …

Hi @prakash.veer06

here is an example subscribing on measurements:

here is an example of polling data (but for the inventory, you can adapt that for the measurements):

Hello Stefan,

I am getting below error . I and running this application on my local system and connect with dev tenent.

Could you please help me in this.

023-05-25 17:08:41.087 ERROR 32832 — [subscriptions-0] .s.s.i.MicroserviceSubscriptionScheduler : Error while reacting on microservice subscription

com.cumulocity.sdk.client.SDKException: Error invoking GET http://localhost:8181/application/applicationsByName/hello-microservice-notification
at com.cumulocity.microservice.subscription.repository.impl.LegacyMicroserviceRepository.handleException( ~[microservice-subscription-1011.0.12.jar!/:na]
at com.cumulocity.microservice.subscription.repository.impl.LegacyMicroserviceRepository.getByName( ~[microservice-subscription-1011.0.12.jar!/:na]
at com.cumulocity.microservice.subscription.repository.impl.LegacyMicroserviceRepository.register( ~[microservice-subscription-1011.0.12.jar!/:na]
at com.cumulocity.microservice.subscription.repository.MicroserviceSubscriptionsRepository.register( ~[microservice-subscription-1011.0.12.jar!/:na]
at com.cumulocity.microservice.subscription.service.impl.MicroserviceSubscriptionsServiceImpl.registerApplication( ~[microservice-subscription-1011.0.12.jar!/:na]
at com.cumulocity.microservice.subscription.service.impl.MicroserviceSubscriptionsServiceImpl.subscribe( ~[microservice-subscription-1011.0.12.jar!/:na]
at com.cumulocity.microservice.subscription.service.impl.MicroserviceSubscriptionScheduler.lambda$schedulePeriodicSubscription$0( ~[microservice-subscription-1011.0.12.jar!/:na]
at java.base/java.util.concurrent.Executors$ ~[na:na]
at java.base/java.util.concurrent.FutureTask.runAndReset( ~[na:na]
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker( ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$ ~[na:na]
at java.base/ ~[na:na]
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:8181 [localhost/, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect

Hi Prakash,
I think you don’t have done the required configuration set to run a microservice locally:

You can also find good examples here:

Thanks for your reply Stefan,

I am able to deploy my microservice in Complicity and getting below logs but not getting the measurement data

80 (http) with context path ‘’
2023-05-26 08:10:22.207 INFO 13 — [main] c.e.n.helloworld.NotificationExample : Subscription added for Tenant ID:
2023-05-26 08:10:22.403 INFO 13 — [main] c.e.n.helloworld.NotificationExample : Reusing existing subscription on device <126546272>
2023-05-26 08:10:22.427 INFO 13 — [main] c.e.n.helloworld.NotificationExample : Connecting WebSocket client …
2023-05-26 08:10:22.612 INFO 13 — [WebSocketConnectReadThread-28] c.e.n.helloworld.NotificationExample : Connected to Cumulocity notification service over WebSocket ws://
2023-05-26 08:10:22.617 INFO 13 — [main] c.e.n.helloworld.HelloWorldApplication : Started HelloWorldApplication in 18.414 seconds (JVM running for 20.565)
2023-05-26 08:10:34.023 INFO 13 — [http-nio-80-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet ‘dispatcherServlet’
2023-05-26 08:10:34.023 INFO 13 — [http-nio-80-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet ‘dispatcherServlet’
2023-05-26 08:10:34.101 INFO 13 — [http-nio-80-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 78 ms

That’s hard to debug remotely. Most likely there is something wrong with your subscription. Please note that you have to subscribe on “mo” context using “measurements” subscription filter.

Hello Stefan,

I am able to deploy
with my changes and its running fine on local as well as when i deploy on VM and able to get measurements data as in listener.

I am able to deploy this microservices in complicity tenant as well and i got this response when i check the health of microservice.


“status”: “UP”,
“components”: {
“diskSpace”: {
“status”: “UP”,
“details”: {
“total”: 158395219968,
“free”: 126023880704,
“threshold”: 10485760,
“exists”: true
“heapMemory”: {
“status”: “UP”,
“details”: {
“init”: 8388608,
“used”: 34932736,
“committed”: 122683392,
“max”: 392167424,
“threshold”: 19608371
“livenessState”: {
“status”: “UP”
“nonHeapMemory”: {
“status”: “UP”,
“details”: {
“init”: 7667712,
“used”: 87188024,
“committed”: 91262976,
“max”: 377487360,
“threshold”: 18874368
“ping”: {
“status”: “UP”
“readinessState”: {
“status”: “UP”
“groups”: [

But this microservice is not listening the measurement update for specific device or all device.
Am i missing some thing . Please suggest .

That one is using the “old” realtime API. You shoud use the notification 2.0 API instead: