Skip to content

Commit

Permalink
feat(rabbitmq): publish using ChannelWrapper
Browse files Browse the repository at this point in the history
Publish messages using the ChannelWrapper instead of the raw ConfirmChannel to take advantage of the
reliability features of  `amqp-connection-manager`.

BREAKING CHANGE: This changes the behavior of throwing connection related errors

re golevelup#673
  • Loading branch information
ttshivers committed Jan 15, 2024
1 parent 1891b32 commit c911a21
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions packages/rabbitmq/src/amqp/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,12 +592,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 @@ -609,21 +604,12 @@ 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.selectManagedChannel().publish(
exchange,
routingKey,
buffer,
options
);
}

private handleMessage<T, U>(
Expand Down

0 comments on commit c911a21

Please sign in to comment.