npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

seneca-amqp-transport-alt

v0.2.0

Published

This is a re-implementation of the official amqp transport for seneca

Downloads

4

Readme

Seneca

seneca-amqp-transport-alt

This is a re-implementation of the official amqp transport for seneca. It supports a few different things:

  • reconnecting / re-establishing connections upon failure
  • model: observe via fanout exchanges
  • return messages if no listeners defined

install

npm i seneca-amqp-transport-alt

usage

You can use this plugin by loading it into seneca via use The second parameter to use are configuration options. See options below.

Then adding clients and listeners to the seneca instance. The default model is consume, but observe (via fanout) is also supported.

The pin or pins object must match identically between the respective client and listen calls.

options / defaults

const Transport = require('seneca-amqp-transport-alt')

const opts = {

  // will wait this long before reconnecting if connection is lost
  // will connect in a setInterval callback until connection re-established.
  // if not provided, will not reconnect.
  reconnectInterval: 5000,

  // if true, calls `seneca.die` upon connection loss instead of attempting to reconnect
  die: false,

  // if provided, passed to the consume channel of the actor
  prefetch: 1,

  // all options are provided as first parameter to amqp.connect
  // this includes the following defaults

  protocol: 'amqp',
  hostname: 'localhost',
  port: 5672,
  username: 'guest',
  password: 'guest',
  locale: 'en_US',
  frameMax: 0,
  heartbeat: 0,
  vhost: '/',

  // if provided, this url will be passed as the first param instead
  url = null,

  // if provided, will be passed as second parameter to amqplib.connect
  socketOpts = {

  },

}

rpc (consume)

const server = Seneca()
server.use(Transport, opts)
server.listen({ type: 'amqp', pin: 'role:test,cmd:echo' })
server.add({ role: test, cmd: echo }, (msg, cb) => cb(null, msg))
await new Promise(resolve => server.ready(resolve))

const client = Seneca()
client.use(Transport, opts)
client.client({ type: 'amqp', pin: 'role:test,cmd:echo' })
await new Promise(resolve => client.ready(resolve))
const res = client.act('role:test,cmd:echo', { ok: true }, msg =>
  assert(msg.ok)
)

pubsub (observe)

const server1 = Seneca()
server1.use(Transport, opts)
server1.listen({ type: 'amqp', model: 'observe', pin: 'role:cache,cmd:clear' })
server1.add('role:cache,cmd:clear', (msg, cb) => cb(null, msg))
await new Promise(resolve => server1.ready(resolve))

const server2 = Seneca()
server2.use(Transport, opts)
server2.listen({ type: 'amqp', model: 'observe', pin: 'role:cache,cmd:clear' })
server2.add('role:cache,cmd:clear', (msg, cb) => cb(null, msg))
await new Promise(resolve => server2.ready(resolve))

const client = Seneca()
client.use(Transport, opts)
client.client({ type: 'amqp', model: 'observe', pin: 'role:cache,cmd:clear' })
await new Promise(resolve => client.ready(resolve))

const res = client.act('role:cache,cmd:clear', (err, msg) => {
  // note - you won't get back any meaningul message here, it is always set to {ok: true}
  // you will get errors though if there's a problem publishing to the fanout exchange
  assert(msg.ok)
})

amqp notes / how it works

consume

  • A queue name is derived from the pin (typically prefix with seneca_, delimit kv pairs by _)
  • For listen - the derived queueName is asserted as an autoDelete queue with the defined prefetch in the options. We consume the queue and send replies back to the replyTo property.
  • For client - an exclusive/delete queue is created. messages are sent to the derived queueName with a replyTo on this queue. Any returns are returned to the client as unrouted errors

observe

  • an exchange name is derived from the pin (typically prefix with seneca_, delimit kv pairs by _)
  • For listen - the derived exchange name is asserted as autoDelete, a new queue is created and bound to the exchange. We consume this new queue and call the seneca action.
  • For client - each of the derived exchange names is asserted as autoDelete. Acting into the pin will publish the defined message to the exchange.

License

MIT