freddy
Simple messaging API supporting acknowledgements and request-response
Last updated 7 months ago by urmas .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install freddy 
SYNC missed versions from official npm registry.

Messaging API supporting acknowledgements and request-response

Build Status

Setup

Inject the appropriate logger and set up connection parameters:

Freddy = require 'freddy'
Freddy.addErrorListener(listener)
Freddy.connect('amqp://guest:guest@localhost:5672', {logger}).done (freddy) ->
  continueWith(freddy)
, (error) ->
  doSthWithError(error)

TLS connection

See http://www.squaremobius.net/amqp.node/ssl.html for available options.

sslOptions = {
  cert: fs.readFileSync('clientcert.pem'),
  key: fs.readFileSync('clientkey.pem'),
  ca: [fs.readFileSync('cacert.pem')]
}

Freddy.connect('amqps://localhost:5671', {logger, ...sslOptions}).done (freddy) ->
  continueWith(freddy)
, (error) ->
  doSthWithError(error)

Supported message queues

These message queues have been tested and are working with Freddy. Other queues can be added easily:

Delivering messages

Simple delivery

Send and forget

Sends a message to the given destination. If there is no consumer then the message stays in the queue until somebody consumes it.

  freddy.deliver destination, message

Expiring messages

Sends a message to the given destination. If nobody consumes the message in timeout seconds then the message is discarded. This is useful for showing notifications that must happen in a certain timeframe but where we don't really care if it reached the destination or not.

freddy.deliver destination, message, timeout: 5

Request delivery

Expiring messages

Sends a message to the given destination. Has a default timeout of 3 and discards the message from the queue if a response hasn't been returned in that time.

freddy.deliver destination, message, (response) ->
  # ...
, (error) ->
  # ...

Persistant messages

Sends a message to the given destination. Keeps the message in the queue if a timeout occurs.

freddy.deliver destination, message, timeout: 4, deleteOnTimeout: false, (response) ->
  # ...
, (error) ->
  # ...

Responding to messages

freddy.respondTo destination, (message, handler) ->
  if true
    handler.success(id: 5)
  else
    handler.error(error: 'something went wrong')
.done (responderHandler) ->
  doSthWith(responderHandler)

Tapping into messages

When it's necessary to receive messages but not consume them, consider tapping.

responderHandler = freddy.tapInto(pattern, callback)
  • destination refers to the destination that the message was sent to
  • Note that it is not possible to respond to the message while tapping.
  • When tapping the following wildcards are supported in the pattern :
    • # matching 0 or more words
    • * matching exactly one word

Examples:

freddy.tapInto "i.#.free", (message, handler) ->
  # ...

receives messages that are delivered to "i.want.to.break.free"

freddy.tapInto "somebody.*.love", (message, handler) ->
  # ...

receives messages that are delivered to somebody.to.love but doesn't receive messages delivered to someboy.not.to.love

Credits

freddy was originally written by Urmas Talimaa as part of SaleMove development team.

SaleMove Inc. 2012

freddy is maintained and funded by SaleMove, Inc.

The names and logos for SaleMove are trademarks of SaleMove, Inc.

Current Tags

  • 0.4.0                                ...           latest (7 months ago)

33 Versions

  • 0.4.0                                ...           7 months ago
  • 0.3.5                                ...           4 years ago
  • 0.3.4                                ...           4 years ago
  • 0.3.3                                ...           5 years ago
  • 0.3.2                                ...           5 years ago
  • 0.3.1                                ...           5 years ago
  • 0.3.0                                ...           5 years ago
  • 0.2.11                                ...           5 years ago
  • 0.2.10                                ...           6 years ago
  • 0.2.9                                ...           6 years ago
  • 0.2.8                                ...           6 years ago
  • 0.2.7                                ...           6 years ago
  • 0.2.6                                ...           6 years ago
  • 0.2.5                                ...           6 years ago
  • 0.2.2                                ...           6 years ago
  • 0.2.1                                ...           6 years ago
  • 0.1.0                                ...           6 years ago
  • 0.0.18                                ...           6 years ago
  • 0.0.17                                ...           6 years ago
  • 0.0.16                                ...           6 years ago
  • 0.0.15                                ...           6 years ago
  • 0.0.14                                ...           6 years ago
  • 0.0.12                                ...           6 years ago
  • 0.0.10                                ...           6 years ago
  • 0.0.9                                ...           6 years ago
  • 0.0.8                                ...           6 years ago
  • 0.0.6                                ...           6 years ago
  • 0.0.5                                ...           6 years ago
  • 0.0.4                                ...           6 years ago
  • 0.0.3                                ...           6 years ago
  • 0.0.2                                ...           6 years ago
  • 0.0.1                                ...           6 years ago
  • 0.0.0                                ...           6 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (6)
Dev Dependencies (6)
Dependents (2)

Copyright 2014 - 2016 © taobao.org |