Issues with receiving real-time measurements using websockets

Hello Community,

What product/components do you use and which version/fix level are you on?

Question related to receiving real-time measurements with Cumulocity IoT.

Is your question related to the free trial, or to a production (customer) instance?

I am using free trial tenant.

What are you trying to achieve? Please describe it in detail.

I am trying to get real-time measurements using “notification2” websocket.
All looks good for first time after establishing data channel but after 1-2 minutes websocket stops receiving new data and I need to restart websocket to continue getting measurements updates.
Already tried few different websockets from Node-Red, NodeJS, and Postman but behaviour the same.

Steps to reproduce:

  1. Ensure subscription created and if not create one:
    Make POST request to https://<tenant_id>.eu-latest.cumulocity.com/notification2/subscriptions with following body:
{
    "source": {
        "id": <source_id>
    },
    "context": "mo",
    "subscription": "SubscriptionName",
    "subscriptionFilter": {
        "apis": [ "measurements" ]
    }
}
  1. Request new token:
    Make POST request to https://<tenant_id>.eu-latest.cumulocity.com/notification2/token with following body:
{
    "subscriber": "MySubscriber",
    "subscription": "SubscriptionName"
}
  1. Use token from response of previous request to make websocket connection:
    wss://<tenant_id>.eu-latest.cumulocity.com/notification2/consumer/?token=<new_token>

Result:
Receiving data for 1-2 mins and after that steam stucks without any errors (websocket connection looks good)

Could you please explain what I am doing wrong

Best regards,
Maksym Taran

I have a similar issue. I received only 1000 measurements through websocket and didn’t receive new ones. Does anybody know why only 1000 measurements were received in websocket and all new ones were ignored?

Hi guys. I tried notification2 with Websocket to get measurements and managedObjects. It works well and gets all the data. The duration of the connection and the amount of data don’t have any effect of the data reception in my case. Here are my steps:

  1. Create a subscription: send post request to “https://<tenant_id>.eu-latest.cumulocity.com/notification2/subscriptions”. Context is mo, apis has “measurements” and “managedObjects”.
  2. Create a token: send post request to “https://<tenant_id>.eu-latest.cumulocity.com/notification2/token”. Payload of it has “subscription”," subscriber" and “expiresInMinutes”.
  3. Build the Websocket connection using Python package “websocket”.

After 10 mins I can still get the data of measurements and managedObjects. After 1000 measurements it can still receive new measurements.

Hi,

are you aware of the notification acknowledgements mechanism?

The WebSocket service sends a sequence of notifications to the consumer and the consumer should send back a short acknowledgement over this connection for each notification received.

Hence without the acknowledgements the server might close the connection.

Regards Kai

2 Likes

I suspect Kai is correct here. The default internal queue size for unacknowledged notifications is 1,000 - once that queue is full no further messages will be delivered to the consumer until some of the pending ones have been acknowledged.

You might be interested in the example notifications microservice that demonstrates how to receive and acknowledge notifications with a couple of different Java-based websocket clients: cumulocity-examples/hello-world-notification-microservice at develop · SoftwareAG/cumulocity-examples (github.com).

Thanks,

Scott

3 Likes

In case you have troubles finding the spot in the code, check line 31 here in one of the implementations of websocket clients.

2 Likes