Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit f5add5b

Browse files
authored
refactor(Brokers): change confusing client/server naming to publisher/subscriber (#87)
* refactor(Brokers): change confusing client/server naming to publisher/subscriber * chore: update gw service to use the proper class
1 parent 1d16779 commit f5add5b

File tree

11 files changed

+52
-52
lines changed

11 files changed

+52
-52
lines changed

libs/brokers/src/brokers/pubsub/PubSubServer.ts renamed to libs/brokers/src/brokers/pubsub/PubSubPublisher.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { Broker } from '../Broker';
33
import type * as amqp from 'amqplib';
44

55
/**
6-
* Options for initializing the pub/sub server
6+
* Options for initializing the pub/sub publisher
77
*/
8-
export interface PubSubServerInitOptions {
8+
export interface PubSubPublisherInitOptions {
99
/**
1010
* Name of the queue/exchange to use
1111
*/
@@ -17,9 +17,9 @@ export interface PubSubServerInitOptions {
1717
}
1818

1919
/**
20-
* Server for simple publish/subscribe lasyout
20+
* Publisher for simple publish/subscribe layout
2121
*/
22-
export class PubSubServer<T> extends Broker {
22+
export class PubSubPublisher<T> extends Broker {
2323
public name?: string;
2424
public fanout?: boolean;
2525

@@ -31,7 +31,7 @@ export class PubSubServer<T> extends Broker {
3131
* Initializes the client, making it ready to publish packets
3232
* @param options Options to use for the server
3333
*/
34-
public async init(options: PubSubServerInitOptions) {
34+
public async init(options: PubSubPublisherInitOptions) {
3535
const { name, fanout = false } = options;
3636

3737
this.name = fanout

libs/brokers/src/brokers/pubsub/PubSubClient.ts renamed to libs/brokers/src/brokers/pubsub/PubSubSubscriber.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import type { ConsumeQueueCallback } from '../BrokerUtil';
33
import type * as amqp from 'amqplib';
44

55
/**
6-
* Options for initializing the pub/sub client
6+
* Options for initializing the pub/sub consumer
77
*/
8-
export interface PubSubClientInitOptions<T> {
8+
export interface PubSubSubscriberInitOptions<T> {
99
/**
1010
* Name of the queue/exchange to use
1111
*/
@@ -21,9 +21,9 @@ export interface PubSubClientInitOptions<T> {
2121
}
2222

2323
/**
24-
* Client for simple publish/subscribe lasyout
24+
* Consumer for simple publish/subscribe layout
2525
*/
26-
export class PubSubClient<T> extends Broker {
26+
export class PubSubSubscriber<T> extends Broker {
2727
public constructor(channel: amqp.Channel) {
2828
super(channel);
2929
}
@@ -32,7 +32,7 @@ export class PubSubClient<T> extends Broker {
3232
* Initializes the server, making it listen to incoming packets
3333
* @param options Options to use for the client
3434
*/
35-
public async init(options: PubSubClientInitOptions<T>) {
35+
public async init(options: PubSubSubscriberInitOptions<T>) {
3636
const { fanout = false, cb } = options;
3737

3838
const name = fanout

libs/brokers/src/brokers/pubsub/pubsub.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { PubSubClient } from './PubSubClient';
2-
import { PubSubServer } from './PubSubServer';
1+
import { PubSubSubscriber } from './PubSubSubscriber';
2+
import { PubSubPublisher } from './PubSubPublisher';
33
import { createAmqp } from '../../amqp';
44
import { CordisBrokerError } from '../../error';
55
import type * as amqp from 'amqplib';
@@ -52,13 +52,13 @@ jest.mock('amqplib', () => {
5252
});
5353

5454
const eventCb = jest.fn(() => Promise.resolve());
55-
let client!: PubSubClient<string>;
56-
let server!: PubSubServer<string>;
55+
let client!: PubSubSubscriber<string>;
56+
let server!: PubSubPublisher<string>;
5757

5858
beforeEach(async () => {
5959
const { channel } = await createAmqp('boop');
60-
client = new PubSubClient(channel);
61-
server = new PubSubServer(channel);
60+
client = new PubSubSubscriber(channel);
61+
server = new PubSubPublisher(channel);
6262
});
6363

6464
afterEach(() => jest.clearAllMocks());

libs/brokers/src/brokers/routing/RoutingServer.ts renamed to libs/brokers/src/brokers/routing/RoutingPublisher.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type * as amqp from 'amqplib';
55
/**
66
* Options for initializing the routing server
77
*/
8-
export interface RoutingServerInitOptions {
8+
export interface RoutingPublisherInitOptions {
99
/**
1010
* Name of the exchange to use
1111
*/
@@ -19,7 +19,7 @@ export interface RoutingServerInitOptions {
1919
/**
2020
* Server-side broker for routing packets using keys
2121
*/
22-
export class RoutingServer<K extends string, T extends Record<K, any>> extends Broker {
22+
export class RoutingPublisher<K extends string, T extends Record<K, any>> extends Broker {
2323
/**
2424
* Exchange being used
2525
*/
@@ -33,7 +33,7 @@ export class RoutingServer<K extends string, T extends Record<K, any>> extends B
3333
* Initializes the server
3434
* @param options Options used for this server
3535
*/
36-
public async init(options: RoutingServerInitOptions) {
36+
public async init(options: RoutingPublisherInitOptions) {
3737
this.exchange = await this.channel
3838
.assertExchange(options.name, options.topicBased ? 'topic' : 'direct', { durable: false })
3939
.then(d => d.exchange);

libs/brokers/src/brokers/routing/RoutingClient.ts renamed to libs/brokers/src/brokers/routing/RoutingSubscriber.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type * as amqp from 'amqplib';
44
/**
55
* Options for initializing the routing client
66
*/
7-
export interface RoutingClientInitOptions<K extends string> {
7+
export interface RoutingSubscriberInitOptions<K extends string> {
88
/**
99
* Name of the exchange to use
1010
*/
@@ -29,7 +29,7 @@ export interface RoutingClientInitOptions<K extends string> {
2929
maxMessageAge?: number;
3030
}
3131

32-
export interface RoutingClient<K extends string, T extends Record<K, any>> extends Broker {
32+
export interface RoutingSubscriber<K extends string, T extends Record<K, any>> extends Broker {
3333
/**
3434
* Event used mostly for internal errors
3535
* @event
@@ -55,7 +55,7 @@ export interface RoutingClient<K extends string, T extends Record<K, any>> exten
5555
/**
5656
* Client-side broker for routing packets using keys
5757
*/
58-
export class RoutingClient<K extends string, T extends Record<K, any>> extends Broker {
58+
export class RoutingSubscriber<K extends string, T extends Record<K, any>> extends Broker {
5959
public constructor(channel: amqp.Channel) {
6060
super(channel);
6161
}
@@ -64,7 +64,7 @@ export class RoutingClient<K extends string, T extends Record<K, any>> extends B
6464
* Initializes the client, binding the events you want to the queue
6565
* @param options Options used for this client
6666
*/
67-
public async init(options: RoutingClientInitOptions<K>) {
67+
public async init(options: RoutingSubscriberInitOptions<K>) {
6868
const { name, topicBased = false, keys, queue: rawQueue = '', maxMessageAge = Infinity } = options;
6969

7070
const exchange = await this.channel.assertExchange(name, topicBased ? 'topic' : 'direct', { durable: false }).then(d => d.exchange);

libs/brokers/src/brokers/routing/routing.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { RoutingClient } from './RoutingClient';
2-
import { RoutingServer } from './RoutingServer';
1+
import { RoutingSubscriber } from './RoutingSubscriber';
2+
import { RoutingPublisher } from './RoutingPublisher';
33
import { createAmqp } from '../../amqp';
44
import { CordisBrokerError } from '../../error';
55
import type * as amqp from 'amqplib';
@@ -58,13 +58,13 @@ interface Data {
5858
}
5959

6060
const eventCb = jest.fn();
61-
let client!: RoutingClient<keyof Data, Data>;
62-
let server!: RoutingServer<keyof Data, Data>;
61+
let client!: RoutingSubscriber<keyof Data, Data>;
62+
let server!: RoutingPublisher<keyof Data, Data>;
6363

6464
beforeEach(async () => {
6565
const { channel } = await createAmqp('boop');
66-
client = new RoutingClient(channel);
67-
server = new RoutingServer(channel);
66+
client = new RoutingSubscriber(channel);
67+
server = new RoutingPublisher(channel);
6868
});
6969

7070
afterEach(() => jest.clearAllMocks());

libs/brokers/src/brokers/rpc/RpcClient.ts renamed to libs/brokers/src/brokers/rpc/RpcPublisher.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type * as amqp from 'amqplib';
55
/**
66
* Options for initializing the RPC client
77
*/
8-
export interface RpcClientInitOptions {
8+
export interface RpcPublisherInitOptions {
99
/**
1010
* Queue the server should be recieving requests on
1111
*/
@@ -20,7 +20,7 @@ export interface RpcClientInitOptions {
2020
* Client-side broker for a simple RPC layout
2121
*/
2222
// eslint-disable-next-line @typescript-eslint/no-unused-vars
23-
export interface RpcClient<S, C> extends Broker {
23+
export interface RpcPublisher<S, C> extends Broker {
2424
/**
2525
* Event used mostly for internal errors
2626
* @event
@@ -45,7 +45,7 @@ export interface RpcClient<S, C> extends Broker {
4545
/**
4646
* Client-side broker for a simple RPC layout
4747
*/
48-
export class RpcClient<S, C> extends Broker {
48+
export class RpcPublisher<S, C> extends Broker {
4949
/**
5050
* Queue used to send requests to the server
5151
*/
@@ -67,7 +67,7 @@ export class RpcClient<S, C> extends Broker {
6767
* Initializes the client, making it listen for reply packets
6868
* @param options Options used for this client
6969
*/
70-
public async init(options: RpcClientInitOptions) {
70+
public async init(options: RpcPublisherInitOptions) {
7171
const { name, timeout = 1e4 } = options;
7272

7373
this.serverQueue = await this.channel.assertQueue(name, { durable: false }).then(d => d.queue);

libs/brokers/src/brokers/rpc/RpcServer.ts renamed to libs/brokers/src/brokers/rpc/RpcSubscriber.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@ import type * as amqp from 'amqplib';
44
/**
55
* Callback used for generating a server response from the client-given data
66
*/
7-
export type RpcServerCallback<C, S> = (content: C) => S | Promise<S>;
7+
export type RpcSubscriberCallback<C, S> = (content: C) => S | Promise<S>;
88

99
/**
1010
* Options for initializing the RPC server
1111
*/
12-
export interface RpcServerInitOptions<S, C> {
12+
export interface RpcSubscriberInitOptions<S, C> {
1313
/**
1414
* Queue the server should be recieving requests on
1515
*/
1616
name: string;
1717
/**
1818
* The callback to run for each message
1919
*/
20-
cb: RpcServerCallback<C, S>;
20+
cb: RpcSubscriberCallback<C, S>;
2121
}
2222

2323
/**
2424
* Server-side broker for a simple RPC layout
2525
*/
26-
export class RpcServer<S, C> extends Broker {
26+
export class RpcSubscriber<S, C> extends Broker {
2727
public constructor(channel: amqp.Channel) {
2828
super(channel);
2929
}
@@ -32,7 +32,7 @@ export class RpcServer<S, C> extends Broker {
3232
* Initializes the server, making it listen for packets
3333
* @param options Options used for this server
3434
*/
35-
public async init(options: RpcServerInitOptions<S, C>) {
35+
public async init(options: RpcSubscriberInitOptions<S, C>) {
3636
const { name, cb } = options;
3737

3838
const queue = await this.channel.assertQueue(name, { durable: false }).then(d => d.queue);

libs/brokers/src/brokers/rpc/rpc.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { RpcClient } from './RpcClient';
2-
import { RpcServer } from './RpcServer';
1+
import { RpcPublisher } from './RpcPublisher';
2+
import { RpcSubscriber } from './RpcSubscriber';
33
import { createAmqp } from '../../amqp';
44
import { CordisBrokerError } from '../../error';
55
import type * as amqp from 'amqplib';
@@ -80,13 +80,13 @@ jest.mock('amqplib', () => {
8080
};
8181
});
8282

83-
let client!: RpcClient<string, string>;
84-
let server!: RpcServer<string, string>;
83+
let client!: RpcPublisher<string, string>;
84+
let server!: RpcSubscriber<string, string>;
8585

8686
beforeEach(async () => {
8787
const { channel } = await createAmqp('boop');
88-
client = new RpcClient(channel);
89-
server = new RpcServer(channel);
88+
client = new RpcPublisher(channel);
89+
server = new RpcSubscriber(channel);
9090
});
9191

9292
afterEach(() => jest.clearAllMocks());

libs/brokers/src/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
export * from './brokers/Broker';
22

3-
export * from './brokers/pubsub/PubSubClient';
4-
export * from './brokers/pubsub/PubSubServer';
3+
export * from './brokers/pubsub/PubSubPublisher';
4+
export * from './brokers/pubsub/PubSubSubscriber';
55

6-
export * from './brokers/routing/RoutingClient';
7-
export * from './brokers/routing/RoutingServer';
6+
export * from './brokers/routing/RoutingPublisher';
7+
export * from './brokers/routing/RoutingSubscriber';
88

9-
export * from './brokers/rpc/RpcClient';
10-
export * from './brokers/rpc/RpcServer';
9+
export * from './brokers/rpc/RpcPublisher';
10+
export * from './brokers/rpc/RpcSubscriber';
1111

1212
export * from './amqp';
1313

0 commit comments

Comments
 (0)