3.0.4 • Published 6 months ago

@diyaner/egg-mqtt v3.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

egg-mqtt

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Install

$ npm i @diyaner/egg-mqtt --save

Usage

// {app_root}/config/plugin.js
exports.mqtt = {
	enable: true,
	package: "@diyaner/egg-mqtt",
};

Configuration

// {app_root}/config/config.default.js
exports.mqtt = {
	enable: true,
	clients: [],
};

see config/config.default.js for more detail.

Example

在 app 上挂载 mqtt 客户端调用,发布订阅和接收消息。 在 agent 上挂载 mqtts 存储所有连接实例。

// 在app.ts中使用
// 推荐注册回调,当agent上mqtt连接完成后会触发回调来执行初始化逻辑
this.app.mqtt.onConnected(() => {
	const client = this.app.mqtt.get(this.app, "eggMQTTPluginTest");
	client.onMessage((topic, msg) => {
		console.log("topic", topic);
		console.log("msg", msg);
	});
	const opt: mqtt.IClientPublishOptions = {
		retain: false,
	};
	client.publish(
		"topic/abc/bcd",
		{ a: 1, b: 2 },
		{
			...opt,
		}
	);
	client.subscribe("hello/world", { qos: 2 });
});
// 其他情况,在service中调用发布,按正常使用即可。
// fetch api 通过payload的特殊字段messageId实现请求响应模型。要求消息消费者端必须携带返回messageId

Questions & Suggestions

Please open an issue here.

License

MIT

3.0.4

6 months ago

3.0.3

10 months ago

3.0.2

10 months ago

3.0.1

10 months ago

3.0.0

10 months ago

2.1.0

10 months ago

2.0.1

1 year ago

2.0.0

1 year ago

1.4.0

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.2.0

1 year ago

1.1.0

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago