Skip to content

Commit

Permalink
feat: pass the full message into the consumer as second param
Browse files Browse the repository at this point in the history
  • Loading branch information
beeman authored and Tom Kirkpatrick committed Mar 30, 2017
1 parent 8a0f9e2 commit 6238a74
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/mixins/message-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = function messageQueueMixin(Model, options) {
const RabbitMQ = loopback.getModel('RabbitMQ')

try {
return Model[name](msg.body)
return Model[name](msg.body, msg)
.then(() => {
debug('consumer %s ran successfully for model %s. key: %o',
name, Model.modelName, msg.fields.routingKey)
Expand Down
6 changes: 4 additions & 2 deletions test/mixin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ describe('Mixin', function() {
expect(app.models.Client.consumeNewItems.calledOnce).to.be.true()
})
it('should pass the message body to the consumer', function() {
expect(app.models.Client.consumeAllItems.calledWith('a message')).to.be.true()
expect(app.models.Client.consumeNewItems.calledWith('a message')).to.be.true()
expect(
app.models.Client.consumeAllItems.calledWithMatch('a message', { type: 'item.write.created' })).to.be.true()
expect(
app.models.Client.consumeNewItems.calledWithMatch('a message', { type: 'item.write.created' })).to.be.true()
})
})
})

0 comments on commit 6238a74

Please sign in to comment.