1
1
# Device Communication API
2
2
3
3
Device communication API enables users and applications to send configurations and commands to devices via HTTP(S)
4
- endpoints.
4
+ endpoints as well as retrieve states of devices .
5
5
6
6
![ img.png] ( img.png )
7
7
8
8
### Application
9
9
10
- The application is reactive and uses Quarkus Framework for the application and Vertx tools for the HTTP server.
10
+ The application is reactive and uses the Quarkus framework for the application and Vert.x tools for the HTTP server.
11
11
12
12
### Hono internal communication
13
13
14
- API uses [ Google's PubSub] ( https://cloud.google.com/pubsub/docs/overview?hl=de ) service to communicate with the command
15
- router.
14
+ The application uses [ Google's PubSub] ( https://cloud.google.com/pubsub/docs/overview?hl=de ) service to communicate with
15
+ the command router.
16
16
17
17
## API endpoints
18
18
@@ -32,32 +32,41 @@ router.
32
32
33
33
- POST: create a device config version
34
34
35
- For more information please see resources/api/openApi file.
35
+ For more information please see resources/api/hono-endpoint.yaml file.
36
36
37
37
## Pub/Sub - Internal Messaging
38
38
39
- API communicates with hono components via the internal messaging interface (implemented from Google's PubSub).
40
- All the settings for the InternalMessaging component are in the application.yaml file. By publish/subscribe to a topic
41
- application sends or expects some message attributes.
39
+ The application communicates with hono components via the internal messaging interface (implemented for Google PubSub).
40
+ The settings for the internal messaging component can be found in the application.yaml file.
42
41
43
42
### Events
44
43
45
- API will subscribe to all tenants' event topic at startup.
44
+ The application subscribes to all tenants' event topic at startup to listen for config requests .
46
45
47
- Expected message Attributes:
46
+ #### MQTT config request (empty notification)
47
+
48
+ Expected message attributes:
48
49
49
50
- deviceId
50
51
- tenantId
51
- - content-type
52
+ - content-type (must be "application/vnd.eclipse-hono-empty-notification")
53
+ - ttd (must be -1)
52
54
53
- Application will <b >proceed only empty Notifications events (content-type is
54
- application/vnd.eclipse-hono-empty-notification)</b >.
55
+ #### HTTP config request
56
+
57
+ Expected message attributes:
58
+
59
+ - deviceId
60
+ - tenantId
61
+ - ttd (must not be blank or empty)
62
+ - orig_adapter (must be "hono-http")
63
+ - orig_address (must contain "config")
55
64
56
65
### States
57
66
58
- API will subscribe to all tenants' state topic at startup.
67
+ The application subscribes to all tenants' state topic at startup.
59
68
60
- Expected message Attributes :
69
+ Expected message attributes :
61
70
62
71
- deviceId
63
72
- tenantId
@@ -66,49 +75,71 @@ States are read only.
66
75
67
76
### Configs
68
77
69
- Application will publish the latest device configuration when:
78
+ The application publishes the latest device configuration when:
70
79
71
- - an empty Notifications event was received
72
- - a new device config was created
80
+ - An empty notification event is received (MQTT device subscribed to the command topic)
81
+ - A config request from an HTTP device is received
82
+ - A new device config is created
73
83
74
- Message will be published with the following attributes:
84
+ Message attributes:
75
85
76
86
- deviceId
77
87
- tenantId
78
- - config-version
88
+ - correlation-id (the config version)
89
+ - subject (always set to "config")
90
+ - ack-required (always set to true)
91
+
92
+ Body:
79
93
80
- The Body will be a JSON object with the device config object.
94
+ A JSON object with the device config object.
81
95
82
- After publishing device configs, application subscribes to config_response topic and waits for the device to ack the
83
- configs .
96
+ After publishing a device config, the application waits internally for an acknowledgement from the device on the
97
+ command_response topic to update the "device_ack_time" in the database .
84
98
85
99
### Config ACK
86
100
87
101
Expected message attributes:
88
102
89
103
- deviceId
90
104
- tenantId
91
- - configVersion (the config version received from device )
92
-
93
- If configVersion is not set, application will ack always the latest config.
105
+ - correlation-id (the config version)
106
+ - content-type (must be "application/vnd.eclipse-hono-delivery-success-notification+json")
107
+ - subject (must be " config")
94
108
95
109
### Commands
96
110
97
- A command will be published from API to the command topic.
111
+ A command will be published from the application to the command topic.
98
112
99
113
Attributes:
100
114
101
115
- deviceId
102
116
- tenantId
103
- - subject (always set to "command")
117
+ - subject (if not specified set to "command")
118
+ - response-required (optional)
119
+ - ack-required (optional)
120
+ - correlation-id (optional)
121
+ - timeout (optional)
104
122
105
123
Body:
106
124
107
125
The command as string.
108
126
127
+ If ack-required is set to "true", the request will wait for the duration of the specified timeout (in milliseconds)
128
+ for an acknowledgement from the device on the command_response topic.
129
+
130
+ ### Command ACK
131
+
132
+ Expected message attributes:
133
+
134
+ - deviceId
135
+ - tenantId
136
+ - correlation-id
137
+ - content-type (must be "application/vnd.eclipse-hono-delivery-success-notification+json")
138
+ - subject (must not be "config")
139
+
109
140
## Database
110
141
111
- Application uses PostgresSQL database. All the database configurations can be found in application.yaml file.
142
+ The application uses a PostgreSQL database. All the database configurations can be found in the application.yaml file.
112
143
113
144
### Tables
114
145
@@ -121,29 +152,29 @@ Application uses PostgresSQL database. All the database configurations can be fo
121
152
122
153
### Migrations
123
154
124
- When Applications starts tables will be created by the DatabaseSchemaCreator service.
155
+ When the application starts the tables will be created by the DatabaseSchemaCreator service.
125
156
126
- ### Running postgresSQL container local
157
+ ### Running PostgresSQL container locally
127
158
128
- For running the PostgresSQL Database local with docker run :
159
+ The docker run command for running the PostgreSQL database locally :
129
160
130
161
``````
131
162
132
163
docker run -p 5432:5432 --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
133
164
134
165
``````
135
166
136
- After the container is running, log in to the container and with psql create the database. Then we have
137
- to set the application settings.
167
+ After the container is running, log in to the container and with psql create the database. Then we have to set the
168
+ application settings.
138
169
139
- Default postgresSQl values:
170
+ Default PostgreSQl values:
140
171
141
172
- userName = postgres
142
173
- password = mysecretpassword
143
174
144
- ## Build and Push API Docker Image
175
+ ## Build and push the application's Docker image
145
176
146
- Mavens auto build and push functionality can be enabled from application.yaml settings:
177
+ Mavens auto build and push functionality can be enabled in the application.yaml settings:
147
178
148
179
````
149
180
quarkus:
@@ -154,45 +185,49 @@ quarkus:
154
185
image: "eclipse/hono-device-communication"
155
186
````
156
187
157
- By running maven package, install or deploy will automatically build the docker image and if push is enabled it will
158
- push the image
159
- to the given registry.
188
+ By running maven package, install or deploy the docker image will automatically be built and if push is enabled it will
189
+ push the image to the registry specified in the image path.
160
190
161
191
## OpenApi Contract-first
162
192
163
- For creating the endpoints, Vertx takes the openApi definition file and maps every endpoint operation-ID with a specific
164
- Handler
165
- function.
193
+ For creating the endpoints, Vert.x takes the openApi definition file and maps every endpoint operation-ID with a
194
+ specific handler function.
166
195
167
196
## Handlers
168
197
169
- Handlers are providing callBack functions for every endpoint. Functions are going to be called automatically from vertx
170
- server every time a request is received.
198
+ Handlers are providing callBack functions for every endpoint. Functions are going to be called automatically from the
199
+ Vert.x server every time a request is received.
171
200
172
- ## Adding a new Endpoint
201
+ ## Adding a new endpoint
173
202
174
- Adding new Endpoint steps:
203
+ Adding new endpoint steps:
175
204
176
- 1 . Add Endpoint in openApi file and set an operationId
177
- 2 . Use an existing const Class or create a new one under /config and set the operation id name
178
- 3 . Implement an HttpEndpointHandler and set the Routes
205
+ 1 . Add endpoint in openApi (hono-device-communication-v1.yaml) and swagger (hono-endpoint.yaml) file and set an
206
+ operationId in the openApi file
207
+ 2 . Depending on the endpoint, create a new HttpEndpointHandler or use an existing one (in case it's a new one, add it to
208
+ the availableHandlerServices within the VertxHttpHandlerManagerService)
209
+ 3 . Implement the method and set the routes within the handler
179
210
180
211
## PubSub Events
181
212
182
- Application subscribes and uses to the following topics:
213
+ The application publishes and subscribes to the following topics:
183
214
184
- 1 . TENANT_ID.command
185
- 2 . TENANT_ID.command_response
186
- 3 . TENANT_ID.event
187
- 4 . TENANT_ID.event.state
188
- 5 . registry-tenant.notification
215
+ publish:
216
+ * TENANT_ID.command
189
217
190
- ## Automatically create PubSub topics and subscriptions
218
+ subscribe:
219
+ * TENANT_ID.command_response
220
+ * TENANT_ID.event
221
+ * TENANT_ID.event.state
222
+ * registry-tenant.notification
191
223
192
- Application creates all tenants topics and subscriptions when:
224
+ ## Automatically create and delete PubSub topics and subscriptions
193
225
194
- 1 . Application starts if are not exist
195
- 2 . New tenant is created
226
+ The application creates tenant topics and subscriptions when:
196
227
228
+ * The application starts, if they do not exist already
229
+ * A new tenant is created
197
230
231
+ The application deletes tenant topics and subscriptions when:
198
232
233
+ * A tenant is deleted
0 commit comments