Code Monkey home page Code Monkey logo

deno-amqp's Introduction

deno-amqp

CI deno doc

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/

deno-amqp's People

Contributors

andrinheusser avatar cat66a avatar edward653 avatar eliassjogreen avatar lenkan avatar mikroskeem avatar nashaddams avatar ryooit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

deno-amqp's Issues

0.14.0 issue in createResolveable?

Working on upgrading a project I have in progress to latest Deno and library versions. What was working fine earlier (sadly I do not recall the Deno version), is now not compiling, and I do not think I am the cause (though I will admit to not being a Typescript expert by any stretch!!)

Deno version is:

deno 1.6.2 (release, x86_64-apple-darwin)
v8 8.8.278.2
typescript 4.1.3

The error trace is:

error: TS2322 [ERROR]: Type '(value: T | PromiseLike) => void' is not assignable to type '(value?: T | PromiseLike | Promise | undefined) => void'.
Types of parameters 'value' and 'value' are incompatible.
Type 'T | PromiseLike | Promise | undefined' is not assignable to type 'T | PromiseLike'.
Type 'undefined' is not assignable to type 'T | PromiseLike'.
resolveFun = resolve;
~~~~~~~~~~
at https://deno.land/x/[email protected]/src/resolvable.ts:13:5

Resource tcpStream remains after channel close

deno --version
deno 1.8.3 (release, x86_64-unknown-linux-gnu)
v8 9.0.257.3
typescript 4.2.2

# execute with:
deno run --allow-net test.ts
import {
  connect
} from 'https://deno.land/x/[email protected]/mod.ts'

// Init log resources
console.log(Deno.resources())

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

await channel.declareExchange(
  {
    exchange: 'test-exchange',
    type: 'fanout',
    durable: true,
    autoDelete: false,
  }
)

await channel.declareQueue(
  {
    autoDelete: false,
    durable: true,
    exclusive: false,
    passive: false,
    queue: 'test',
    arguments: {
      'x-max-length': 1000000,
      // // 1 Gigabyte
      'x-max-length-bytes': 1048576000,
    },
  }
)

await channel.bindQueue({
  exchange: 'test-exchange',
})

await channel.publish(...)

await channel.close()


// End log resources
console.log(Deno.resources())
// init
{ "0": "stdin", "1": "stdout", "2": "stderr" }
// end
{ "0": "stdin", "1": "stdout", "2": "stderr", "3": "tcpStream" }

The exchange, queue and published payload all works fine.
The application will however not exit after that close.

feat: auto reconnect in case broker fail

I hope to you can implement this feature because when the broker dies, we need to restart the deno to get it to reconnect, which is unacceptable for event handling.

Usage notice.

We have integrated this module in microlemon as part of the permissions granted by the MIT license.

Any questions regarding Microlemon and its RabbitMQ integration will be welcome.

Thank you.

ConnectionReset: Connection reset by peer (os error 104)

I'm getting this when trying to connect:

            this.connection = await amqp.connect({
              hostname: ENV.RABBITMQ_HOST,
              username: ENV.RABBITMQ_USER,
              password: ENV.RABBITMQ_PASS,
              port: parseInt(ENV.RABBITMQ_PORT),
              vhost: ENV.RABBITMQ_VHOST,
            });

I double checked env varialbes, they are correct. vhost is just "dev". host is "localhost"

This is running on Ubuntu 22.04

AMQPS / mTLS available with Deno unstable API

In Deno it is now possible to use mTLS
Thanks to the certChain and privateKey parameters in the unstable API of the connectTLS method.
Read more: https://deno.land/[email protected]?s=Deno.ConnectTlsOptions&unstable=.

Please consider adding to src/amqp_connect.ts the ability to specify client certificates to fully utilize TLS session with verify-peer option.

Since the parameter is only available with the unstable API, a possible solution is to generate an error if the certificate passed and the unstable option missing, as implemented here:
https://github.com/cloudydeno/deno-kubernetes_client/blob/main/transports/via-kubeconfig.ts#L87

Thank you for your work!

[Question]: Can we publish a persistent message?

Hello friend. I am new to rabbit-mq and I was working through their work queue tutorial and discovered the following code where I noticed persistent: true option.

channel.assertQueue(queue, {
  durable: true
});

channel.sendToQueue(queue, Buffer.from(msg), {
  persistent: true
});

I have tried finding parallels with deno-amqp lib and I was not able to find persistent: true option with channel.publish as seen below

const queue = 'task_queue';
await channel.declareQueue({ queue, durable: true });

await channel.publish(
	{ routingKey: queue },
	{ contentType: 'text' },
	new TextEncoder().encode(msg),
);

How can I set persistent: true option? Maybe I am not asking the the right question, any guidance would be appreciated.

TS2339 [ERROR]: Property 'methodId' does not exist on type 'never'

After upgraded Deno to v1.13.2, my repository that uses this library fails to run with these error messages:

TS2339 [ERROR]: Property 'methodId' does not exist on type 'never'.
            "Unknown method " + method!.methodId + " for class 'confirm'",
                                        ~~~~~~~~
    at https://deno.land/x/[email protected]/src/amqp_codec.ts:2570:41

TS2339 [ERROR]: Property 'classId' does not exist on type 'never'.
      throw new Error("Unknown class " + method!.classId);
                                                 ~~~~~~~
    at https://deno.land/x/[email protected]/src/amqp_codec.ts:2577:50

# similar errors in various positions ...

tsconfig.json.zip

I've attached tsconfig.json used in my project.

Please help check this issue. Thanks!

support basic.get

basic.get is the only AMQP method that can have two different response methods. The codegen currently does not handle this well, especially since basic.get-ok carries content and basic.get-empty does not. See:

If get should be exposed on AmqpChannel it needs to support both get-empty and get-ok appropriately.

Nack requeue:false not works correctly

Hi,

I'm trying to run this code:

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) => {
    //some error ...

    await channel.nack(
      { deliveryTag: BASIC_NACK, multiple: false, requeue: false },
    );
  },
);

I'm using a Dead Letter Exchanges structure on rabbitmq (https://www.rabbitmq.com/dlx.html).

According to the documentation, when executing the "nack" with "requeue:false", and with all the structure created behind it should go to another queue, but this does not happen, it is requeue.

As far as I could see in the code, these parameters are passed correctly.

Running the "same" code in .Net and Go and it works correctly, already identified something like that?

Connection String Format

Hi there, will this library supports connection string as the authentication parameters soon?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.