Code Monkey home page Code Monkey logo

mock-amqplib's People

Contributors

bernardini687 avatar caioteixeira95 avatar joge97 avatar mjcctech avatar mkls avatar monster-zero-sugar avatar newx666 avatar stepanho avatar

Stargazers

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

Watchers

 avatar  avatar

mock-amqplib's Issues

Add support to exchange type 'x-delayed-message'

Hello folks! I hope you are doing well. ๐Ÿ‘‹ ๐Ÿ˜ƒ

I'm currently working on a project that uses this awesome lib to mock the amqp connection and the amqplib instance. ๐Ÿš€
Today, we've added an exchange layer because some messages must be delayed before being consumed by the consumers. Here's an example of how we are setting things up:

const connection = amqplib.connect('amqp://localhost')
const channel = connection.createChannel()

const queue = 'my-queue'
const exchange = `my-exchange-${queue}`
const binding = `${queue}-exchange-binding`

channel.assertExchange(exchange, 'x-delayed-message', {
  durable: true,
  arguments: { 'x-delayed-type': 'direct' },
})
channel.assertQueue(queue, { durable: true })
channel.bindQueue(queue, exchange, binding)

Here's our jest-setup file:

beforeAll(() => {
  amqplib.connect = mockAmqplib.connect
})

When we try to run the tests we receive the following error:

TypeError: Cannot read properties of undefined (reading 'bindQueue')
        at Object.bindQueue (/path/to/node_modules/mock-amqplib/src/main.js:119:14)

That happens because on the assertExchange mock it doesn't match to any type so the exchange is undefined.

// main.js:100

assertExchange: async (exchangeName, type) => {
  let exchange;

  switch(type) {
    case 'fanout':
      exchange = createFanoutExchange();
      break;
    case 'direct':
      exchange = createDirectExchange();
      break;
    case 'headers':
      exchange = createHeadersExchange();
      break;
  }

  exchanges[exchangeName] = exchange;
},

We did some tests using the same exchange as the case direct and it worked fine. So, my suggestion is to add x-delayed-message as the same as direct. We're going to have:

// main.js:100

assertExchange: async (exchangeName, type) => {
  let exchange;

  switch(type) {
    case 'fanout':
      exchange = createFanoutExchange();
      break;
    case 'direct':
    case 'x-delayed-message':
      exchange = createDirectExchange();
      break;
    case 'headers':
      exchange = createHeadersExchange();
      break;
  }

  exchanges[exchangeName] = exchange;
},

We're using the following versions of the libs:

  • amqplib: "^0.8.0"
  • mock-amqplib: "^1.4.0"

What do you folks think about that? Let me know if you have any questions.

support checkExchange

Could you please add support for this method on Channel?

checkExchange(exchange: string): Promise<Replies.Empty>;

Thanks

publishing to a topic exchange with a bad routing key generates an error

1- create an exchange (topic, direct, header...)
2- create a queue and bind it with a binding key
3- publish a message to the exchange, using a routing key that does not match any binding key and the exchange binding logic.

it generates this error:

TypeError: Cannot read property 'targetQueue' of undefined
at Object.getTargetQueues .../node_modules/mock-amqplib/src/main.js:57:31) // for direct, similar error for others.

It should instead check the mandatory property of the message, and handle the logic described here: https://www.rabbitmq.com/publishers.html
In the meantime a more friendly error message would help :)

support topic exchange

Could you please support topic exchanges? assertExchange() with a topic exchange yields an unassigned exchange.

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.