Skip to content

nashaddams/amqp

 
 

Repository files navigation

amqp

This is a fork of the fantastic deno-amqp AMQP 0.9.1 implementation.

JSR main

Usage

Consuming messages

import { connect } from "jsr:@nashaddams/amqp";

const connection = await connect({
  hostname: "127.0.0.1",
  port: 5672,
});
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 });
  },
);

Publishing messages

import { connect } from "jsr:@nashaddams/amqp";

const connection = await connect({
  hostname: "127.0.0.1",
  port: 5672,
});
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();

TLS

import { connect } from "jsr:@nashaddams/amqp";

const connection = await connect({
  hostname: "127.0.0.1",
  port: 5671,
  key: "...",
  cert: "...",
  caCerts: ["..."],
});

// ...

Testing

podman run -d --rm \
  -p 15672:15672 \
  -p 5671:5671 \
  -p 5672:5672 \
  -v ./test/conf/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf \
  -v ./test/conf/enabled_plugins:/etc/rabbitmq/enabled_plugins \
  -v ./test/cert/ca_certificate.pem:/etc/ssl/certs/rabbitmq/ca_certificate.pem \
  -v ./test/cert/server_guest_certificate.pem:/etc/ssl/certs/rabbitmq/server_guest_certificate.pem \
  -v ./test/cert/server_guest_key.pem:/etc/ssl/certs/rabbitmq/server_guest_key.pem \
  rabbitmq:4-management

deno task test
deno task test:mod

Generating certificates

The certificates are generated with tls-gen:

git clone https://github.com/rabbitmq/tls-gen.git
cd basic
make CN=guest

result/ca_certificate.pem
result/client_guest_certificate.pem
result/client_guest_key.pem
result/server_guest_certificate.pem
result/server_guest_key.pem

Acknowledgments

Thanks to @lenkan for creating deno-amqp.

About

AMQP 0.9.1 implementation for Deno

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%