You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(binding-mqtt): add selfHost documentation for MQTT broker
Add comprehensive documentation for the selfHost feature that allows
hosting an embedded MQTT broker within node-wot applications. Includes
examples for basic setup, authentication, and TLS configuration.
Closes#876
Signed-off-by: jona42-ui <jonathanthembo123@gmail.com>
Copy file name to clipboardExpand all lines: packages/binding-mqtt/README.md
+59Lines changed: 59 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -176,6 +176,65 @@ try {
176
176
}
177
177
```
178
178
179
+
### Hosting your own MQTT Broker
180
+
181
+
Instead of connecting to an external MQTT broker, you can host your own MQTT broker within your node-wot application by setting the `selfHost` option to `true`. This is useful for testing, development, or when you want to run a self-contained application.
// Your Things will now use the self-hosted broker
193
+
WoT.produce({
194
+
title:"My Thing",
195
+
// ... rest of Thing Description
196
+
}).then((thing) => {
197
+
thing.expose();
198
+
});
199
+
});
200
+
```
201
+
202
+
#### Self-Hosted Broker with Authentication
203
+
204
+
You can also add authentication to your self-hosted broker by providing credentials:
205
+
206
+
```js
207
+
constservient=newServient();
208
+
servient.addServer(
209
+
newMqttBrokerServer({
210
+
uri:"mqtt://localhost:1883",
211
+
selfHost:true,
212
+
selfHostAuthentication: [
213
+
{ username:"user1", password:"password1" },
214
+
{ username:"user2", password:"password2" },
215
+
],
216
+
})
217
+
);
218
+
```
219
+
220
+
#### Self-Hosted Broker with TLS
221
+
222
+
For secure communication, you can enable TLS on your self-hosted broker:
223
+
224
+
```js
225
+
constfs=require("fs");
226
+
227
+
constservient=newServient();
228
+
servient.addServer(
229
+
newMqttBrokerServer({
230
+
uri:"mqtts://localhost:8883",
231
+
selfHost:true,
232
+
key:fs.readFileSync("path/to/private-key.pem"),
233
+
cert:fs.readFileSync("path/to/certificate.pem"),
234
+
})
235
+
);
236
+
```
237
+
179
238
### More Examples
180
239
181
240
There are example implementations provided in the [example/scripting folder](https://github.com/eclipse-thingweb/node-wot/tree/master/examples/scripts).
0 commit comments