Skip to content

Commit ca86bf6

Browse files
Merge pull request #14129 from EeeasyCode/fix/issue-#13931
fix: rabbitmq bindings and auto-generated queues
2 parents 09a1933 + e231f98 commit ca86bf6

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

packages/microservices/client/client-rmq.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,15 @@ export class ClientRMQ extends ClientProxy {
192192
if (!this.noAssert) {
193193
await channel.assertQueue(this.queue, this.queueOptions);
194194
}
195+
196+
if (this.options.exchange && this.options.routingKey) {
197+
await channel.bindQueue(
198+
this.queue,
199+
this.options.exchange,
200+
this.options.routingKey,
201+
);
202+
}
203+
195204
await channel.prefetch(prefetchCount, isGlobalPrefetchCount);
196205
await this.consumeChannel(channel);
197206
resolve();

packages/microservices/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const PARAM_ARGS_METADATA = ROUTE_ARGS_METADATA;
3333
export const REQUEST_PATTERN_METADATA = 'microservices:request_pattern';
3434
export const REPLY_PATTERN_METADATA = 'microservices:reply_pattern';
3535

36-
export const RQM_DEFAULT_QUEUE = 'default';
36+
export const RQM_DEFAULT_QUEUE = '';
3737
export const RQM_DEFAULT_PREFETCH_COUNT = 0;
3838
export const RQM_DEFAULT_IS_GLOBAL_PREFETCH_COUNT = false;
3939
export const RQM_DEFAULT_QUEUE_OPTIONS = {};

packages/microservices/interfaces/microservice-configuration.interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ export interface RmqOptions {
209209
isGlobalPrefetchCount?: boolean;
210210
queueOptions?: AmqplibQueueOptions;
211211
socketOptions?: AmqpConnectionManagerSocketOptions;
212+
exchange?: string;
213+
routingKey?: string;
212214
noAck?: boolean;
213215
consumerTag?: string;
214216
serializer?: Serializer;

packages/microservices/server/server-rmq.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,18 @@ export class ServerRMQ extends Server implements CustomTransportStrategy {
153153
if (!this.noAssert) {
154154
await channel.assertQueue(this.queue, this.queueOptions);
155155
}
156+
157+
if (this.options.exchange && this.options.routingKey) {
158+
await channel.assertExchange(this.options.exchange, 'topic', {
159+
durable: true,
160+
});
161+
await channel.bindQueue(
162+
this.queue,
163+
this.options.exchange,
164+
this.options.routingKey,
165+
);
166+
}
167+
156168
await channel.prefetch(this.prefetchCount, this.isGlobalPrefetchCount);
157169
channel.consume(
158170
this.queue,

0 commit comments

Comments
 (0)