JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 36722
  • Score
    100M100P100Q160270F
  • License Apache-2.0

AMQP 0-9-1 client, both for browsers (WebSocket) and node (TCP Socket)

Package Exports

  • @cloudamqp/amqp-client

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@cloudamqp/amqp-client) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

amqp-client.js

AMQP 0-9-1 client both for Node.js and browsers (using WebSocket)

Install

npm install @cloudamqp/amqp-client --save

Example usage

import AMQPClient from 'amqp-client'

async function run() {
  try {
    const amqp = new AMQPClient("amqp://localhost")
    const conn = await amqp.connect()
    const ch = await conn.channel()
    const q = await ch.queue()
    let i = 0
    const consumer = await q.subscribe({noAck: true}, async (msg) => {
      console.log(msg.bodyString())
      if (i++ < 3)
        setTimeout(() => q.publish(`hello world ${i}`), 1000)
      else
        await consumer.cancel()
    })
    await q.publish("first!")
    await consumer.wait() // will block until consumer is cancled or throw an error if server closed channel/connection
    await conn.close()
  } catch (e) {
    console.error("ERROR", e)
    e.connection.close()
    setTimeout(run, 1000) // will try to reconnect in 1s
  }
}

run()