3.0.11 • Published 6 years ago

sbnoti v3.0.11

Weekly downloads
127
License
-
Repository
github
Last release
6 years ago

servicebus-notifications-reader

(or sbnoti because Azure has problems with large path names -__-)

Notifications Reader for Azure Service Bus

Usage:

SbnotiBuilder = require("sbnoti")

reader = new SbnotiBuilder()
.withServiceBus #required
  connectionString: "the azure connection string"
  topic: "the topic name"
  subscription: "the subscription name"
#All settigns below are optional. The values are the defaults.
.withFilters [ 
    { name: "theNameOfTheCustomFilter", expression: "created = True" }
  ]
.withLogging true # or simply .withLogging()
.withConcurrency 25
.withReceiveBatchSize 5
.withWaitForMessageTime 3000
# new health notifiying option:
.withHealth
  redis: 
    host: "host"
    port: 6739
    auth: "cadenaDeAuth"
    db: 2
  app: "la-aplicacion-que-esta-usando-sbnoti"
.build()

To read from the dead letter subscription

reader = new SbnotiBuilder()
.withServiceBus #required
  connectionString: "the azure connection string"
  topic: "the topic name"
  subscription: "the subscription name"
.fromDeadLetter()
.build()

Also read from regular and dead letter at the same time!

reader = new SbnotiBuilder()
.withServiceBus #required
  connectionString: "the azure connection string"
  topic: "the topic name"
  subscription: "the subscription name"
.activeFor
  pending: true #Read from regular subscription
  failed: true  #Read from dead letter
.build()

TIP: Use the booleans for pending and failed to control which readers are active

A nice function to transform strings 'true' and 'false' to actual the boolean value or a default:

stringToBoolean: (value,_default) ->
  (value?.toLowerCase?() ? _default?.toString()) == 'true'

To start the reader with a given process

Promise = require("bluebird")
reader.run (message) =>
  # do something with message
  Promise.resolve "message processed ok"
  # or...
  Promise.reject "error processing the message"

To make an http request for each message

messageToOptions = (message) =>
  uri: "http://an.endpoint.com"
  body: message.data
  headers:
    authorization: "access token"

reader.runAndPost messageToOptions, ignoredStatusCodes: [409,503]
reader.runAndGet messageToOptions
reader.runAndPut messageToOptions
reader.runAndDelete messageToOptions
#or also
method = 'post',  #'get','delete','update'
reader.runAndRequest messageToOptions, method, ignoredStatusCodes: [409]
3.0.11

6 years ago

3.0.10

7 years ago

3.0.9

7 years ago

3.0.8

7 years ago

3.0.7

7 years ago

3.0.6

7 years ago

3.0.5

7 years ago

3.0.4

7 years ago

3.0.3

7 years ago

3.0.2

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.1.3

7 years ago

2.1.2

8 years ago

2.1.1

8 years ago

2.0.2

8 years ago

2.1.0

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.1.0

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago