Skip to content

Commit 5633df4

Browse files
fix(microservices): add missing get pattern to rmq and tcp
1 parent 371bec6 commit 5633df4

6 files changed

Lines changed: 31 additions & 7 deletions

File tree

packages/microservices/ctx-host/rmq.context.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BaseRpcContext } from './base-rpc.context';
22

3-
type RmqContextArgs = [Record<string, any>, any];
3+
type RmqContextArgs = [Record<string, any>, any, string];
44

55
export class RmqContext extends BaseRpcContext<RmqContextArgs> {
66
constructor(args: RmqContextArgs) {
@@ -20,4 +20,11 @@ export class RmqContext extends BaseRpcContext<RmqContextArgs> {
2020
getChannelRef() {
2121
return this.args[1];
2222
}
23+
24+
/**
25+
* Returns the name of the pattern.
26+
*/
27+
getPattern() {
28+
return this.args[2];
29+
}
2330
}

packages/microservices/ctx-host/tcp.context.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { JsonSocket } from '../helpers';
22
import { BaseRpcContext } from './base-rpc.context';
33

4-
type TcpContextArgs = [JsonSocket];
4+
type TcpContextArgs = [JsonSocket, string];
55

66
export class TcpContext extends BaseRpcContext<TcpContextArgs> {
77
constructor(args: TcpContextArgs) {
@@ -14,4 +14,11 @@ export class TcpContext extends BaseRpcContext<TcpContextArgs> {
1414
getSocketRef() {
1515
return this.args[0];
1616
}
17+
18+
/**
19+
* Returns the name of the pattern.
20+
*/
21+
getPattern() {
22+
return this.args[1];
23+
}
1724
}

packages/microservices/server/server-rmq.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export class ServerRMQ extends Server implements CustomTransportStrategy {
110110
? packet.pattern
111111
: JSON.stringify(packet.pattern);
112112

113-
const rmqContext = new RmqContext([message, channel]);
113+
const rmqContext = new RmqContext([message, channel, pattern]);
114114
if (isUndefined((packet as IncomingRequest).id)) {
115115
return this.handleEvent(pattern, packet, rmqContext);
116116
}

packages/microservices/server/server-tcp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class ServerTCP extends Server implements CustomTransportStrategy {
6363
? JSON.stringify(packet.pattern)
6464
: packet.pattern;
6565

66-
const tcpContext = new TcpContext([socket]);
66+
const tcpContext = new TcpContext([socket, pattern]);
6767
if (isUndefined((packet as IncomingRequest).id)) {
6868
return this.handleEvent(pattern, packet, tcpContext);
6969
}

packages/microservices/test/ctx-host/rmq.context.spec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { expect } from 'chai';
22
import { RmqContext } from '../../ctx-host';
33

44
describe('RmqContext', () => {
5-
const args = [{ test: true }, 'test'];
5+
const args = [{ test: true }, 'test', 'pattern'];
66
let context: RmqContext;
77

88
beforeEach(() => {
9-
context = new RmqContext(args as [Record<string, any>, any]);
9+
context = new RmqContext(args as [Record<string, any>, any, string]);
1010
});
1111
describe('getMessage', () => {
1212
it('should return original message', () => {
@@ -18,4 +18,9 @@ describe('RmqContext', () => {
1818
expect(context.getChannelRef()).to.be.eql(args[1]);
1919
});
2020
});
21+
describe('getPattern', () => {
22+
it('should return pattern', () => {
23+
expect(context.getPattern()).to.be.eql(args[2]);
24+
});
25+
});
2126
});

packages/microservices/test/ctx-host/tcp.context.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect } from 'chai';
22
import { TcpContext } from '../../ctx-host';
33

44
describe('TcpContext', () => {
5-
const args = [{}];
5+
const args = [{}, 'pattern'];
66
let context: TcpContext;
77

88
beforeEach(() => {
@@ -13,4 +13,9 @@ describe('TcpContext', () => {
1313
expect(context.getSocketRef()).to.be.eql(args[0]);
1414
});
1515
});
16+
describe('getPattern', () => {
17+
it('should return pattern', () => {
18+
expect(context.getPattern()).to.be.eql(args[1]);
19+
});
20+
});
1621
});

0 commit comments

Comments
 (0)