Skip to content

Commit

Permalink
Return raw message
Browse files Browse the repository at this point in the history
  • Loading branch information
thbkid committed Jan 7, 2021
1 parent f6330bf commit 0e4d93f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions amqp.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ class AMQPWrapper {
* cf http://squaremo.github.io/amqp.node/doc/channel_api.html#toc_34
* @returns {Promise}
*/
async consume (handleMessage, options) {
async consume (handleMessage, _options = {}) {
const { returnRawMessage = false, ...options } = _options;
const { channel } = this;
function callback (message) {
function done (err, requeue) {
Expand All @@ -120,7 +121,11 @@ class AMQPWrapper {
try {
const messagePayload = message.content.toString();
const parsedPayload = JSON.parse(messagePayload);
handleMessage(parsedPayload, done);
if (returnRawMessage) {
handleMessage(parsedPayload, message, done);
} else {
handleMessage(parsedPayload, done);
}
} catch (error) {
console.log(error);
// Do not requeue on exception - it means something unexpected
Expand Down

0 comments on commit 0e4d93f

Please sign in to comment.