Question

SDC - Connect & Subscribe to Http Client

  • 6 December 2022
  • 3 replies
  • 47 views

Hi

I am a newbie at Streamset and its DC. I am currently trying to connect to Cumulocity IoT and streams device measurement to store them into a file. Cumulocity offers a public REST API and it is possible to subscribe to real-time measurements once the client is connected. So what i m trying to achieve in my pipeline is as per below:

  1. create an handshake with Cumulocity IoT
  2. Subscribe to the measurement channel with the client ID generated in the response of step 1
  3. Receive the measurements and store them

 

For step 1, I used as Origin the HTTP Client. It does connect to Cumulocity and does generate a clientId. However, I would like for the origin to just send 1 request and stops sending any other handshake request afterwards. At the moment it is sending handshake request continuously and therefore generating continuously different clientId which is not what I want. How do I limit this stage to send only 1 request? As a temp workaround I put the stage as Batch mode, with a batch size of 1 and a connect Timeout of 1sec. But this is a bit dirty and would like to know the proper way to handle the sending of 1 request only?

 

For step 2, I need to use the generated clientId from step 1 inside the body of my POST request in step 2. However I always have some syntax issues and I am not sure how to extract the field and use it within the body. Is is possible to use an extracted field from my response in the Handshake within the body? Can you please help ? 

 

For step 3, I have no idea if it is all possible to accomplish. Indeed, once the subscription is established, then Cumulocity will automatically sends the measurements to the created channel and they will be in JSON. Which SDC stage(s) could i then use to ensure i receive those measurements in a streaming mode? The pipeline will be subscribed to the channel but I dont know how to say “now listen to some JSON messages which will be coming at different intervals and parse them”.

Thank you

 


3 replies

Userlevel 2

Hi Melanie,

I will give you a message directly, But I think for step 1 I would do this as a Starter Pipeline, which would then fire off the Streaming pipeline

Step 2, You need to consider the speech marks required by the API to handle strings, also check that the field matches the source as its case sensitive.

[
  {
    "channel": "/meta/subscribe",
    "clientId": "${record:value('/clientId')}",
    "subscription": "/measurements/22166059"
  }
]


Step 3, Lets work on together, but I'm sure is do-able

@antmcmullen Hi Anthony, sure i can put the origin stage in a separate pipeline but i still dont know how to configure the stage so it only makes one request.

Userlevel 4
Badge

hi @Melanie 

 

In HTTP Client, change the Execution mode to Batch.

 

 

Reply