Skip to content

fix: rabbitmq bindings and auto-generated queues #14129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/microservices/client/client-rmq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@ export class ClientRMQ extends ClientProxy {
if (!this.noAssert) {
await channel.assertQueue(this.queue, this.queueOptions);
}

if (this.options.exchange && this.options.routingKey) {
await channel.bindQueue(
this.queue,
this.options.exchange,
this.options.routingKey,
);
}

await channel.prefetch(prefetchCount, isGlobalPrefetchCount);
await this.consumeChannel(channel);
resolve();
Expand Down
2 changes: 1 addition & 1 deletion packages/microservices/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const PARAM_ARGS_METADATA = ROUTE_ARGS_METADATA;
export const REQUEST_PATTERN_METADATA = 'microservices:request_pattern';
export const REPLY_PATTERN_METADATA = 'microservices:reply_pattern';

export const RQM_DEFAULT_QUEUE = 'default';
export const RQM_DEFAULT_QUEUE = '';
export const RQM_DEFAULT_PREFETCH_COUNT = 0;
export const RQM_DEFAULT_IS_GLOBAL_PREFETCH_COUNT = false;
export const RQM_DEFAULT_QUEUE_OPTIONS = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ export interface RmqOptions {
isGlobalPrefetchCount?: boolean;
queueOptions?: AmqplibQueueOptions;
socketOptions?: AmqpConnectionManagerSocketOptions;
exchange?: string;
routingKey?: string;
noAck?: boolean;
consumerTag?: string;
serializer?: Serializer;
Expand Down
12 changes: 12 additions & 0 deletions packages/microservices/server/server-rmq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,18 @@ export class ServerRMQ extends Server implements CustomTransportStrategy {
if (!this.noAssert) {
await channel.assertQueue(this.queue, this.queueOptions);
}

if (this.options.exchange && this.options.routingKey) {
await channel.assertExchange(this.options.exchange, 'topic', {
durable: true,
});
await channel.bindQueue(
this.queue,
this.options.exchange,
this.options.routingKey,
);
}

await channel.prefetch(this.prefetchCount, this.isGlobalPrefetchCount);
channel.consume(
this.queue,
Expand Down