@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.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=connection-factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-factory.d.ts","sourceRoot":"","sources":["../../src/connection-factory.ts"],"names":[],"mappings":""}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const di_1 = require("@spinajs/di");
4
+ const connection_js_1 = require("./connection.js");
5
+ const configuration_1 = require("@spinajs/configuration");
6
+ /**
7
+ * Create factory func that sets client-id to connection by app name.
8
+ * We cannot have two connection with same ID, so by default we take app-name
9
+ * with NODE_ENV and then name from options.
10
+ *
11
+ * This way we can have same config/connections for shared across multipel apps
12
+ *
13
+ */
14
+ di_1.DI.register(async (container, options) => {
15
+ const cfg = container.get(configuration_1.Configuration);
16
+ const appName = cfg.get("app.name", "no-app");
17
+ const env = cfg.get("process.env.APP_ENV", "development");
18
+ const c = new connection_js_1.StompQueueClient({
19
+ ...options,
20
+ clientId: `${appName}-${env}-${options.name}`,
21
+ });
22
+ await c.resolve();
23
+ return c;
24
+ }).as(connection_js_1.StompQueueClient);
25
+ //# sourceMappingURL=connection-factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-factory.js","sourceRoot":"","sources":["../../src/connection-factory.ts"],"names":[],"mappings":";;AAAA,oCAAiC;AAEjC,mDAAmD;AACnD,0DAAuD;AAEvD;;;;;;;GAOG;AACH,OAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,EAAE,OAAgC,EAAE,EAAE;IAEhE,MAAM,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,6BAAa,CAAC,CAAC;IACzC,MAAM,OAAO,GAAG,GAAG,CAAC,GAAG,CAAS,UAAU,EAAC,QAAQ,CAAC,CAAC;IACrD,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAS,qBAAqB,EAAE,aAAa,CAAC,CAAC;IAElE,MAAM,CAAC,GAAG,IAAI,gCAAgB,CAAC;QAC7B,GAAG,OAAO;QACV,QAAQ,EAAE,GAAG,OAAO,IAAI,GAAG,IAAI,OAAO,CAAC,IAAI,EAAE;KAC9C,CAAC,CAAC;IACH,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC;IAElB,OAAO,CAAC,CAAC;AACX,CAAC,CAAC,CAAC,EAAE,CAAC,gCAAgB,CAAC,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { IQueueMessage, IQueueConnectionOptions, QueueClient, QueueMessage } from '@spinajs/queue';
2
+ import Stomp from '@stomp/stompjs';
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
+ }
15
+ //# sourceMappingURL=connection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/connection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnG,OAAO,KAAK,MAAM,gBAAgB,CAAC;AAEnC,OAAO,EAAE,WAAW,EAAgC,MAAM,aAAa,CAAC;AAOxE,qBAEa,gBAAiB,SAAQ,WAAW;IAC/C,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC;IAE/B,SAAS,CAAC,aAAa,uCAA8C;IAErE,IAAW,QAAQ,WAElB;gBAEW,OAAO,EAAE,uBAAuB;IAI/B,OAAO;IAiEP,OAAO;IAsBP,IAAI,CAAC,OAAO,EAAE,aAAa;IAuCjC,WAAW,CAAC,gBAAgB,EAAE,MAAM,GAAG,WAAW,CAAC,YAAY,CAAC;IAa1D,SAAS,CAAC,gBAAgB,EAAE,MAAM,GAAG,WAAW,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,EAAE,cAAc,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CA4CvL"}
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.StompQueueClient = void 0;
16
+ const exceptions_1 = require("@spinajs/exceptions");
17
+ const queue_1 = require("@spinajs/queue");
18
+ const stompjs_1 = __importDefault(require("@stomp/stompjs"));
19
+ const lodash_1 = __importDefault(require("lodash"));
20
+ const di_1 = require("@spinajs/di");
21
+ const websocket_1 = __importDefault(require("websocket"));
22
+ Object.assign(global, { WebSocket: websocket_1.default.w3cwebsocket });
23
+ let StompQueueClient = class StompQueueClient extends queue_1.QueueClient {
24
+ get ClientId() {
25
+ return this.Options.clientId ?? this.Options.name;
26
+ }
27
+ constructor(options) {
28
+ super(options);
29
+ this.Subscriptions = new Map();
30
+ }
31
+ async resolve() {
32
+ this.Client = new stompjs_1.default.Client({
33
+ brokerURL: this.Options.host,
34
+ connectHeaders: {
35
+ login: this.Options.login,
36
+ passcode: this.Options.password,
37
+ 'client-id': this.ClientId,
38
+ },
39
+ reconnectDelay: 5000,
40
+ heartbeatIncoming: 4000,
41
+ heartbeatOutgoing: 4000,
42
+ // additional options
43
+ ...this.Options.options,
44
+ });
45
+ if (this.Options.debug) {
46
+ this.Client.debug = (str) => {
47
+ this.Log.trace(str);
48
+ };
49
+ }
50
+ return new Promise((resolve, reject) => {
51
+ this.Client.onStompError = (frame) => {
52
+ reject(new exceptions_1.UnexpectedServerError(`Cannot connect to queue server at ${this.Options.host}`, frame));
53
+ };
54
+ this.Client.onConnect = () => {
55
+ this.Log.success('Connected to STOMP client, client-id: ' + this.ClientId);
56
+ resolve();
57
+ // when connected override callbacks for loggin
58
+ this.Client.onStompError = (frame) => {
59
+ // Will be invoked in case of error encountered at Broker
60
+ // Bad login/passcode typically will cause an error
61
+ // Complaint brokers will set `message` header with a brief message. Body may contain details.
62
+ // Compliant brokers will terminate the connection after any error
63
+ this.Log.error('Broker reported error: ' + frame.headers['message']);
64
+ this.Log.error('Additional details: ' + frame.body);
65
+ };
66
+ this.Client.onConnect = () => {
67
+ this.Log.success('Connected to STOMP client');
68
+ };
69
+ this.Client.onDisconnect = () => {
70
+ this.Log.warn('Disconnected to STOMP client');
71
+ };
72
+ this.Client.onWebSocketError = (err) => {
73
+ this.Log.warn(err);
74
+ };
75
+ };
76
+ this.Client.onWebSocketError = (err) => {
77
+ this.Log.error(`Websocket error: ${JSON.stringify(err)}`);
78
+ reject(new exceptions_1.UnexpectedServerError(`Cannot connect to queue server at ${this.Options.host}, websocket error`, err));
79
+ };
80
+ this.Client.activate();
81
+ });
82
+ }
83
+ async dispose() {
84
+ this.Log.info(`Disposing queue connection ${this.Options.name} ...`);
85
+ return new Promise((resolve) => {
86
+ // if we dont have onDisconnect callback after 5sek, assume we have disconnected
87
+ const t = setTimeout(() => {
88
+ this.Log.warn('STOMP client deactivated, but was not connected before');
89
+ resolve();
90
+ }, 5000);
91
+ this.Client.onDisconnect = () => {
92
+ clearTimeout(t);
93
+ resolve();
94
+ this.Log.success('STOMP client deactivated');
95
+ };
96
+ this.Client.deactivate();
97
+ });
98
+ }
99
+ async emit(message) {
100
+ const channels = this.getChannelForMessage(message);
101
+ const headers = {};
102
+ if (message.Persistent) {
103
+ headers['persistent'] = 'true';
104
+ }
105
+ if (message.Priority) {
106
+ headers.priority = `${message.Priority}`;
107
+ }
108
+ if (message.ScheduleCron) {
109
+ headers['AMQ_SCHEDULED_CRON'] = message.ScheduleCron;
110
+ }
111
+ if (message.ScheduleDelay) {
112
+ headers['AMQ_SCHEDULED_DELAY'] = message.ScheduleDelay.toString();
113
+ }
114
+ if (message.SchedulePeriod) {
115
+ headers['AMQ_SCHEDULED_PERIOD'] = message.SchedulePeriod.toString();
116
+ }
117
+ if (message.ScheduleRepeat) {
118
+ headers['AMQ_SCHEDULED_REPEAT'] = message.ScheduleRepeat.toString();
119
+ }
120
+ channels.forEach((c) => {
121
+ this.Client.publish({
122
+ destination: c,
123
+ body: JSON.stringify(message),
124
+ headers,
125
+ });
126
+ this.Log.trace(`Published ${message.Type} Name: ${message.Name}} to channel ${c} ( ${this.Options.name} )`);
127
+ });
128
+ }
129
+ unsubscribe(channelOrMessage) {
130
+ const channels = lodash_1.default.isString(channelOrMessage) ? [channelOrMessage] : this.getChannelForMessage(channelOrMessage);
131
+ channels.forEach((c) => {
132
+ if (!this.Subscriptions.has(c)) {
133
+ return;
134
+ }
135
+ this.Subscriptions.get(c).unsubscribe();
136
+ this.Subscriptions.delete(c);
137
+ });
138
+ }
139
+ async subscribe(channelOrMessage, callback, subscriptionId, durable) {
140
+ const channels = lodash_1.default.isString(channelOrMessage) ? [channelOrMessage] : this.getChannelForMessage(channelOrMessage);
141
+ channels.forEach((c) => {
142
+ if (this.Subscriptions.has(c)) {
143
+ this.Log.warn(`Channel ${c} already subscribed !`);
144
+ return;
145
+ }
146
+ const headers = { ack: 'client', 'activemq.prefetchSize': '1' };
147
+ if (subscriptionId) {
148
+ headers.id = subscriptionId;
149
+ }
150
+ if (durable) {
151
+ if (!subscriptionId) {
152
+ throw new exceptions_1.InvalidArgument(`subscriptionId cannot be empty if using durable subscriptions`);
153
+ }
154
+ headers['activemq.subscriptionName'] = subscriptionId;
155
+ }
156
+ const subscription = this.Client.subscribe(c, (message) => {
157
+ const qMessage = JSON.parse(message.body);
158
+ callback(qMessage)
159
+ .then(() => {
160
+ message.ack();
161
+ })
162
+ .catch(() => {
163
+ message.nack();
164
+ });
165
+ }, headers);
166
+ this.Subscriptions.set(c, subscription);
167
+ this.Log.success(`Channel ${c}, durable: ${durable ? 'true' : 'false'} subscribed and ready to receive messages !`);
168
+ });
169
+ }
170
+ };
171
+ exports.StompQueueClient = StompQueueClient;
172
+ exports.StompQueueClient = StompQueueClient = __decorate([
173
+ (0, di_1.PerInstanceCheck)(),
174
+ (0, di_1.Injectable)(queue_1.QueueClient),
175
+ __metadata("design:paramtypes", [Object])
176
+ ], StompQueueClient);
177
+ //# sourceMappingURL=connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/connection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oDAA6E;AAC7E,0CAAmG;AACnG,6DAAmC;AACnC,oDAAuB;AACvB,oCAAwE;AACxE,0DAAkC;AAElC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,mBAAS,CAAC,YAAY,EAAE,CAAC,CAAC;AAMtD,IAAM,gBAAgB,GAAtB,MAAM,gBAA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AAC,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,4CAAgB;2BAAhB,gBAAgB;IAF5B,IAAA,qBAAgB,GAAE;IAClB,IAAA,eAAU,EAAC,mBAAW,CAAC;;GACX,gBAAgB,CAoM5B"}
@@ -1,15 +1,3 @@
1
- import { IQueueMessage, IQueueConnectionOptions, QueueClient, QueueMessage } from '@spinajs/queue';
2
- import Stomp from '@stomp/stompjs';
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
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnG,OAAO,KAAK,MAAM,gBAAgB,CAAC;AAEnC,OAAO,EAAE,WAAW,EAAgC,MAAM,aAAa,CAAC;AAKxE,qBAEa,gBAAiB,SAAQ,WAAW;IAC/C,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC;IAE/B,SAAS,CAAC,aAAa,uCAA8C;IAErE,IAAW,QAAQ,WAElB;gBAEW,OAAO,EAAE,uBAAuB;IAI/B,OAAO;IAiEP,OAAO;IAsBP,IAAI,CAAC,OAAO,EAAE,aAAa;IAuCjC,WAAW,CAAC,gBAAgB,EAAE,MAAM,GAAG,WAAW,CAAC,YAAY,CAAC;IAa1D,SAAS,CAAC,gBAAgB,EAAE,MAAM,GAAG,WAAW,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,EAAE,cAAc,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CA4CvL"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC"}
package/lib/cjs/index.js CHANGED
@@ -1,177 +1,19 @@
1
1
  "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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
- return c > 3 && r && Object.defineProperty(target, key, r), r;
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.StompQueueClient = void 0;
16
- const exceptions_1 = require("@spinajs/exceptions");
17
- const queue_1 = require("@spinajs/queue");
18
- const stompjs_1 = __importDefault(require("@stomp/stompjs"));
19
- const lodash_1 = __importDefault(require("lodash"));
20
- const di_1 = require("@spinajs/di");
21
- const websocket_1 = __importDefault(require("websocket"));
22
- Object.assign(global, { WebSocket: websocket_1.default.w3cwebsocket });
23
- let StompQueueClient = class StompQueueClient extends queue_1.QueueClient {
24
- get ClientId() {
25
- return this.Options.clientId ?? this.Options.name;
26
- }
27
- constructor(options) {
28
- super(options);
29
- this.Subscriptions = new Map();
30
- }
31
- async resolve() {
32
- this.Client = new stompjs_1.default.Client({
33
- brokerURL: this.Options.host,
34
- connectHeaders: {
35
- login: this.Options.login,
36
- passcode: this.Options.password,
37
- 'client-id': this.ClientId,
38
- },
39
- reconnectDelay: 5000,
40
- heartbeatIncoming: 4000,
41
- heartbeatOutgoing: 4000,
42
- // additional options
43
- ...this.Options.options,
44
- });
45
- if (this.Options.debug) {
46
- this.Client.debug = (str) => {
47
- this.Log.trace(str);
48
- };
49
- }
50
- return new Promise((resolve, reject) => {
51
- this.Client.onStompError = (frame) => {
52
- reject(new exceptions_1.UnexpectedServerError(`Cannot connect to queue server at ${this.Options.host}`, frame));
53
- };
54
- this.Client.onConnect = () => {
55
- this.Log.success('Connected to STOMP client, client-id: ' + this.ClientId);
56
- resolve();
57
- // when connected override callbacks for loggin
58
- this.Client.onStompError = (frame) => {
59
- // Will be invoked in case of error encountered at Broker
60
- // Bad login/passcode typically will cause an error
61
- // Complaint brokers will set `message` header with a brief message. Body may contain details.
62
- // Compliant brokers will terminate the connection after any error
63
- this.Log.error('Broker reported error: ' + frame.headers['message']);
64
- this.Log.error('Additional details: ' + frame.body);
65
- };
66
- this.Client.onConnect = () => {
67
- this.Log.success('Connected to STOMP client');
68
- };
69
- this.Client.onDisconnect = () => {
70
- this.Log.warn('Disconnected to STOMP client');
71
- };
72
- this.Client.onWebSocketError = (err) => {
73
- this.Log.warn(err);
74
- };
75
- };
76
- this.Client.onWebSocketError = (err) => {
77
- this.Log.error(`Websocket error: ${JSON.stringify(err)}`);
78
- reject(new exceptions_1.UnexpectedServerError(`Cannot connect to queue server at ${this.Options.host}, websocket error`, err));
79
- };
80
- this.Client.activate();
81
- });
82
- }
83
- async dispose() {
84
- this.Log.info(`Disposing queue connection ${this.Options.name} ...`);
85
- return new Promise((resolve) => {
86
- // if we dont have onDisconnect callback after 5sek, assume we have disconnected
87
- const t = setTimeout(() => {
88
- this.Log.warn('STOMP client deactivated, but was not connected before');
89
- resolve();
90
- }, 5000);
91
- this.Client.onDisconnect = () => {
92
- clearTimeout(t);
93
- resolve();
94
- this.Log.success('STOMP client deactivated');
95
- };
96
- this.Client.deactivate();
97
- });
98
- }
99
- async emit(message) {
100
- const channels = this.getChannelForMessage(message);
101
- const headers = {};
102
- if (message.Persistent) {
103
- headers['persistent'] = 'true';
104
- }
105
- if (message.Priority) {
106
- headers.priority = `${message.Priority}`;
107
- }
108
- if (message.ScheduleCron) {
109
- headers['AMQ_SCHEDULED_CRON'] = message.ScheduleCron;
110
- }
111
- if (message.ScheduleDelay) {
112
- headers['AMQ_SCHEDULED_DELAY'] = message.ScheduleDelay.toString();
113
- }
114
- if (message.SchedulePeriod) {
115
- headers['AMQ_SCHEDULED_PERIOD'] = message.SchedulePeriod.toString();
116
- }
117
- if (message.ScheduleRepeat) {
118
- headers['AMQ_SCHEDULED_REPEAT'] = message.ScheduleRepeat.toString();
119
- }
120
- channels.forEach((c) => {
121
- this.Client.publish({
122
- destination: c,
123
- body: JSON.stringify(message),
124
- headers,
125
- });
126
- this.Log.trace(`Published ${message.Type} Name: ${message.Name}} to channel ${c} ( ${this.Options.name} )`);
127
- });
128
- }
129
- unsubscribe(channelOrMessage) {
130
- const channels = lodash_1.default.isString(channelOrMessage) ? [channelOrMessage] : this.getChannelForMessage(channelOrMessage);
131
- channels.forEach((c) => {
132
- if (!this.Subscriptions.has(c)) {
133
- return;
134
- }
135
- this.Subscriptions.get(c).unsubscribe();
136
- this.Subscriptions.delete(c);
137
- });
138
- }
139
- async subscribe(channelOrMessage, callback, subscriptionId, durable) {
140
- const channels = lodash_1.default.isString(channelOrMessage) ? [channelOrMessage] : this.getChannelForMessage(channelOrMessage);
141
- channels.forEach((c) => {
142
- if (this.Subscriptions.has(c)) {
143
- this.Log.warn(`Channel ${c} already subscribed !`);
144
- return;
145
- }
146
- const headers = { ack: 'client', 'activemq.prefetchSize': '1' };
147
- if (subscriptionId) {
148
- headers.id = subscriptionId;
149
- }
150
- if (durable) {
151
- if (!subscriptionId) {
152
- throw new exceptions_1.InvalidArgument(`subscriptionId cannot be empty if using durable subscriptions`);
153
- }
154
- headers['activemq.subscriptionName'] = subscriptionId;
155
- }
156
- const subscription = this.Client.subscribe(c, (message) => {
157
- const qMessage = JSON.parse(message.body);
158
- callback(qMessage)
159
- .then(() => {
160
- message.ack();
161
- })
162
- .catch(() => {
163
- message.nack();
164
- });
165
- }, headers);
166
- this.Subscriptions.set(c, subscription);
167
- this.Log.success(`Channel ${c}, durable: ${durable ? 'true' : 'false'} subscribed and ready to receive messages !`);
168
- });
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
169
7
  }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
170
15
  };
171
- exports.StompQueueClient = StompQueueClient;
172
- exports.StompQueueClient = StompQueueClient = __decorate([
173
- (0, di_1.PerInstanceCheck)(),
174
- (0, di_1.Injectable)(queue_1.QueueClient),
175
- __metadata("design:paramtypes", [Object])
176
- ], StompQueueClient);
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./connection-factory.js"), exports);
18
+ __exportStar(require("./connection.js"), exports);
177
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oDAA6E;AAC7E,0CAAmG;AACnG,6DAAmC;AACnC,oDAAuB;AACvB,oCAAwE;AACxE,0DAAkC;AAElC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,mBAAS,CAAC,YAAY,EAAE,CAAC,CAAC;AAItD,IAAM,gBAAgB,GAAtB,MAAM,gBAAiB,SAAQ,mBAAW;IAK/C,IAAW,QAAQ;QACjB,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IACpD,CAAC;IAED,YAAY,OAAgC;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAC;QAPP,kBAAa,GAAG,IAAI,GAAG,EAAmC,CAAC;IAQrE,CAAC;IAEM,KAAK,CAAC,OAAO;QAClB,IAAI,CAAC,MAAM,GAAG,IAAI,iBAAK,CAAC,MAAM,CAAC;YAC7B,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;YAC5B,cAAc,EAAE;gBACd,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK;gBACzB,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ;gBAC/B,WAAW,EAAE,IAAI,CAAC,QAAQ;aAC3B;YACD,cAAc,EAAE,IAAI;YACpB,iBAAiB,EAAE,IAAI;YACvB,iBAAiB,EAAE,IAAI;YAEvB,qBAAqB;YACrB,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO;SACxB,CAAC,CAAC;QAEH,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE;YACtB,IAAI,CAAC,M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,CAAC,GAAG,cAAc,CAAC;aACvD;YAED,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CACxC,CAAC,EACD,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,4CAAgB;2BAAhB,gBAAgB;IAF5B,IAAA,qBAAgB,GAAE;IAClB,IAAA,eAAU,EAAC,mBAAW,CAAC;;GACX,gBAAgB,CAoM5B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAwC;AACxC,kDAAgC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=connection-factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-factory.d.ts","sourceRoot":"","sources":["../../src/connection-factory.ts"],"names":[],"mappings":""}
@@ -0,0 +1,23 @@
1
+ import { DI } from '@spinajs/di';
2
+ import { StompQueueClient } from './connection.js';
3
+ import { Configuration } from '@spinajs/configuration';
4
+ /**
5
+ * Create factory func that sets client-id to connection by app name.
6
+ * We cannot have two connection with same ID, so by default we take app-name
7
+ * with NODE_ENV and then name from options.
8
+ *
9
+ * This way we can have same config/connections for shared across multipel apps
10
+ *
11
+ */
12
+ DI.register(async (container, options) => {
13
+ const cfg = container.get(Configuration);
14
+ const appName = cfg.get("app.name", "no-app");
15
+ const env = cfg.get("process.env.APP_ENV", "development");
16
+ const c = new StompQueueClient({
17
+ ...options,
18
+ clientId: `${appName}-${env}-${options.name}`,
19
+ });
20
+ await c.resolve();
21
+ return c;
22
+ }).as(StompQueueClient);
23
+ //# sourceMappingURL=connection-factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection-factory.js","sourceRoot":"","sources":["../../src/connection-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAEjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD;;;;;;;GAOG;AACH,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,EAAE,OAAgC,EAAE,EAAE;IAEhE,MAAM,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IACzC,MAAM,OAAO,GAAG,GAAG,CAAC,GAAG,CAAS,UAAU,EAAC,QAAQ,CAAC,CAAC;IACrD,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAS,qBAAqB,EAAE,aAAa,CAAC,CAAC;IAElE,MAAM,CAAC,GAAG,IAAI,gBAAgB,CAAC;QAC7B,GAAG,OAAO;QACV,QAAQ,EAAE,GAAG,OAAO,IAAI,GAAG,IAAI,OAAO,CAAC,IAAI,EAAE;KAC9C,CAAC,CAAC;IACH,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC;IAElB,OAAO,CAAC,CAAC;AACX,CAAC,CAAC,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { IQueueMessage, IQueueConnectionOptions, QueueClient, QueueMessage } from '@spinajs/queue';
2
+ import Stomp from '@stomp/stompjs';
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
+ }
15
+ //# sourceMappingURL=connection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/connection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnG,OAAO,KAAK,MAAM,gBAAgB,CAAC;AAEnC,OAAO,EAAE,WAAW,EAAgC,MAAM,aAAa,CAAC;AAOxE,qBAEa,gBAAiB,SAAQ,WAAW;IAC/C,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC;IAE/B,SAAS,CAAC,aAAa,uCAA8C;IAErE,IAAW,QAAQ,WAElB;gBAEW,OAAO,EAAE,uBAAuB;IAI/B,OAAO;IAiEP,OAAO;IAsBP,IAAI,CAAC,OAAO,EAAE,aAAa;IAuCjC,WAAW,CAAC,gBAAgB,EAAE,MAAM,GAAG,WAAW,CAAC,YAAY,CAAC;IAa1D,SAAS,CAAC,gBAAgB,EAAE,MAAM,GAAG,WAAW,CAAC,YAAY,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,EAAE,cAAc,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CA4CvL"}