@spinajs/queue-stomp-transport 2.0.259 → 2.0.261
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/lib/cjs/connection-factory.d.ts +2 -0
- package/lib/cjs/connection-factory.d.ts.map +1 -0
- package/lib/cjs/connection-factory.js +25 -0
- package/lib/cjs/connection-factory.js.map +1 -0
- package/lib/cjs/connection.d.ts +15 -0
- package/lib/cjs/connection.d.ts.map +1 -0
- package/lib/cjs/connection.js +177 -0
- package/lib/cjs/connection.js.map +1 -0
- package/lib/cjs/index.d.ts +2 -14
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +15 -173
- package/lib/cjs/index.js.map +1 -1
- package/lib/mjs/connection-factory.d.ts +2 -0
- package/lib/mjs/connection-factory.d.ts.map +1 -0
- package/lib/mjs/connection-factory.js +23 -0
- package/lib/mjs/connection-factory.js.map +1 -0
- package/lib/mjs/connection.d.ts +15 -0
- package/lib/mjs/connection.d.ts.map +1 -0
- package/lib/mjs/connection.js +171 -0
- package/lib/mjs/connection.js.map +1 -0
- package/lib/mjs/index.d.ts +2 -14
- package/lib/mjs/index.d.ts.map +1 -1
- package/lib/mjs/index.js +2 -170
- package/lib/mjs/index.js.map +1 -1
- package/lib/tsconfig.cjs.tsbuildinfo +1 -1
- package/lib/tsconfig.mjs.tsbuildinfo +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
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;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { UnexpectedServerError, InvalidArgument } from '@spinajs/exceptions';
|
|
11
|
+
import { QueueClient } from '@spinajs/queue';
|
|
12
|
+
import Stomp from '@stomp/stompjs';
|
|
13
|
+
import _ from 'lodash';
|
|
14
|
+
import { Injectable, PerInstanceCheck } from '@spinajs/di';
|
|
15
|
+
import websocket from 'websocket';
|
|
16
|
+
Object.assign(global, { WebSocket: websocket.w3cwebsocket });
|
|
17
|
+
let StompQueueClient = class StompQueueClient extends QueueClient {
|
|
18
|
+
get ClientId() {
|
|
19
|
+
return this.Options.clientId ?? this.Options.name;
|
|
20
|
+
}
|
|
21
|
+
constructor(options) {
|
|
22
|
+
super(options);
|
|
23
|
+
this.Subscriptions = new Map();
|
|
24
|
+
}
|
|
25
|
+
async resolve() {
|
|
26
|
+
this.Client = new Stomp.Client({
|
|
27
|
+
brokerURL: this.Options.host,
|
|
28
|
+
connectHeaders: {
|
|
29
|
+
login: this.Options.login,
|
|
30
|
+
passcode: this.Options.password,
|
|
31
|
+
'client-id': this.ClientId,
|
|
32
|
+
},
|
|
33
|
+
reconnectDelay: 5000,
|
|
34
|
+
heartbeatIncoming: 4000,
|
|
35
|
+
heartbeatOutgoing: 4000,
|
|
36
|
+
// additional options
|
|
37
|
+
...this.Options.options,
|
|
38
|
+
});
|
|
39
|
+
if (this.Options.debug) {
|
|
40
|
+
this.Client.debug = (str) => {
|
|
41
|
+
this.Log.trace(str);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
this.Client.onStompError = (frame) => {
|
|
46
|
+
reject(new UnexpectedServerError(`Cannot connect to queue server at ${this.Options.host}`, frame));
|
|
47
|
+
};
|
|
48
|
+
this.Client.onConnect = () => {
|
|
49
|
+
this.Log.success('Connected to STOMP client, client-id: ' + this.ClientId);
|
|
50
|
+
resolve();
|
|
51
|
+
// when connected override callbacks for loggin
|
|
52
|
+
this.Client.onStompError = (frame) => {
|
|
53
|
+
// Will be invoked in case of error encountered at Broker
|
|
54
|
+
// Bad login/passcode typically will cause an error
|
|
55
|
+
// Complaint brokers will set `message` header with a brief message. Body may contain details.
|
|
56
|
+
// Compliant brokers will terminate the connection after any error
|
|
57
|
+
this.Log.error('Broker reported error: ' + frame.headers['message']);
|
|
58
|
+
this.Log.error('Additional details: ' + frame.body);
|
|
59
|
+
};
|
|
60
|
+
this.Client.onConnect = () => {
|
|
61
|
+
this.Log.success('Connected to STOMP client');
|
|
62
|
+
};
|
|
63
|
+
this.Client.onDisconnect = () => {
|
|
64
|
+
this.Log.warn('Disconnected to STOMP client');
|
|
65
|
+
};
|
|
66
|
+
this.Client.onWebSocketError = (err) => {
|
|
67
|
+
this.Log.warn(err);
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
this.Client.onWebSocketError = (err) => {
|
|
71
|
+
this.Log.error(`Websocket error: ${JSON.stringify(err)}`);
|
|
72
|
+
reject(new UnexpectedServerError(`Cannot connect to queue server at ${this.Options.host}, websocket error`, err));
|
|
73
|
+
};
|
|
74
|
+
this.Client.activate();
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
async dispose() {
|
|
78
|
+
this.Log.info(`Disposing queue connection ${this.Options.name} ...`);
|
|
79
|
+
return new Promise((resolve) => {
|
|
80
|
+
// if we dont have onDisconnect callback after 5sek, assume we have disconnected
|
|
81
|
+
const t = setTimeout(() => {
|
|
82
|
+
this.Log.warn('STOMP client deactivated, but was not connected before');
|
|
83
|
+
resolve();
|
|
84
|
+
}, 5000);
|
|
85
|
+
this.Client.onDisconnect = () => {
|
|
86
|
+
clearTimeout(t);
|
|
87
|
+
resolve();
|
|
88
|
+
this.Log.success('STOMP client deactivated');
|
|
89
|
+
};
|
|
90
|
+
this.Client.deactivate();
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
async emit(message) {
|
|
94
|
+
const channels = this.getChannelForMessage(message);
|
|
95
|
+
const headers = {};
|
|
96
|
+
if (message.Persistent) {
|
|
97
|
+
headers['persistent'] = 'true';
|
|
98
|
+
}
|
|
99
|
+
if (message.Priority) {
|
|
100
|
+
headers.priority = `${message.Priority}`;
|
|
101
|
+
}
|
|
102
|
+
if (message.ScheduleCron) {
|
|
103
|
+
headers['AMQ_SCHEDULED_CRON'] = message.ScheduleCron;
|
|
104
|
+
}
|
|
105
|
+
if (message.ScheduleDelay) {
|
|
106
|
+
headers['AMQ_SCHEDULED_DELAY'] = message.ScheduleDelay.toString();
|
|
107
|
+
}
|
|
108
|
+
if (message.SchedulePeriod) {
|
|
109
|
+
headers['AMQ_SCHEDULED_PERIOD'] = message.SchedulePeriod.toString();
|
|
110
|
+
}
|
|
111
|
+
if (message.ScheduleRepeat) {
|
|
112
|
+
headers['AMQ_SCHEDULED_REPEAT'] = message.ScheduleRepeat.toString();
|
|
113
|
+
}
|
|
114
|
+
channels.forEach((c) => {
|
|
115
|
+
this.Client.publish({
|
|
116
|
+
destination: c,
|
|
117
|
+
body: JSON.stringify(message),
|
|
118
|
+
headers,
|
|
119
|
+
});
|
|
120
|
+
this.Log.trace(`Published ${message.Type} Name: ${message.Name}} to channel ${c} ( ${this.Options.name} )`);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
unsubscribe(channelOrMessage) {
|
|
124
|
+
const channels = _.isString(channelOrMessage) ? [channelOrMessage] : this.getChannelForMessage(channelOrMessage);
|
|
125
|
+
channels.forEach((c) => {
|
|
126
|
+
if (!this.Subscriptions.has(c)) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
this.Subscriptions.get(c).unsubscribe();
|
|
130
|
+
this.Subscriptions.delete(c);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
async subscribe(channelOrMessage, callback, subscriptionId, durable) {
|
|
134
|
+
const channels = _.isString(channelOrMessage) ? [channelOrMessage] : this.getChannelForMessage(channelOrMessage);
|
|
135
|
+
channels.forEach((c) => {
|
|
136
|
+
if (this.Subscriptions.has(c)) {
|
|
137
|
+
this.Log.warn(`Channel ${c} already subscribed !`);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const headers = { ack: 'client', 'activemq.prefetchSize': '1' };
|
|
141
|
+
if (subscriptionId) {
|
|
142
|
+
headers.id = subscriptionId;
|
|
143
|
+
}
|
|
144
|
+
if (durable) {
|
|
145
|
+
if (!subscriptionId) {
|
|
146
|
+
throw new InvalidArgument(`subscriptionId cannot be empty if using durable subscriptions`);
|
|
147
|
+
}
|
|
148
|
+
headers['activemq.subscriptionName'] = subscriptionId;
|
|
149
|
+
}
|
|
150
|
+
const subscription = this.Client.subscribe(c, (message) => {
|
|
151
|
+
const qMessage = JSON.parse(message.body);
|
|
152
|
+
callback(qMessage)
|
|
153
|
+
.then(() => {
|
|
154
|
+
message.ack();
|
|
155
|
+
})
|
|
156
|
+
.catch(() => {
|
|
157
|
+
message.nack();
|
|
158
|
+
});
|
|
159
|
+
}, headers);
|
|
160
|
+
this.Subscriptions.set(c, subscription);
|
|
161
|
+
this.Log.success(`Channel ${c}, durable: ${durable ? 'true' : 'false'} subscribed and ready to receive messages !`);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
StompQueueClient = __decorate([
|
|
166
|
+
PerInstanceCheck(),
|
|
167
|
+
Injectable(QueueClient),
|
|
168
|
+
__metadata("design:paramtypes", [Object])
|
|
169
|
+
], StompQueueClient);
|
|
170
|
+
export { StompQueueClient };
|
|
171
|
+
//# sourceMappingURL=connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/connection.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,qBAAqB,C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,CAAC,OAAO,EAAE,EAAE;gBACV,MAAM,QAAQ,GAAkB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;gBAEzD,QAAQ,CAAC,QAAQ,CAAC;qBACf,IAAI,CAAC,GAAG,EAAE;oBACT,OAAO,CAAC,GAAG,EAAE,CAAC;gBAChB,CAAC,CAAC;qBACD,KAAK,CAAC,GAAG,EAAE;oBACV,OAAO,CAAC,IAAI,EAAE,CAAC;gBACjB,CAAC,CAAC,CAAC;YACP,CAAC,EACD,OAAO,CACR,CAAC;YAEF,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;YAExC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,cAAc,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,6CAA6C,CAAC,CAAC;QACtH,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AApMY,gBAAgB;IAF5B,gBAAgB,EAAE;IAClB,UAAU,CAAC,WAAW,CAAC;;GACX,gBAAgB,CAoM5B"}
|
package/lib/mjs/index.d.ts
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { Constructor } from '@spinajs/di';
|
|
4
|
-
export declare class StompQueueClient extends QueueClient {
|
|
5
|
-
protected Client: Stomp.Client;
|
|
6
|
-
protected Subscriptions: Map<string, Stomp.StompSubscription>;
|
|
7
|
-
get ClientId(): string;
|
|
8
|
-
constructor(options: IQueueConnectionOptions);
|
|
9
|
-
resolve(): Promise<void>;
|
|
10
|
-
dispose(): Promise<void>;
|
|
11
|
-
emit(message: IQueueMessage): Promise<void>;
|
|
12
|
-
unsubscribe(channelOrMessage: string | Constructor<QueueMessage>): void;
|
|
13
|
-
subscribe(channelOrMessage: string | Constructor<QueueMessage>, callback: (e: IQueueMessage) => Promise<void>, subscriptionId?: string, durable?: boolean): Promise<void>;
|
|
14
|
-
}
|
|
1
|
+
export * from "./connection-factory.js";
|
|
2
|
+
export * from "./connection.js";
|
|
15
3
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/mjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC"}
|
package/lib/mjs/index.js
CHANGED
|
@@ -1,171 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
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;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { UnexpectedServerError, InvalidArgument } from '@spinajs/exceptions';
|
|
11
|
-
import { QueueClient } from '@spinajs/queue';
|
|
12
|
-
import Stomp from '@stomp/stompjs';
|
|
13
|
-
import _ from 'lodash';
|
|
14
|
-
import { Injectable, PerInstanceCheck } from '@spinajs/di';
|
|
15
|
-
import websocket from 'websocket';
|
|
16
|
-
Object.assign(global, { WebSocket: websocket.w3cwebsocket });
|
|
17
|
-
let StompQueueClient = class StompQueueClient extends QueueClient {
|
|
18
|
-
get ClientId() {
|
|
19
|
-
return this.Options.clientId ?? this.Options.name;
|
|
20
|
-
}
|
|
21
|
-
constructor(options) {
|
|
22
|
-
super(options);
|
|
23
|
-
this.Subscriptions = new Map();
|
|
24
|
-
}
|
|
25
|
-
async resolve() {
|
|
26
|
-
this.Client = new Stomp.Client({
|
|
27
|
-
brokerURL: this.Options.host,
|
|
28
|
-
connectHeaders: {
|
|
29
|
-
login: this.Options.login,
|
|
30
|
-
passcode: this.Options.password,
|
|
31
|
-
'client-id': this.ClientId,
|
|
32
|
-
},
|
|
33
|
-
reconnectDelay: 5000,
|
|
34
|
-
heartbeatIncoming: 4000,
|
|
35
|
-
heartbeatOutgoing: 4000,
|
|
36
|
-
// additional options
|
|
37
|
-
...this.Options.options,
|
|
38
|
-
});
|
|
39
|
-
if (this.Options.debug) {
|
|
40
|
-
this.Client.debug = (str) => {
|
|
41
|
-
this.Log.trace(str);
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
return new Promise((resolve, reject) => {
|
|
45
|
-
this.Client.onStompError = (frame) => {
|
|
46
|
-
reject(new UnexpectedServerError(`Cannot connect to queue server at ${this.Options.host}`, frame));
|
|
47
|
-
};
|
|
48
|
-
this.Client.onConnect = () => {
|
|
49
|
-
this.Log.success('Connected to STOMP client, client-id: ' + this.ClientId);
|
|
50
|
-
resolve();
|
|
51
|
-
// when connected override callbacks for loggin
|
|
52
|
-
this.Client.onStompError = (frame) => {
|
|
53
|
-
// Will be invoked in case of error encountered at Broker
|
|
54
|
-
// Bad login/passcode typically will cause an error
|
|
55
|
-
// Complaint brokers will set `message` header with a brief message. Body may contain details.
|
|
56
|
-
// Compliant brokers will terminate the connection after any error
|
|
57
|
-
this.Log.error('Broker reported error: ' + frame.headers['message']);
|
|
58
|
-
this.Log.error('Additional details: ' + frame.body);
|
|
59
|
-
};
|
|
60
|
-
this.Client.onConnect = () => {
|
|
61
|
-
this.Log.success('Connected to STOMP client');
|
|
62
|
-
};
|
|
63
|
-
this.Client.onDisconnect = () => {
|
|
64
|
-
this.Log.warn('Disconnected to STOMP client');
|
|
65
|
-
};
|
|
66
|
-
this.Client.onWebSocketError = (err) => {
|
|
67
|
-
this.Log.warn(err);
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
this.Client.onWebSocketError = (err) => {
|
|
71
|
-
this.Log.error(`Websocket error: ${JSON.stringify(err)}`);
|
|
72
|
-
reject(new UnexpectedServerError(`Cannot connect to queue server at ${this.Options.host}, websocket error`, err));
|
|
73
|
-
};
|
|
74
|
-
this.Client.activate();
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
async dispose() {
|
|
78
|
-
this.Log.info(`Disposing queue connection ${this.Options.name} ...`);
|
|
79
|
-
return new Promise((resolve) => {
|
|
80
|
-
// if we dont have onDisconnect callback after 5sek, assume we have disconnected
|
|
81
|
-
const t = setTimeout(() => {
|
|
82
|
-
this.Log.warn('STOMP client deactivated, but was not connected before');
|
|
83
|
-
resolve();
|
|
84
|
-
}, 5000);
|
|
85
|
-
this.Client.onDisconnect = () => {
|
|
86
|
-
clearTimeout(t);
|
|
87
|
-
resolve();
|
|
88
|
-
this.Log.success('STOMP client deactivated');
|
|
89
|
-
};
|
|
90
|
-
this.Client.deactivate();
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
async emit(message) {
|
|
94
|
-
const channels = this.getChannelForMessage(message);
|
|
95
|
-
const headers = {};
|
|
96
|
-
if (message.Persistent) {
|
|
97
|
-
headers['persistent'] = 'true';
|
|
98
|
-
}
|
|
99
|
-
if (message.Priority) {
|
|
100
|
-
headers.priority = `${message.Priority}`;
|
|
101
|
-
}
|
|
102
|
-
if (message.ScheduleCron) {
|
|
103
|
-
headers['AMQ_SCHEDULED_CRON'] = message.ScheduleCron;
|
|
104
|
-
}
|
|
105
|
-
if (message.ScheduleDelay) {
|
|
106
|
-
headers['AMQ_SCHEDULED_DELAY'] = message.ScheduleDelay.toString();
|
|
107
|
-
}
|
|
108
|
-
if (message.SchedulePeriod) {
|
|
109
|
-
headers['AMQ_SCHEDULED_PERIOD'] = message.SchedulePeriod.toString();
|
|
110
|
-
}
|
|
111
|
-
if (message.ScheduleRepeat) {
|
|
112
|
-
headers['AMQ_SCHEDULED_REPEAT'] = message.ScheduleRepeat.toString();
|
|
113
|
-
}
|
|
114
|
-
channels.forEach((c) => {
|
|
115
|
-
this.Client.publish({
|
|
116
|
-
destination: c,
|
|
117
|
-
body: JSON.stringify(message),
|
|
118
|
-
headers,
|
|
119
|
-
});
|
|
120
|
-
this.Log.trace(`Published ${message.Type} Name: ${message.Name}} to channel ${c} ( ${this.Options.name} )`);
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
unsubscribe(channelOrMessage) {
|
|
124
|
-
const channels = _.isString(channelOrMessage) ? [channelOrMessage] : this.getChannelForMessage(channelOrMessage);
|
|
125
|
-
channels.forEach((c) => {
|
|
126
|
-
if (!this.Subscriptions.has(c)) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
this.Subscriptions.get(c).unsubscribe();
|
|
130
|
-
this.Subscriptions.delete(c);
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
async subscribe(channelOrMessage, callback, subscriptionId, durable) {
|
|
134
|
-
const channels = _.isString(channelOrMessage) ? [channelOrMessage] : this.getChannelForMessage(channelOrMessage);
|
|
135
|
-
channels.forEach((c) => {
|
|
136
|
-
if (this.Subscriptions.has(c)) {
|
|
137
|
-
this.Log.warn(`Channel ${c} already subscribed !`);
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
const headers = { ack: 'client', 'activemq.prefetchSize': '1' };
|
|
141
|
-
if (subscriptionId) {
|
|
142
|
-
headers.id = subscriptionId;
|
|
143
|
-
}
|
|
144
|
-
if (durable) {
|
|
145
|
-
if (!subscriptionId) {
|
|
146
|
-
throw new InvalidArgument(`subscriptionId cannot be empty if using durable subscriptions`);
|
|
147
|
-
}
|
|
148
|
-
headers['activemq.subscriptionName'] = subscriptionId;
|
|
149
|
-
}
|
|
150
|
-
const subscription = this.Client.subscribe(c, (message) => {
|
|
151
|
-
const qMessage = JSON.parse(message.body);
|
|
152
|
-
callback(qMessage)
|
|
153
|
-
.then(() => {
|
|
154
|
-
message.ack();
|
|
155
|
-
})
|
|
156
|
-
.catch(() => {
|
|
157
|
-
message.nack();
|
|
158
|
-
});
|
|
159
|
-
}, headers);
|
|
160
|
-
this.Subscriptions.set(c, subscription);
|
|
161
|
-
this.Log.success(`Channel ${c}, durable: ${durable ? 'true' : 'false'} subscribed and ready to receive messages !`);
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
StompQueueClient = __decorate([
|
|
166
|
-
PerInstanceCheck(),
|
|
167
|
-
Injectable(QueueClient),
|
|
168
|
-
__metadata("design:paramtypes", [Object])
|
|
169
|
-
], StompQueueClient);
|
|
170
|
-
export { StompQueueClient };
|
|
1
|
+
export * from "./connection-factory.js";
|
|
2
|
+
export * from "./connection.js";
|
|
171
3
|
//# sourceMappingURL=index.js.map
|
package/lib/mjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC"}
|