@hamq/client
TypeScript icon, indicating that this package has built-in type declarations

0.1.9 • Public • Published

@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

All events from connback

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

/@hamq/client/

    Package Sidebar

    Install

    npm i @hamq/client

    Weekly Downloads

    1

    Version

    0.1.9

    License

    MIT

    Unpacked Size

    111 kB

    Total Files

    51

    Last publish

    Collaborators

    • towyuan