xcraft-core-busclient 5.2.0 → 5.2.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/index.js +11 -11
- package/lib/command.js +6 -4
- package/lib/events.js +4 -5
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -533,28 +533,28 @@ class BusClient extends EventEmitter {
|
|
|
533
533
|
}
|
|
534
534
|
|
|
535
535
|
registerEvents(topic, handler) {
|
|
536
|
-
const
|
|
536
|
+
const str = topic.str || xUtils.regex.toXcraftRegExpStr(topic);
|
|
537
|
+
const ids = topic.ids || extractIds(topic);
|
|
538
|
+
const reg = topic.reg || new RegExp(str);
|
|
537
539
|
|
|
538
|
-
if (this._eventsRegistry[
|
|
540
|
+
if (this._eventsRegistry[str]) {
|
|
539
541
|
xLog.info(`${topic} already registered, unsub and sub again`);
|
|
540
542
|
this.unregisterEvents(topic);
|
|
541
543
|
}
|
|
542
544
|
|
|
543
|
-
const re = new RegExp(escapeTopic);
|
|
544
|
-
const ids = extractIds(topic);
|
|
545
545
|
const id = ids[ids.length - 1];
|
|
546
|
-
this._eventsCache.set(id,
|
|
547
|
-
this._eventsRegistry[
|
|
548
|
-
topic:
|
|
546
|
+
this._eventsCache.set(id, str, reg);
|
|
547
|
+
this._eventsRegistry[str] = {
|
|
548
|
+
topic: reg,
|
|
549
549
|
handler,
|
|
550
|
-
unregister: () => this._unregister(id,
|
|
550
|
+
unregister: () => this._unregister(id, str),
|
|
551
551
|
};
|
|
552
552
|
}
|
|
553
553
|
|
|
554
554
|
unregisterEvents(topic) {
|
|
555
|
-
const
|
|
556
|
-
if (this._eventsRegistry[
|
|
557
|
-
this._eventsRegistry[
|
|
555
|
+
const str = topic.str || xUtils.regex.toXcraftRegExpStr(topic);
|
|
556
|
+
if (this._eventsRegistry[str]) {
|
|
557
|
+
this._eventsRegistry[str].unregister();
|
|
558
558
|
}
|
|
559
559
|
}
|
|
560
560
|
|
package/lib/command.js
CHANGED
|
@@ -8,6 +8,11 @@ var xLog = require('xcraft-core-log')(moduleName, null);
|
|
|
8
8
|
function Command(busClient, pushSocket) {
|
|
9
9
|
this._busClient = busClient;
|
|
10
10
|
this._push = pushSocket;
|
|
11
|
+
|
|
12
|
+
const {appId, appArgs} = require('xcraft-core-host');
|
|
13
|
+
const {tribe} = appArgs();
|
|
14
|
+
|
|
15
|
+
this._routingKey = tribe ? `${appId}-${tribe}` : appId;
|
|
11
16
|
}
|
|
12
17
|
|
|
13
18
|
Command.prototype.connectedWith = function () {
|
|
@@ -67,11 +72,8 @@ Command.prototype.send = function (
|
|
|
67
72
|
}
|
|
68
73
|
|
|
69
74
|
if (!busMessage.arp) {
|
|
70
|
-
const {appId, appArgs} = require('xcraft-core-host');
|
|
71
|
-
const {tribe} = appArgs();
|
|
72
|
-
const routingKey = tribe ? `${appId}-${tribe}` : appId;
|
|
73
75
|
let token = xBus.getToken();
|
|
74
|
-
let nodeName =
|
|
76
|
+
let nodeName = this._routingKey;
|
|
75
77
|
let {orcName} = busMessage;
|
|
76
78
|
let nice = 0;
|
|
77
79
|
let noForwarding = false;
|
package/lib/events.js
CHANGED
|
@@ -74,12 +74,11 @@ Events.prototype.subscribe = function (topic, handler, backend, orcName) {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
this._handlers.set(topic, new Map([[id, handler]]));
|
|
77
|
-
this._sub.subscribe(topic, backend, orcName);
|
|
78
|
-
|
|
77
|
+
const topicCtx = this._sub.subscribe(topic, backend, orcName);
|
|
79
78
|
const handlers = this._handlers.get(topic);
|
|
80
79
|
|
|
81
80
|
/* register a pre-handler for deserialize object if needed */
|
|
82
|
-
this._busClient.registerEvents(
|
|
81
|
+
this._busClient.registerEvents(topicCtx, (msg) => {
|
|
83
82
|
/* FIXME: it's not safe. */
|
|
84
83
|
if (msg.serialized) {
|
|
85
84
|
msg.data = JSON.parse(msg.data, function (key, value) {
|
|
@@ -125,8 +124,8 @@ Events.prototype.unsubscribeAll = function (topic, backend, orcName) {
|
|
|
125
124
|
|
|
126
125
|
xLog.verb('client removing handler on topic: ' + topic);
|
|
127
126
|
|
|
128
|
-
this._sub.unsubscribe(topic, backend, orcName);
|
|
129
|
-
this._busClient.unregisterEvents(
|
|
127
|
+
const topicCtx = this._sub.unsubscribe(topic, backend, orcName);
|
|
128
|
+
this._busClient.unregisterEvents(topicCtx);
|
|
130
129
|
this._handlers.delete(topic);
|
|
131
130
|
};
|
|
132
131
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xcraft-core-busclient",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.1",
|
|
4
4
|
"description": "Xcraft bus client",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"engines": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"xcraft-core-host": "^3.0.0",
|
|
26
26
|
"xcraft-core-etc": "^3.0.0",
|
|
27
27
|
"xcraft-core-log": "^2.0.0",
|
|
28
|
-
"xcraft-core-transport": "^4.
|
|
28
|
+
"xcraft-core-transport": "^4.5.0",
|
|
29
29
|
"xcraft-core-utils": "^4.0.0"
|
|
30
30
|
},
|
|
31
31
|
"author": "Mathieu Schroeter & Samuel Loup",
|