Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Summary

This example we show simple use of the IoT Data-Processing Agent. As an example, we will count the amount of events revived by the agent. For this we need:

  1. to deploy and run an agent
  2. to deploy an statement that does the counting
  3. subscribing to the results of this statement
  4. generate events so the agent can process them

Requirements 

  1. Java >= 1.8
  2. MQTT broker (locally install)
  3. mosquito clients
  4. curl
  5. wget

Notes:

For running the IoT Data-Processing Agent is only needed the (1) and a MQTT broker no matter where. Anyhow, for realizing this tutorial the all above is needed.  Please, notice that for this demo we need three console sessions. 

1) Deploy and run the agent

In the console 1 download the agent.

 

Deployment (console 1)
user@hostname:~/dir$ wget "https://linksmart.eu/repo/service/local/artifact/maven/redirect?r=releases&g=eu.linksmart.services.events.gpl.distributions.rest&a=iot.learning.rest.agent&v=LATEST" -O DataProcessingAgent.jar
Result Deployment (console 1)
--2016-09-08 15:59:52--  https://linksmart.eu/repo/service/local/artifact/maven/redirect?r=releases&g=eu.linksmart.services.events.gpl.distributions.rest&a=iot.learning.rest.agent&v=LATEST
Resolving linksmart.eu (linksmart.eu)... 193.175.161.121
Connecting to linksmart.eu (linksmart.eu)|193.175.161.121|:443... connected.
HTTP request sent, awaiting response... 307 Temporary Redirect
Location: https://linksmart.eu/repo/service/local/repositories/releases/content/eu/linksmart/services/events/gpl/distributions/rest/iot.learning.rest.agent/1.3.1/iot.learning.rest.agent-1.3.1.jar [following]
--2016-09-08 15:59:52--  https://linksmart.eu/repo/service/local/repositories/releases/content/eu/linksmart/services/events/gpl/distributions/rest/iot.learning.rest.agent/1.3.1/iot.learning.rest.agent-1.3.1.jar
Reusing existing connection to linksmart.eu:443.
HTTP request sent, awaiting response... 200 OK
Length: 89665190 (86M) [application/java-archive]
Saving to: ‘DataProcessingAgent.jar’

100%[===================================================================================================================================================================================================================================================================================>] 89.665.190  11,2MB/s   in 7,7s

2016-09-08 15:59:59 (11,2 MB/s) - ‘DataProcessingAgent.jar’ saved [89665190/89665190]

Again in console 1, we started the agent.

Run (console 1)
user@hostname:~/dir$ java -jar DataProcessingAgent.jar 
Result Run (console 1)
....
Lot of the output had being remove. 
If no exception is given then this output is not relevant now. 
....
2016-09-08 16:00:16.202  INFO 16010 --- [           main] eu.linksmart.services.Application        : Started Application in 6.607 seconds (JVM running for 9.535)

2) Deploy a statement in the agent

 
In console three we deploy a statement.

Deploy Statement (console 2)
user@hostname:~/dir$ curl -H "Content-Type: application/json" -X POST -d '{"name":"countEvents","statement":"select count(*) as obs from Observation.win:time(1 sec)"}' http://localhost:8319/statement/add

The content of the result is not important what is important is that returns 201 created as response. 

Prettify Result (console 2)
{  
   "resources":{  
      "97939930775881634626547151622159126031434832852884240170848287519360840953073":{  
         "name":"countEvents",
         "statement":"select count(*) as obs from Observation.win:time(1 sec)",
         "source":"",
         "input":[  
            ""
         ],
         "output":null,
         "stateLifecycle":"RUN",
         "scope":[  
            "default"
         ],
         "targetAgents":[  

         ],
         "id":"97939930775881634626547151622159126031434832852884240170848287519360840953073",
         "cehandler":"eu.almanac.event.datafusion.handler.ComplexEventHandler",
         "synchronousResponse":null
      }
   },
   "overallStatus":201,
   "responsesTail":{  
      "headline":"Created",
      "agentID":"0ab8b321-b182-4e72-812c-bd7b9ea31d3c",
      "producerID":"EsperEngine",
      "producerName":"CEPEngine",
      "message":"Statement 97939930775881634626547151622159126031434832852884240170848287519360840953073 was successful",
      "status":201,
      "messageType":"SUCCESS",
      "topic":"0ab8b321-b182-4e72-812c-bd7b9ea31d3c/EsperEngine/"
   },
   "responses":[  
      {  
         "headline":"Created",
         "agentID":"0ab8b321-b182-4e72-812c-bd7b9ea31d3c",
         "producerID":"EsperEngine",
         "producerName":"CEPEngine",
         "message":"Statement 97939930775881634626547151622159126031434832852884240170848287519360840953073 was successful",
         "status":201,
         "messageType":"SUCCESS",
         "topic":"0ab8b321-b182-4e72-812c-bd7b9ea31d3c/EsperEngine/"
      }
   ],
   "headResourceKey":"97939930775881634626547151622159126031434832852884240170848287519360840953073",
   "headResource":{  
      "name":"countEvents",
      "statement":"select count(*) as obs from Observation.win:time(1 sec)",
      "source":"",
      "input":[  
         ""
      ],
      "output":null,
      "stateLifecycle":"RUN",
      "scope":[  
         "default"
      ],
      "targetAgents":[  

      ],
      "id":"97939930775881634626547151622159126031434832852884240170848287519360840953073"
   }
}

We subscribe to the all statements.

Subscribe to an event (Console 2)
user@hostname:~/dir$ mosquitto_sub -t /out/#

3) Subscribe to the statement 


For see the result of the of the statement we need to generate data. For this we publish an event payload located in the file event.json.

 

Generate event (console 3)
user@hostname:~/dir$ mosquitto_pub -t /in/something -f event.json

4) Generate data 

 

event.json
{  
   "Datastream":{  
      "id":"1"
   },
   "ResultValue":1,
   "ResultType":"Int",
   "Time":"2015-09-08T17:16:12.00Z",
   "Sensor":{  
      "id":"1"
   },
   "id":"1"
}

Then in console 2, we can see the result. Quicker the data is being generate the "ResulValue" will increase. 

Result (Console 2)
{"Time":"2016-09-08T15:18:36.367+0000","ResultValue":1,"ResultType":"obs","Datastream":{"id":"98ce0a31-53c1-484a-a1a3-2c1d677060f1"},"Sensor":{"id":"98ce0a31-53c1-484a-a1a3-2c1d677060f1"}}


 

  • No labels