To realise the use case "Detect and Locate", this sample application consumes "Device Location Update" Event of the Cisco Spaces Firehose API. This can be used as a starting point and reference for consuming the Cisco Spaces Firehose API events.
Sample Application consists of the below components
- API Server
- Proxy Server
- Client
- Kafka Consumer Application
The API Server consumes "DEVICE_LOCATION_UPDATE" event and keeps updating RocksDB or Redis Cache (based on which one is enabled, by default uses RocksDB) for each Device MAC address. Server also exposes an HTTP GET API which can be invoked with a MAC address param(mac), to get recent location update for the given mac. API server also writes every event into given corresponding Kafka topic(only if Kafka configuration is enabled) which can be used by a Kafka client for further processing.
NOTE: Regarding RocksDB & Redis Cache, enable any one of them, in case of both are enabled then RocksDB will be considered for pulling data for the HTTP GET API.
- Navigate to /server/ folder in the cloned repository.
- Rename or copy /server/src/main/resources/app.default.properties file to /server/src/main/resources/app.properties and Update app.properties file (/server/src/main/resources/app.properties) with appropriate values. All the below mentioned properties are mandatory.
api.key={{Firehose API Key}}
api.url={{Firehose API URL}}
http.port={{http server port}}
redis.feeder.enabled=false
rocksdb.feeder.enabled=true
- Build the project by using
mvn install
. - Set the classes folder path in the classspath and execute
com.cisco.dnaspaces.APIConsumer
class to run the application.
Proxy Server is used to avoid CORS restriction while using the partners api for retrieving map information and image from client application. This takes the request and communicates with API and serves response to client application without any CORS Restriction
- Navigate to /client/ folder in the cloned repository.
- Rename or copy /proxy-server/proxy-server.default.properties file to /proxy-server/proxy-server.properties and update below mentioned properties with appropriate Partners API details
apiserver.host={{Partners API Host}}
apiserver.apikey={{Partners API Key}}
- In console move to /client directory of project
- Run command
npm install
- Start the node server using command
node server
The client application provides an UI to enter MAC address of client and when user clicks on "start polling", Ajax polling starts with a certain time interval to server. On each location update, co-ordinates are stacked to the screen.
- Navigate to /client/ folder in the cloned repository.
- Rename or copy /client/src/environments/environment.default.ts file to /client/src/environments/environment.ts and update below mentioned properties with appropriate Partners API details
{
"apiUrl":"{{API Server url}}",
"serverUrl":"{{Proxy Server url}}"
}
- In console move to /client directory of project
- Start the Angular application by using command
ng serve
This is a standalone sample application which subscribes to the provided Kafka Topic into which API server pushes the event data. Kafka Consumer Application subscribes to given Kafka Topic and writes every received events to console.
- Navigate to /kafka client folder in the cloned repository
- Execute
com.cisco.dnaspaces.clients.kafka.Application
class to run the application. - Application will prompt you Kafka specific configurations which you need to enter optionally. Leaving it blank will take default value.
Once all the applications are started,
- Client UI can be accessed by opening http://localhost:4200 in the browser.
- By providing the Device MAC Address, Device can be detected and located.
- Given user current location is plotted in the map using small red dot icon.
- Given user locatoin updates starting from the time of request are listed below the map