Skip to content

Commit dfa1693

Browse files
HiveMQ
1 parent a6bdcaa commit dfa1693

File tree

3 files changed

+24
-35
lines changed

3 files changed

+24
-35
lines changed

docs/modules/arangodb.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
npm install @testcontainers/arangodb --save-dev
77
```
88

9-
## Example
9+
## Examples
1010

11-
This example uses the following libraries:
11+
These examples use the following libraries:
1212

1313
- [arangojs](https://www.npmjs.com/package/arangojs/v/6.0.0-alpha.0)
1414

docs/modules/hivemq.md

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
1-
# HiveMQ MQTT Module
2-
3-
This module allows automatic start up of [HiveMQ's](https://www.hivemq.com/) docker container within
4-
test suites, to enable programmatic testing of JavaScript based MQTT client applications.
1+
# HiveMQ
52

63
## Install
74

85
```bash
96
npm install @testcontainers/hivemq --save-dev
107
```
118

12-
## Resources
13-
14-
- [Community forum](https://community.hivemq.com/)
15-
- [HiveMQ website](https://www.hivemq.com/)
16-
- [MQTT Essentials](https://www.hivemq.com/mqtt-essentials/)
17-
- [MQTT 5 Essentials](https://www.hivemq.com/mqtt-5/)
9+
## Examples
1810

19-
Please make sure to check out the hivemq-docs for the [Community Edition](https://github.com/hivemq/hivemq-community-edition/wiki/).
11+
These examples use the following libraries:
2012

21-
!!! Info
22-
We are working to support the HiveMQ Enterprise Edition as outlined in the [Java Test Containers Module](https://java.testcontainers.org/modules/hivemq/).
13+
- [mqtt](https://www.npmjs.com/package/mqtt)
2314

24-
## Examples
15+
npm install mqtt
2516

26-
<!--codeinclude-->
17+
Choose an image from the [container registry](https://hub.docker.com/r/hivemq/hivemq-ce) and substitute `IMAGE`.
2718

28-
[Connect with a mqtt.js client to HiveMQ](../../packages/modules/hivemq/src/hivemq-container.test.ts) inside_block:connect
19+
### Produce/consume a message
2920

21+
<!--codeinclude-->
22+
[](../../packages/modules/hivemq/src/hivemq-container.test.ts) inside_block:hivemqConnect
3023
<!--/codeinclude-->

packages/modules/hivemq/src/hivemq-container.test.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,28 @@ import mqtt from "mqtt";
22
import { expect } from "vitest";
33
import { getImage } from "../../../testcontainers/src/utils/test-helper";
44
import { HiveMQContainer } from "./hivemq-container";
5+
56
const IMAGE = getImage(__dirname);
67

78
describe("HiveMQContainer", { timeout: 240_000 }, () => {
8-
// connect {
99
it("should connect to HiveMQ Community Edition via MQTT.js", async () => {
10+
// hivemqConnect {
1011
await using container = await new HiveMQContainer(IMAGE).start();
1112

12-
const testMqttClient = mqtt.connect(container.getConnectionString());
13+
const mqttClient = await mqtt.connectAsync(container.getConnectionString());
1314

14-
const promise = new Promise<void>((resolve) => {
15-
testMqttClient.on("message", (topic, message) => {
16-
expect(message.toString()).toEqual("Test Message");
17-
testMqttClient.end();
18-
resolve();
19-
});
15+
const firstMessagePromise = new Promise<{ topic: string; message: Buffer }>((resolve, reject) => {
16+
mqttClient.once("message", (topic, message) => resolve({ topic, message }));
17+
mqttClient.once("error", (err) => reject(err));
2018
});
2119

22-
testMqttClient.on("connect", () => {
23-
testMqttClient.subscribe("test", (error) => {
24-
if (!error) {
25-
testMqttClient.publish("test", "Test Message");
26-
}
27-
});
28-
});
20+
await mqttClient.subscribeAsync("test");
21+
await mqttClient.publishAsync("test", "Test Message");
22+
23+
const { message } = await firstMessagePromise;
24+
expect(message.toString()).toEqual("Test Message");
2925

30-
await expect(promise).resolves.toBeUndefined();
26+
mqttClient.end();
27+
// }
3128
});
32-
// }
3329
});

0 commit comments

Comments
 (0)