Skip to content
lenkanPublic

About

No description, website, or topics provided.

Resources

Stars

50 stars

Watchers

3 watching

Forks

Repository files navigation

deno-amqp

CI deno doc

This library is deprecated and no longer maintained.

Deno runs Node packages now, so a Deno-specific AMQP client is no longer needed. Use one of these instead:

  • amqplib — import amqp from "npm:amqplib"
  • @cloudamqp/amqp-client — import { AMQPClient } from "npm:@cloudamqp/amqp-client", if you want a TypeScript-native API

Both connect to RabbitMQ over amqp:// and amqps://.

Existing https://deno.land/x/amqp imports will keep working — those URLs are immutable. But this library does not type check on Deno 2, since it depends on the removed Deno.Reader, Deno.Writer and Deno.Closer types.

AMQP 0.9.1 implementation for https://deno.land/. The library is implemented to connect to a RabbitMQ broker. For testing purposes, an instance can be started using docker:

docker run -d --rm -p 15672:15672 -p 5672:5672 rabbitmq:3-management

Usage

Consume messages

import { connect } from "https://deno.land/x/amqp/mod.ts";

const connection = await connect();
const channel = await connection.openChannel();

const queueName = "my.queue";
await channel.declareQueue({ queue: queueName });
await channel.consume(
  { queue: queueName },
  async (args, props, data) => {
    console.log(JSON.stringify(args));
    console.log(JSON.stringify(props));
    console.log(new TextDecoder().decode(data));
    await channel.ack({ deliveryTag: args.deliveryTag });
  },
);

Publish messages

import { connect } from "https://deno.land/x/amqp/mod.ts";

const connection = await connect();
const channel = await connection.openChannel();

const queueName = "my.queue";
await channel.declareQueue({ queue: queueName });
await channel.publish(
  { routingKey: queueName },
  { contentType: "application/json" },
  new TextEncoder().encode(JSON.stringify({ foo: "bar" })),
);

await connection.close();

More examples

See examples/. Start the example consumer by running

deno run --allow-net examples/consume_message.ts queue

Then, send a message to the same queue using the default exchange using the example publisher

deno run --allow-net examples/publish_message.ts queue

Documentation

See autogenerated deno docs at: https://doc.deno.land/https/deno.land/x/amqp/mod.ts

Development

Testing

Run unit tests

deno test src/

Run module tests (requires an AMQP broker running on localhost)

deno test --allow-net module_test/

About

No description, website, or topics provided.

Resources

Stars

50 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages