amqp-connection-manager
- Version 5.0.0
- Published
- 148 kB
- 1 dependency
- MIT license
Install
npm i amqp-connection-manageryarn add amqp-connection-managerpnpm add amqp-connection-managerOverview
Auto-reconnect and round robin support for amqplib.
Index
Variables
Functions
Classes
Interfaces
Type Aliases
Namespaces
Variables
variable amqp
const amqp: { connect: typeof connect };Functions
function connect
connect: ( urls: ConnectionUrl | ConnectionUrl[] | undefined | null, options?: AmqpConnectionManagerOptions) => IAmqpConnectionManager;Classes
class AmqpConnectionManagerClass
class AmqpConnectionManager extends EventEmitter implements IAmqpConnectionManager {}constructor
constructor(urls: any, options?: AmqpConnectionManagerOptions);Create a new AmqplibConnectionManager.
Parameter urls
An array of brokers to connect to. Takes url strings or objects {url: string, connectionOptions?: object} If present, a broker's [connectionOptions] will be used instead of [options.connectionOptions] when passed to the amqplib connect method. AmqplibConnectionManager will round-robin between them whenever it needs to create a new connection.
Parameter options
Parameter
[options.heartbeatIntervalInSeconds=5] - The interval, in seconds, to send heartbeats.
Parameter
[options.reconnectTimeInSeconds] - The time to wait before trying to reconnect. If not specified, defaults to
heartbeatIntervalInSeconds.Parameter
[options.connectionOptions] - Passed to the amqplib connect method.
Parameter
[options.findServers] - A
fn(callback)or afn()which returns a Promise. This should resolve to one or more servers to connect to, either a single URL or an array of URLs. This is handy when you're using a service discovery mechanism such as Consul or etcd. Note that if this is supplied, thenurlsis ignored.
property channelCount
readonly channelCount: number;Returns the number of registered channels.
property connection
readonly connection: any;The current connection.
property connectionOptions
connectionOptions: any;property heartbeatIntervalInSeconds
heartbeatIntervalInSeconds: number;property reconnectTimeInSeconds
reconnectTimeInSeconds: number;method close
close: () => Promise<void>;method connect
connect: ({ timeout }?: { timeout?: number }) => Promise<void>;Start the connect retries and await the first connect result. Even if the initial connect fails or timeouts, the reconnect attempts will continue in the background.
Parameter options
Parameter
[options.timeout] - Time to wait for initial connect
method createChannel
createChannel: (options?: CreateChannelOpts) => ChannelWrapper;method isConnected
isConnected: () => boolean;method reconnect
reconnect: () => void;Force reconnect - noop unless connected
Interfaces
interface AmqpConnectionManager
interface IAmqpConnectionManager extends EventEmitter {}property channelCount
readonly channelCount: number;Returns the number of registered channels.
property connection
readonly connection: amqp.ChannelModel | undefined;The current connection.
property connectionOptions
connectionOptions?: AmqpConnectionOptions;property heartbeatIntervalInSeconds
heartbeatIntervalInSeconds: number;property reconnectTimeInSeconds
reconnectTimeInSeconds: number;method addListener
addListener: { (event: string, listener: (...args: any[]) => void): this; (event: 'connect', listener: ConnectListener): this; (event: 'connectFailed', listener: ConnectFailedListener): this; (event: 'blocked', listener: (arg: { reason: string }) => void): this; (event: 'unblocked', listener: () => void): this; (event: 'disconnect', listener: (arg: { err: Error }) => void): this;};method close
close: () => Promise<void>;method connect
connect: (options?: { timeout?: number }) => Promise<void>;method createChannel
createChannel: (options?: CreateChannelOpts) => ChannelWrapper;method isConnected
isConnected: () => boolean;method listeners
listeners: (eventName: string | symbol) => Function[];method on
on: { (event: string, listener: (...args: any[]) => void): this; (event: 'connect', listener: ConnectListener): this; (event: 'connectFailed', listener: ConnectFailedListener): this; (event: 'blocked', listener: (arg: { reason: string }) => void): this; (event: 'unblocked', listener: () => void): this; (event: 'disconnect', listener: (arg: { err: Error }) => void): this;};method once
once: { (event: string, listener: (...args: any[]) => void): this; (event: 'connect', listener: ConnectListener): this; (event: 'connectFailed', listener: ConnectFailedListener): this; (event: 'blocked', listener: (arg: { reason: string }) => void): this; (event: 'unblocked', listener: () => void): this; (event: 'disconnect', listener: (arg: { err: Error }) => void): this;};method prependListener
prependListener: { (event: string, listener: (...args: any[]) => void): this; (event: 'connect', listener: ConnectListener): this; (event: 'connectFailed', listener: ConnectFailedListener): this; (event: 'blocked', listener: (arg: { reason: string }) => void): this; (event: 'unblocked', listener: () => void): this; (event: 'disconnect', listener: (arg: { err: Error }) => void): this;};method prependOnceListener
prependOnceListener: { (event: string, listener: (...args: any[]) => void): this; (event: 'connect', listener: ConnectListener): this; (event: 'connectFailed', listener: ConnectFailedListener): this; (event: 'blocked', listener: (arg: { reason: string }) => void): this; (event: 'unblocked', listener: () => void): this; (event: 'disconnect', listener: (arg: { err: Error }) => void): this;};method reconnect
reconnect: () => void;method removeListener
removeListener: (event: string, listener: (...args: any[]) => void) => this;interface AmqpConnectionManagerOptions
interface AmqpConnectionManagerOptions {}property connectionOptions
connectionOptions?: AmqpConnectionOptions;Connection options, passed as options to the amqplib.connect() method.
property findServers
findServers?: | ((callback: (urls: ConnectionUrl | ConnectionUrl[]) => void) => void) | (() => Promise<ConnectionUrl | ConnectionUrl[]>) | undefined;findServersis a function that which returns one or more servers to connect to. This should return either a single URL or an array of URLs. This is handy when you're using a service discovery mechanism such as Consul or etcd. Instead of taking a callback, this can also return a Promise. Note that if this is supplied, thenurlsis ignored.
property heartbeatIntervalInSeconds
heartbeatIntervalInSeconds?: number;Interval to send heartbeats to broker. Defaults to 5 seconds.
property reconnectTimeInSeconds
reconnectTimeInSeconds?: number | undefined;The time to wait before trying to reconnect. If not specified, defaults to
heartbeatIntervalInSeconds.
interface CreateChannelOpts
interface CreateChannelOpts {}property confirm
confirm?: boolean;True to create a ConfirmChannel (default). False to create a regular Channel.
property json
json?: boolean;if true, then ChannelWrapper assumes all messages passed to publish() and sendToQueue() are plain JSON objects. These will be encoded automatically before being sent.
property name
name?: string;Name for this channel. Used for debugging.
property publishTimeout
publishTimeout?: number;Default publish timeout in ms. Messages not published within the given time are rejected with a timeout error.
property setup
setup?: SetupFunc;A function to call whenever we reconnect to the broker (and therefore create a new underlying channel.) This function should either accept a callback, or return a Promise. See addSetup below
Type Aliases
type Channel
type Channel = amqplib.ConfirmChannel | amqplib.Channel;type ChannelWrapper
type ChannelWrapper = CW;type ConnectionUrl
type ConnectionUrl = | string | amqp.Options.Connect | { url: string; connectionOptions?: AmqpConnectionOptions; };type SetupFunc
type SetupFunc = | ((channel: Channel, callback: (error?: Error) => void) => void) | ((channel: Channel) => Promise<void>) | ((channel: amqplib.ConfirmChannel, callback: (error?: Error) => void) => void) | ((channel: amqplib.ConfirmChannel) => Promise<void>);Namespaces
namespace Options
namespace Options {}type AssertExchange
type AssertExchange = AmqpLibOptions.AssertExchange;type AssertQueue
type AssertQueue = AmqpLibOptions.AssertQueue;type Connect
type Connect = AmqpLibOptions.Connect;type Consume
type Consume = AmqpLibOptions.Consume;type DeleteExchange
type DeleteExchange = AmqpLibOptions.DeleteExchange;type DeleteQueue
type DeleteQueue = AmqpLibOptions.DeleteQueue;type Get
type Get = AmqpLibOptions.Get;type Publish
type Publish = PublishOptions;Package Files (3)
Dependencies (1)
Dev Dependencies (34)
- @jwalton/semantic-release-config
- @semantic-release/changelog
- @semantic-release/git
- @types/amqplib
- @types/chai
- @types/chai-as-promised
- @types/chai-string
- @types/jest
- @types/node
- @types/whatwg-url
- @typescript-eslint/eslint-plugin
- @typescript-eslint/parser
- amqplib
- chai
- chai-as-promised
- chai-jest
- chai-string
- cross-env
- eslint
- eslint-config-prettier
- eslint-plugin-promise
- greenkeeper-lockfile
- husky
- istanbul
- jest
- jest-ts-webcompat-resolver
- lint-staged
- prettier
- pretty-quick
- promise-tools
- semantic-release
- ts-jest
- ts-node
- typescript
Peer Dependencies (1)
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/amqp-connection-manager.
- Markdown[](https://www.jsdocs.io/package/amqp-connection-manager)
- HTML<a href="https://www.jsdocs.io/package/amqp-connection-manager"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3649 ms. - Missing or incorrect documentation? Open an issue for this package.
