Norse Polytheistic Mythology

    @luxuryescapes/lib-events
    TypeScript icon, indicating that this package has built-in type declarations

    2.1.5 • Public • Published

    lib-events

    SNS messages and SQS queues helper lib

    Publisher

    A small wrapper around SNS

    const { createPublisher } = require('lib-events');
    
    const publisher = createPublisher({
      accessKeyId: process.env.AWS_ACCESS_KEY_ID,
      secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
      region: 'ap-southeast-2',
      topic: 'arn:aws:sns:ap-southeast-2:1234:my-sns-topic',
      apiHost: 'https://our-api.com'
    })

    Dispatch

    const { createPublisher, ORDER_CREATED } = require('lib-events');
    
    const publisher = createPublisher({ ... })
    
    publisher.dispatch({
      type: ORDER_CREATED,
      uri: `/api/orders/${order.id_orders}`,
      checksum: order.checksum,
      source: process.env.HEROKU_APP_NAME,
      message: `${user.fullname} just purchased ${order.offer.name}`
    })

    Publishing to a fifo queue

    const publisher = createPublisher({ ..., topic: 'arn:aws:sns:ap-southeast-2:1234:my-fifo-topic.fifo' })
    
    publisher.dispatch({
      type: ORDER_CREATED,
      uri: `/api/orders/${order.id_orders}`,
      checksum: order.checksum,
      source: process.env.HEROKU_APP_NAME,
      message: `${user.fullname} just purchased ${order.offer.name}`,
      transactionId: '123456', // this is used for deduplication, required for fifo queues
      groupId: '123'// this is used for partitioning, required for fifo queues
    })

    Consumers

    A small wrapper around SQS

    const { createConsumer } = require('lib-events');
    
    const consumer = createConsumer({
      accessKeyId: process.env.AWS_ACCESS_KEY_ID,
      secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
      region: 'ap-southeast-2',
      queueUrl: 'https://sqs.ap-southeast-2.amazonaws.com/1234/my-sqs-name'
    })

    Poll

    const { createConsumer, ORDER_CREATED } = require('lib-events');
    
    const consumer = createConsumer({ ... })
    
    async function processMessage({ type, source, id, checksum }, ack) {
      if (type === ORDER_CREATED) {
        console.log(`${source} created an order!`);
      }
    
      await ack()
    }
    
    exports.process = async function () {
      await consumer.poll(processMessage, {
        maxNumberOfMessages: 10,
        maxIterations: 10
      });
    }

    Running tests

    yarn test
    

    Publishing

    Update the version in package.json as part of your PR and CircleCI will do the rest.

    Keywords

    none

    Install

    npm i @luxuryescapes/lib-events

    DownloadsWeekly Downloads

    80

    Version

    2.1.5

    License

    UNLICENSED

    Unpacked Size

    20.8 kB

    Total Files

    8

    Last publish

    Collaborators

    • aarontoomey-le
    • sergio.costa.luxuryescapes
    • mzilio-lux
    • jeanbiezus
    • francesca-dellanno
    • tiagotraca
    • michael-reid-le
    • matthewdelaneyatluxuryescapes
    • ricardobalbinot
    • luke-chadwick-le
    • maico-dalponte-le
    • callmekev
    • lee-borkman-le
    • semeer-acheerithodi-le
    • roman-yakobnyuk-le
    • krishanii12
    • deepakini
    • sahil-sharma-le
    • andrey-tryapitsin-le
    • quan.tang
    • william-li-le
    • alexander.yakovenko
    • greg-cumming-le
    • anton-fiveiskiy-le
    • jerry.huang-le
    • dan-wanigasekera-le
    • shrabanee.mishra
    • will-cullen-le
    • adriano-luxex
    • stanislav.davydenko
    • viniciusluxury
    • henrique.aron
    • dunedayl
    • arminmon-le
    • roshinlux
    • udarab-le
    • rufus_post_le
    • kanishka-mw
    • mdluxuryescapes
    • mattswansonlux
    • cleberricardi
    • felipefeal.lux
    • mukeshbishnoi
    • tracymu
    • chris.nguyen.lux
    • marhalpert
    • reb2020
    • zediah
    • sonyque
    • joshuacullenlux
    • shawn-cx-li
    • colins44
    • diegogadens
    • felixivanov
    • joshua.paling.le
    • operations.luxgroup
    • sergey.dyachok
    • eddiemcleanlux
    • robert.harris.lux
    • manojlux
    • kostya-luxuryescapes
    • nizhuluxlux
    • eugene.tareev
    • alexb.pi
    • salman971
    • kaustuva
    • guilherme.guimaraes
    • luizcarraro
    • ryan.tian
    • bevhatzl
    • le_tyang
    • richardbiddle
    • henryshen-le
    • sameera.chandrasena.luxuryescapes
    • michael-malarchuk
    • nuwandarshika
    • lasanthalakmal93
    • jamesly
    • mlaiprasert
    • jamesz96
    • jakekingston-le