Skip to content

Commit

Permalink
fix: stomp nest wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
eddort committed Mar 29, 2023
1 parent 16f5001 commit 3907ac5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/transport/stomp/stomp.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,11 @@ export default class StompClient {
public async connect(headers = {}, timeout = 10000) {
await this._connect(timeout);

const { maxWaitSocketSession } = this.options;

headers['host'] = '/';
headers['accept-version'] = VERSIONS;
headers['heart-beat'] = '100000,100000';
headers['heart-beat'] = `${maxWaitSocketSession},${maxWaitSocketSession}`;

if (this.login != null) {
headers['login'] = this.login;
Expand Down
3 changes: 2 additions & 1 deletion src/transport/stomp/stomp.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type GetWebSocket = (url: string) => WebSocket | WebSocketMock;
export type StompOptions = {
reconnectTimeout: number;
reconnectAttempts: number;
maxWaitSocketSession: number;
};

export interface StompDependencies {
Expand All @@ -18,7 +19,7 @@ export interface StompDependencies {
passcode: string | null;
connectCallback: ConnectCallback;
errorCallback: ErrorCallback;
getWebSocket: GetWebSocket;
getWebSocket?: GetWebSocket;
logger?: LoggerService;
options: StompOptions;
}
18 changes: 14 additions & 4 deletions src/transport/stomp/stomp.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import StompClient from './stomp.client';
import { StompOptions } from './stomp.interface';
import { WebSocketMock } from './stomp.mock';

const wait = (ms = 100) => new Promise((resolve) => setTimeout(resolve, ms));

const DEFAULT_STOMP_OPTIONS: StompOptions = {
reconnectAttempts: 1,
reconnectTimeout: 10,
maxWaitSocketSession: 10_000,
};

describe('StompClient', () => {
describe('regular cases', () => {
let server: WebSocketMock;
Expand All @@ -23,10 +30,7 @@ describe('StompClient', () => {
server = new WebSocketMock();
return server;
},
options: {
reconnectAttempts: 1,
reconnectTimeout: 10,
},
options: DEFAULT_STOMP_OPTIONS,
});

await stompClient.connect();
Expand Down Expand Up @@ -109,6 +113,7 @@ describe('StompClient', () => {
return server;
},
options: {
maxWaitSocketSession: 10_000,
reconnectAttempts,
reconnectTimeout: 10,
},
Expand Down Expand Up @@ -153,6 +158,7 @@ describe('StompClient', () => {
return server;
},
options: {
maxWaitSocketSession: 10_000,
reconnectAttempts,
reconnectTimeout: 10,
},
Expand Down Expand Up @@ -197,6 +203,7 @@ describe('StompClient', () => {
return server;
},
options: {
maxWaitSocketSession: 10_000,
reconnectAttempts,
reconnectTimeout: 10,
},
Expand Down Expand Up @@ -245,6 +252,7 @@ describe('StompClient', () => {
return server;
},
options: {
maxWaitSocketSession: 10_000,
get reconnectAttempts() {
realAttempts += 1;
return reconnectAttempts;
Expand Down Expand Up @@ -291,6 +299,7 @@ describe('StompClient', () => {
return server;
},
options: {
maxWaitSocketSession: 10_000,
get reconnectAttempts() {
realAttempts += 1;
return reconnectAttempts;
Expand Down Expand Up @@ -337,6 +346,7 @@ describe('StompClient', () => {
return server;
},
options: {
maxWaitSocketSession: 10_000,
get reconnectAttempts() {
realAttempts += 1;
return reconnectAttempts;
Expand Down
7 changes: 7 additions & 0 deletions src/transport/transport.constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
import { StompOptions } from './stomp/stomp.interface';

export const KAFKA_LOG_PREFIX = 'Kafka';
export const RABBIT_LOG_PREFIX = 'RabbitMQ';
export const STOMP_OPTIONS: StompOptions = {
reconnectAttempts: 2,
reconnectTimeout: 5_000,
maxWaitSocketSession: 100_000,
};

0 comments on commit 3907ac5

Please sign in to comment.