onify / fake-amqplib

fake nodejs amqplib
MIT License
3 stars 0 forks source link

TypeError: callback is not a function when trying to acknowledge a message #2

Closed victor-solvethex closed 3 years ago

victor-solvethex commented 3 years ago

I'm trying to acknowledge a message with channel.ack(msg) but it fails for some reason using your library on tests

TypeError: callback is not a function

      at confirmCallback (node_modules/@onify/fake-amqplib/index.js:270:11)
      at onConsumeMessage (node_modules/@onify/fake-amqplib/index.js:265:20)
      at eventCallback (node_modules/smqp/dist/src/Broker.js:478:9)
      at consume (node_modules/smqp/dist/src/Queue.js:573:5)
      at Object.push (node_modules/smqp/dist/src/Queue.js:546:7)
      at consumeNext (node_modules/smqp/dist/src/Queue.js:146:16)
      at Object.queueMessage (node_modules/smqp/dist/src/Queue.js:125:28)
      at publishToQueue (node_modules/smqp/dist/src/Exchange.js:123:11)
      at node_modules/smqp/dist/src/Exchange.js:103:11
          at Array.forEach (<anonymous>)
      at topic (node_modules/smqp/dist/src/Exchange.js:101:15)
      at consume (node_modules/smqp/dist/src/Queue.js:573:5)
      at Object.push (node_modules/smqp/dist/src/Queue.js:546:7)
      at consumeNext (node_modules/smqp/dist/src/Queue.js:146:16)
      at Object.queueMessage (node_modules/smqp/dist/src/Queue.js:125:28)
      at Object.publish (node_modules/smqp/dist/src/Exchange.js:76:26)
victor-solvethex commented 3 years ago

My code:

it('should consume messages from a previously created queue', async (done) => {
        const chann = await rabbitService.getChannel()
        chann.consume(
            'cool_queue',
            (msg: any) => {
                expect(msg).toBeTruthy()
                if (msg) expect(msg.content.toString()).toBe('Hello, World')
                                chann.ack(msg)
                done()
            },
            { consumerTag: 'yey' }
        )
    })
victor-solvethex commented 3 years ago

Okey I found the error, I was trying to use ack() on an already acknowledged message. I was using ConfirmChannels instead of normal Channels

paed01 commented 3 years ago

So the issue is solved?