A simple amqp client that facilitates publishing and subscribing to an amqp v0.9.1 RabbitMQ broker.
$ npm i @meowwolf/amqp-0.9.1-client
import { createRabbitMqClient } from '@meowwolf/amqp-0.9.1-client'
// or
const { createRabbitMqClient } = require('@meowwolf/amqp-0.9.1-client')
const amqpClient = await createRabbitMqClient(amqpConfig, exchangeConfig)
/*
AmqpConfig {
host: string
port: number
username: string
password: string
appId?: string - default: '@meowwolf/amqp-0.9.1-client'
vhost?: string - default: '/'
tls?: boolean - default: false
prefetch?: number - default: 0
autoReconnect?: boolean - default: true
retryConnectionInterval?: number in ms - default: 5000
}
ExchangeConfig {
exchangeName?: string - default: 'amq.direct'
type?: 'direct' | 'fanout' | 'topic' | 'header' - default: 'direct'
durable?: boolean - default: false
autoDelete?: boolean
}
*/
addConsumer() expects an argument object consisting of a configuration object and a callback
await amqpClient.addConsumer({
queueConfig,
callback: message => {
// .. do somethig with the message here
},
})
/*
QueueConfig {
queueName?: string - default: ''
routingKey?: string | string[] - default: ''
exclusive?: boolean - default: true
durable?: boolean - default: false
autoDelete?: boolean - default: true
noAck?: boolean - default: true
}
*/
amqpclient.ack(message)
amqpClient.publish(payloadString, publishOptions)
/*
PublishOptions {
exchangeName?: string - defaults to exchangeConfig value
routingKey?: string | string[] - default: ''
correlationId?: string - default: ''
headers?: GenericObject - default: {}
}
*/
amqpClient.sendToQueue(payloadString, sendToQueueOptions)
/*
SendToQueueOptions {
queueName: string
correlationId?: string - default: ''
headers?: GenericObject - default: {}
}
*/