@hamq/client
v0.1.9
Published
A High level type-safe AMQP client with auto-reconnect and auto-declare
Downloads
7
Maintainers
Readme
@hamq/client
A simple and elegant AMQP client written by TypeScript
Inspired by amqp-ts
Usage
An example
import * as amqp from '@hamq/client';
// const amqp = require("@hamq/client"); // js require
async function run() {
const connection = new amqp.Connection('amqp://localhost');
const exchange = connection.declareExchange('ExchangeName');
const queue = connection.declareQueue('QueueName');
await queue.bind(exchange);
await queue.consume(message => {
console.log('Message received: ' + message.getContent());
});
// it is possible that the following message is not received because
// it can be sent before the queue, binding or consumer exist
const msg = new amqp.Message('Test');
exchange.send(msg);
await connection.ready();
// the following message will be received because
// everything you defined earlier for this connection now exists
const msg2 = new amqp.Message('Test2');
exchange.send(msg2);
}
run().catch(console.error);
More examples can be found in the tutorials directory.
Connection Status
connection.connected
: Returns true if the connection exists and false, otherwise.connection.online()
: Resolved when connected.connection.ready()
: Resolved when connected and all resources(actors) has been ready.
Events
Automatic Reconnection
When the library detects that the connection with the AMQP server is lost, it tries to automatically reconnect to the server.
It is powered by connback.
Roadmap
- Better documentation