-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement automatic reconnection propagation (#38)
- Loading branch information
Showing
18 changed files
with
494 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { Either } from '@lokalise/node-core' | ||
import type { MessageInvalidFormatError, MessageValidationError } from '@message-queue-toolkit/core' | ||
import { objectToBuffer } from '@message-queue-toolkit/core' | ||
|
||
import { AbstractAmqpService } from './AbstractAmqpService' | ||
|
||
export abstract class AbstractAmqpBasePublisher< | ||
MessagePayloadType extends object, | ||
> extends AbstractAmqpService<MessagePayloadType> { | ||
protected sendToQueue(message: MessagePayloadType): void { | ||
try { | ||
this.channel.sendToQueue(this.queueName, objectToBuffer(message)) | ||
} catch (err) { | ||
// Unfortunately, reliable retry mechanism can't be implemented with try-catch block, | ||
// as not all failures end up here. If connection is closed programmatically, it works fine, | ||
// but if server closes connection unexpectedly (e. g. RabbitMQ is shut down), then we don't land here | ||
// @ts-ignore | ||
if (err.message === 'Channel closed') { | ||
this.logger.error(`AMQP channel closed`) | ||
void this.reconnect() | ||
} else { | ||
throw err | ||
} | ||
} | ||
} | ||
|
||
/* c8 ignore start */ | ||
protected resolveMessage(): Either<MessageInvalidFormatError | MessageValidationError, unknown> { | ||
throw new Error('Not implemented for publisher') | ||
} | ||
/* c8 ignore stop */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.