Skip to content
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

feat(rabbitmq): publish using ChannelWrapper #678

Merged
merged 1 commit into from
Jan 16, 2024
Merged
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
24 changes: 2 additions & 22 deletions packages/rabbitmq/src/amqp/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
ConfirmChannel,
Options,
} from 'amqplib';
import { Replies } from 'amqplib/properties';
import {
EMPTY,
interval,
Expand Down Expand Up @@ -589,12 +588,7 @@ export class AmqpConnection {
routingKey: string,
message: T,
options?: Options.Publish
): Promise<Replies.Empty> {
// source amqplib channel is used directly to keep the behavior of throwing connection related errors
if (!this.managedConnection.isConnected() || !this._channel) {
throw new Error('AMQP connection is not available');
}

): Promise<boolean> {
let buffer: Buffer;
if (message instanceof Buffer) {
buffer = message;
Expand All @@ -606,21 +600,7 @@ export class AmqpConnection {
buffer = Buffer.alloc(0);
}

return new Promise((resolve, reject) => {
this._channel.publish(
exchange,
routingKey,
buffer,
options,
(err, ok) => {
if (err) {
reject(err);
} else {
resolve(ok);
}
}
);
});
return this._managedChannel.publish(exchange, routingKey, buffer, options);
}

private handleMessage<T, U>(
Expand Down
Loading