@midwayjs/mqtt 3.20.4 → 4.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/configuration.js +2 -3
- package/dist/decorator.js +2 -2
- package/dist/framework.d.ts +1 -1
- package/dist/framework.js +9 -15
- package/dist/service.js +7 -5
- package/package.json +6 -6
package/dist/configuration.js
CHANGED
|
@@ -21,11 +21,12 @@ let MQTTConfiguration = class MQTTConfiguration {
|
|
|
21
21
|
await this.factory.stop();
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
|
+
exports.MQTTConfiguration = MQTTConfiguration;
|
|
24
25
|
__decorate([
|
|
25
26
|
(0, core_1.Inject)(),
|
|
26
27
|
__metadata("design:type", framework_1.MidwayMQTTFramework)
|
|
27
28
|
], MQTTConfiguration.prototype, "framework", void 0);
|
|
28
|
-
MQTTConfiguration = __decorate([
|
|
29
|
+
exports.MQTTConfiguration = MQTTConfiguration = __decorate([
|
|
29
30
|
(0, core_1.Configuration)({
|
|
30
31
|
namespace: 'mqtt',
|
|
31
32
|
importConfigs: [
|
|
@@ -34,7 +35,6 @@ MQTTConfiguration = __decorate([
|
|
|
34
35
|
mqtt: {
|
|
35
36
|
pub: {},
|
|
36
37
|
sub: {},
|
|
37
|
-
contextLoggerApplyLogger: 'mqttLogger',
|
|
38
38
|
},
|
|
39
39
|
midwayLogger: {
|
|
40
40
|
clients: {
|
|
@@ -48,5 +48,4 @@ MQTTConfiguration = __decorate([
|
|
|
48
48
|
],
|
|
49
49
|
})
|
|
50
50
|
], MQTTConfiguration);
|
|
51
|
-
exports.MQTTConfiguration = MQTTConfiguration;
|
|
52
51
|
//# sourceMappingURL=configuration.js.map
|
package/dist/decorator.js
CHANGED
|
@@ -5,8 +5,8 @@ const core_1 = require("@midwayjs/core");
|
|
|
5
5
|
exports.MQTT_DECORATOR_KEY = 'rpc:mqtt';
|
|
6
6
|
function MqttSubscriber(subscriberName) {
|
|
7
7
|
return target => {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
core_1.DecoratorManager.saveModule(exports.MQTT_DECORATOR_KEY, target);
|
|
9
|
+
core_1.MetadataManager.defineMetadata(exports.MQTT_DECORATOR_KEY, subscriberName, target);
|
|
10
10
|
(0, core_1.Scope)(core_1.ScopeEnum.Request)(target);
|
|
11
11
|
(0, core_1.Provide)()(target);
|
|
12
12
|
};
|
package/dist/framework.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { IClientOptions, MqttClient } from 'mqtt';
|
|
|
4
4
|
export declare class MidwayMQTTFramework extends BaseFramework<IMidwayMQTTApplication, IMidwayMQTTContext, IMidwayMQTTConfigurationOptions> {
|
|
5
5
|
app: IMidwayMQTTApplication;
|
|
6
6
|
protected subscriberMap: Map<string, MqttClient>;
|
|
7
|
-
|
|
7
|
+
protected frameworkLoggerName: string;
|
|
8
8
|
configure(): any;
|
|
9
9
|
applicationInitialize(options: any): Promise<void>;
|
|
10
10
|
run(): Promise<void>;
|
package/dist/framework.js
CHANGED
|
@@ -5,9 +5,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
9
|
exports.MidwayMQTTFramework = void 0;
|
|
13
10
|
const core_1 = require("@midwayjs/core");
|
|
@@ -17,6 +14,7 @@ let MidwayMQTTFramework = class MidwayMQTTFramework extends core_1.BaseFramework
|
|
|
17
14
|
constructor() {
|
|
18
15
|
super(...arguments);
|
|
19
16
|
this.subscriberMap = new Map();
|
|
17
|
+
this.frameworkLoggerName = 'mqttLogger';
|
|
20
18
|
}
|
|
21
19
|
configure() {
|
|
22
20
|
return this.configService.getConfiguration('mqtt');
|
|
@@ -27,13 +25,13 @@ let MidwayMQTTFramework = class MidwayMQTTFramework extends core_1.BaseFramework
|
|
|
27
25
|
async run() {
|
|
28
26
|
const { sub } = this.configurationOptions;
|
|
29
27
|
if (Object.keys(sub || {}).length === 0) {
|
|
30
|
-
this.
|
|
28
|
+
this.logger.info('[midway-mqtt] Not found consumer config, skip init consumer');
|
|
31
29
|
}
|
|
32
30
|
// find subscriber
|
|
33
|
-
const mqttSubscriberModules =
|
|
31
|
+
const mqttSubscriberModules = core_1.DecoratorManager.listModule(decorator_1.MQTT_DECORATOR_KEY);
|
|
34
32
|
const mqttSubscriberMap = {};
|
|
35
33
|
for (const subscriberModule of mqttSubscriberModules) {
|
|
36
|
-
const subscriberName =
|
|
34
|
+
const subscriberName = core_1.MetadataManager.getOwnMetadata(decorator_1.MQTT_DECORATOR_KEY, subscriberModule);
|
|
37
35
|
mqttSubscriberMap[subscriberName] = subscriberModule;
|
|
38
36
|
}
|
|
39
37
|
for (const customKey in sub) {
|
|
@@ -43,7 +41,7 @@ let MidwayMQTTFramework = class MidwayMQTTFramework extends core_1.BaseFramework
|
|
|
43
41
|
async beforeStop() {
|
|
44
42
|
for (const [name, consumer] of this.subscriberMap) {
|
|
45
43
|
await consumer.endAsync();
|
|
46
|
-
this.
|
|
44
|
+
this.logger.info(`[midway-mqtt] subscriber: ${name} is closed`);
|
|
47
45
|
}
|
|
48
46
|
}
|
|
49
47
|
/**
|
|
@@ -76,7 +74,7 @@ let MidwayMQTTFramework = class MidwayMQTTFramework extends core_1.BaseFramework
|
|
|
76
74
|
resolve(client);
|
|
77
75
|
});
|
|
78
76
|
client.on('error', err => {
|
|
79
|
-
this.
|
|
77
|
+
this.logger.error(err);
|
|
80
78
|
});
|
|
81
79
|
});
|
|
82
80
|
consumer.on('message', async (topic, message, packet) => {
|
|
@@ -101,15 +99,11 @@ let MidwayMQTTFramework = class MidwayMQTTFramework extends core_1.BaseFramework
|
|
|
101
99
|
return Object.values(this.subscriberMap);
|
|
102
100
|
}
|
|
103
101
|
getFrameworkName() {
|
|
104
|
-
return '
|
|
102
|
+
return 'mqtt';
|
|
105
103
|
}
|
|
106
104
|
};
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
__metadata("design:type", Object)
|
|
110
|
-
], MidwayMQTTFramework.prototype, "mqttLogger", void 0);
|
|
111
|
-
MidwayMQTTFramework = __decorate([
|
|
105
|
+
exports.MidwayMQTTFramework = MidwayMQTTFramework;
|
|
106
|
+
exports.MidwayMQTTFramework = MidwayMQTTFramework = __decorate([
|
|
112
107
|
(0, core_1.Framework)()
|
|
113
108
|
], MidwayMQTTFramework);
|
|
114
|
-
exports.MidwayMQTTFramework = MidwayMQTTFramework;
|
|
115
109
|
//# sourceMappingURL=framework.js.map
|
package/dist/service.js
CHANGED
|
@@ -17,7 +17,9 @@ let MqttProducerFactory = class MqttProducerFactory extends core_1.ServiceFactor
|
|
|
17
17
|
return 'mqtt';
|
|
18
18
|
}
|
|
19
19
|
async init() {
|
|
20
|
-
await this.initClients(this.pubConfig
|
|
20
|
+
await this.initClients(this.pubConfig, {
|
|
21
|
+
concurrent: true,
|
|
22
|
+
});
|
|
21
23
|
}
|
|
22
24
|
async createClient(config, clientName) {
|
|
23
25
|
return new Promise(resolve => {
|
|
@@ -36,6 +38,7 @@ let MqttProducerFactory = class MqttProducerFactory extends core_1.ServiceFactor
|
|
|
36
38
|
this.logger.info('[midway-mqtt] producer: %s is close', name);
|
|
37
39
|
}
|
|
38
40
|
};
|
|
41
|
+
exports.MqttProducerFactory = MqttProducerFactory;
|
|
39
42
|
__decorate([
|
|
40
43
|
(0, core_1.Logger)('mqttLogger'),
|
|
41
44
|
__metadata("design:type", Object)
|
|
@@ -50,11 +53,10 @@ __decorate([
|
|
|
50
53
|
__metadata("design:paramtypes", []),
|
|
51
54
|
__metadata("design:returntype", Promise)
|
|
52
55
|
], MqttProducerFactory.prototype, "init", null);
|
|
53
|
-
MqttProducerFactory = __decorate([
|
|
56
|
+
exports.MqttProducerFactory = MqttProducerFactory = __decorate([
|
|
54
57
|
(0, core_1.Provide)(),
|
|
55
58
|
(0, core_1.Scope)(core_1.ScopeEnum.Singleton)
|
|
56
59
|
], MqttProducerFactory);
|
|
57
|
-
exports.MqttProducerFactory = MqttProducerFactory;
|
|
58
60
|
let DefaultMqttProducer = class DefaultMqttProducer {
|
|
59
61
|
async init() {
|
|
60
62
|
this.instance = this.mqttProducerFactory.get(this.mqttProducerFactory.getDefaultClientName() || 'default');
|
|
@@ -63,6 +65,7 @@ let DefaultMqttProducer = class DefaultMqttProducer {
|
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
67
|
};
|
|
68
|
+
exports.DefaultMqttProducer = DefaultMqttProducer;
|
|
66
69
|
__decorate([
|
|
67
70
|
(0, core_1.Inject)(),
|
|
68
71
|
__metadata("design:type", MqttProducerFactory)
|
|
@@ -73,10 +76,9 @@ __decorate([
|
|
|
73
76
|
__metadata("design:paramtypes", []),
|
|
74
77
|
__metadata("design:returntype", Promise)
|
|
75
78
|
], DefaultMqttProducer.prototype, "init", null);
|
|
76
|
-
DefaultMqttProducer = __decorate([
|
|
79
|
+
exports.DefaultMqttProducer = DefaultMqttProducer = __decorate([
|
|
77
80
|
(0, core_1.Provide)(),
|
|
78
81
|
(0, core_1.Scope)(core_1.ScopeEnum.Singleton)
|
|
79
82
|
], DefaultMqttProducer);
|
|
80
|
-
exports.DefaultMqttProducer = DefaultMqttProducer;
|
|
81
83
|
(0, core_1.delegateTargetAllPrototypeMethod)(DefaultMqttProducer, mqtt_1.MqttClient);
|
|
82
84
|
//# sourceMappingURL=service.js.map
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/mqtt",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-beta.1",
|
|
4
4
|
"description": "Midway Framework for mqtt",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
|
-
"test": "node
|
|
10
|
-
"cov": "node
|
|
9
|
+
"test": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand",
|
|
10
|
+
"cov": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand --coverage --forceExit",
|
|
11
11
|
"lint:fix": "../../node_modules/.bin/mwts fix"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
],
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@midwayjs/core": "^
|
|
27
|
-
"@midwayjs/mock": "^
|
|
26
|
+
"@midwayjs/core": "^4.0.0-beta.1",
|
|
27
|
+
"@midwayjs/mock": "^4.0.0-beta.1"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"mqtt": "5.10.4"
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"engines": {
|
|
38
38
|
"node": ">=16"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "832961ec3aff123c033197d8c00cb2bc9bad7ff8"
|
|
41
41
|
}
|