examples/src/example-amqp-consumer.js
// And finally, we can set up, let's create a main method to hold our logic...
And finally, we can set up, let's create a main method to hold our logic
And finally we can set up let ' s create a main method to hold our logic
async function main() {
  await amqpCacoon.getConsumerChannel();
  await amqpCacoon.registerConsumer(
    amqpConfig.exampleQueue,
    async (channelWrapper, msg) => {
      try {
        logger.info(`Message content: ${msg.content.toString()}`);
        channelWrapper.ack(msg); 
      } catch (e) {
        channelWrapper.nack(msg); 
      }
    }
  );
}
async function main ( ) { await amqpCacoon . getConsumerChannel ( ) ; await amqpCacoon . registerConsumer ( amqpConfig . exampleQueue , async ( channelWrapper , msg ) => { try { logger . info ( ` ${ msg . content . toString ( ) } ` ) ; channelWrapper . ack ( msg ) ; } catch ( e ) { channelWrapper . nack ( msg ) ; } } ) ; }
And finally, we can set up, let's create a main method to hold our logic...
And finally we can set up let ' s create a main method to hold our logic ...
// Connects and sets up a subscription channelWrapper // Register a consumer to consume single message at a time // ... Do other processing here // To ack a messages // Some error happened in our handling of the message. // The bet practice is to NACK the message so that some other process retries! // To nack a messages we could not handle (by default, will requeue)