mock-amqplib's People
Forkers
pibi joge97 seberik mohithg mikamai propellerfactory nurchik crobinson42 pazzaak caioteixeira95 titaninvest willianbvsanches13 stepanho sefiros1 tkhtechnology stephen-shopopopmock-amqplib's Issues
assertExchange should return { exchange : string }
the function assertExchange should return an AssertExchange type:
https://amqp-node.github.io/amqplib/channel_api.html#channel_assertExchange
assertExchange(exchange: string, type: 'direct' | 'topic' | 'headers' | 'fanout' | 'match' | string, options?: Options.AssertExchange): Promise<Replies.AssertExchange>;
interface AssertExchange {
exchange: string;
}
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 :)
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
How to test consume
Is there a way to test a callback on channel.consume?
support topic exchange
Could you please support topic exchanges? assertExchange() with a topic exchange yields an unassigned exchange.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.