Skip to content

Commit 6e25aff

Browse files
committed
spec: c8y mqtt service connection spec
1 parent 3c9cfc0 commit 6e25aff

File tree

1 file changed

+171
-0
lines changed

1 file changed

+171
-0
lines changed
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# Connect to C8Y MQTT service endpoint
2+
3+
* Date: __2024-06-23__
4+
* Status: __New__
5+
6+
## Requirement
7+
8+
Cumulocity has introduced a new [MQTT service endpoint](https://cumulocity.com/docs/device-integration/mqtt-service)
9+
that allows users to send free-form messages (any arbitrary topic and payload) to Cumulocity.
10+
It does not replace the existing core MQTT endpoint and hence a separate connection is required.
11+
To support the same, `tedge connect` must be enhanced to connect to this new endpoint as well,
12+
in addition to the existing connection to the core endpoint.
13+
14+
## MQTT service specifications/limitations
15+
16+
- The mqtt service endpoint is exposed at the same tenant URL via port 9883 (with TLS).
17+
- Both username/password based and cert based authentication is supported.
18+
- Only connections with clean session enabled are supported. Persistent connection attempts are rejected.
19+
- Subscribing to wildcard topics (`#` and `+`) and system topics (starting with `$SYS`) are not supported.
20+
- Publishing/subscribing to legacy C8Y topics (SmartREST and JSON over MQTT) are not supported either.
21+
- QoS 2 is not supported.
22+
- Retained flag is accepted, but ignored.
23+
- There are limits to the number of topics that can be created
24+
and the number of messages that can be queued per topic.
25+
Publishes are rejected when the queue is full.
26+
- Each published message has a time-to-live, after which it is cleared from the queue.
27+
The subscribed clients are not notified of expired messages.
28+
29+
## Solutions
30+
31+
To establish a bridge connection to the mqtt service endpoint, the following info must be provided in the connect request:
32+
33+
* host: Same as legacy mqtt endpoint
34+
* port: 9883 by default
35+
* auth:
36+
* for username/password based authentication
37+
* username: `<tenant_id>/<user_name>`
38+
* password
39+
* for cert based authentication
40+
* device cert path
41+
* device key path
42+
* server root ca path
43+
* username: `<tenant_id>`
44+
* bridge topics: `<bridge_topic_prefix>/#`
45+
46+
:::note
47+
Even for cert based auth, the `username` must be provided with the tenant id.
48+
:::
49+
50+
The following are the solution approaches that are considered:
51+
52+
### Approach 1: Connect to mqtt service along with core mqtt connection
53+
54+
The mqtt service bridge connection is established along with `tedge connect c8y` command.
55+
56+
:::note
57+
For the builtin bridge functionality, whether to spawn a different mapper,
58+
or establish a secondary connection from the existing mapper itself is to be decided.
59+
The same applies for the trivial mapping rule that adds the timestamp to the payload.
60+
:::
61+
62+
#### Configuration
63+
64+
The mqtt service connection related configs are defined under the `[c8y]` table in `tedge.toml` :
65+
66+
| Config | Description | Default |
67+
| ------ | ----------- | ------- |
68+
| `c8y.mqtt_service.enabled` | Whether the mqtt server connection must be established or not | `false` |
69+
| `c8y.mqtt_service.url` | The config URL for the MQTT service | `<c8y.url>:9883` |
70+
| `c8y.mqtt_service.topic_prefix` | topic prefix used to bridge mqtt topics | `c8y-mqtt` |
71+
72+
To support connecting exclusively to the mqtt service, excluding the core mqtt connection,
73+
a config flag (`c8y.core_mqtt.enabled`) to enable/disable the core mqtt connection can also be introduced.
74+
75+
76+
To connect to the mqtt service, it must be enabled before `tedge connect c8y` is executed:
77+
78+
```sh
79+
tedge config set c8y.mqtt_service.enabled "true"
80+
```
81+
82+
:::note
83+
The tenant id which must be passed in the username is retrieved using the `https://<c8y.url>/tenant/currentTenant` REST API.
84+
An alternative is to take this as an additional `c8y.tenant_id` configuration.
85+
:::
86+
87+
#### Connection
88+
89+
The command to connect to C8Y remains the same:
90+
91+
```sh
92+
tedge connect c8y
93+
```
94+
95+
The connection to the mqtt service is established only if it is enabled.
96+
97+
**Pros**
98+
99+
- Makes the mqtt service connection seamless for existing users, with minimal configuration.
100+
- Reuse most of the existing configurations like `c8y.url`, `c8y.device.key_path`, `c8y.device.cert_path` etc.
101+
- Users can choose **not** to connect to the new endpoint, by keeping it disabled.
102+
- In future, if the core mqtt connection is replaced with the new mqtt service,
103+
we can just switch what is enabled and disabled by default.
104+
105+
**Cons***
106+
107+
- The mqtt service connection is tied to the direct `c8y` connection, to retrieve the tenant id
108+
(although this dependency can be removed if tenant id is accepted via config).
109+
110+
### Approach 2: Connect to mqtt service as an independent cloud endpoint
111+
112+
Do not establish both the core mqtt connection and the mqtt service connection together with `tedge connect c8y` command,
113+
but treat the mqtt service as an independent/generic MQTT broker endpoint like connecting to AWS or AZ endpoints.
114+
115+
#### Configuration
116+
117+
As an independent cloud endpoint, the following config values must be provided:
118+
119+
```sh
120+
tedge config set remote.url example.cumulocity.com:9883
121+
tedge config set remote.username t123456
122+
tedge config set remote.bridge.topic_prefix c8y-mqtt
123+
```
124+
125+
The following setting can also be configured, though they all have default values:
126+
127+
| Config | Description | Default |
128+
| ------ | ----------- | ------- |
129+
| `remote.device.cert_path` | The device cert path used for the authentication | Same as `device.cert_path` |
130+
| `remote.device.key_path` | The device cert path used for the authentication | Same as `device.key_path` |
131+
132+
In addition to the above, pretty much all the configs defined in the `tedge.toml` for `az` and `aws` can be defined
133+
for this generic `remote` endpoint as well, as none of them are cloud specific but applies to any mqtt broker.
134+
135+
#### Connection
136+
137+
```sh
138+
tedge connect remote
139+
```
140+
141+
**Pros**
142+
143+
- Clear separation from `tedge connect c8y` allows the second connection to be established and disconnected on demand.
144+
- Existing users are not affected, as the `tedge connect c8y` behavior stays the same.
145+
- Allows customers to connect exclusively to the new mqtt service, if they don't need the core mqtt connection.
146+
- There is no real dependency on Cumulocity as multiple `remote` profiles can be used to connect to any generic broker.
147+
148+
**Cons**
149+
150+
- Many of the config parameters defined in the `c8y` profile like the `url`, `cert_path` etc
151+
will have to be duplicated in `remote` profile as well.
152+
- When the device is connected to multiple c8y cloud profiles,
153+
corresponding `remote` profiles must be configured explicitly per c8y instance.
154+
155+
### Approach 3: Connect to all configured cloud instances with tedge connect
156+
157+
This is more of an extension of `Approach 2`, where instead of explicitly connecting to each cloud instance/profile,
158+
a `tedge connect` command (without the cloud arg), detects all the cloud profiles that are configured/enabled
159+
and connects to each endpoint one by one.
160+
161+
Only the cloud instances with a `url` explicitly configured are considered as enabled.
162+
An additional `enabled` flag can be added to each cloud profile, to skip connecting to it, even when it is configured.
163+
164+
#### Configuration
165+
166+
TBD
167+
168+
#### Connection
169+
170+
TBD
171+

0 commit comments

Comments
 (0)