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

replyer

v0.2.1

Published

Node.js MQTT client with built-in request and response methods

Downloads

6

Readme

Replyer

Node.js MQTT client with built-in request and response methods

Replyer is a wrapper of MQTT.js client that expands its API with common use cases. It is completely compatible and interoperable, so in most projects you can upgrade by dropping:

var mqtt = require('replyer')

instead of ~~var mqtt = require('mqtt')~~ or ~~socket.io~~.

Hello world

var mqtt = require('replyer')
var client  = mqtt.connect('mqtt://test.mosca.io')

client.on('connect', function () {
  client.publish('chat', 'Hello replyer!')
})

client.on('chat', function (data) {
  console.log(data) // 'Hello replyer!'
  client.end()
})

Request and replyer

var mqtt = require('replyer')
var client  = mqtt.connect('mqtt://test.mosca.io')

client.on('connect', function () {
  console.log('connected')
})

client.request('users', { alias: 'schroedinger' }, function (data) {
  console.log(data) // will be ['schroedinger']
})

client.on('users/#', function (data, topic) {
  console.log(data.alias) // 'schroedinger'
  // find users in database by alias...
  client.reply(topic, { status: '404 Not found' })
})

Replyer scheme

This package is real time communication similar trying to join the best of both socket.io and MQTT.

It implements request and response with a similar API as in socket.io to ease refactor. All clients are listening on their own id path as:

@client-id/message-id

The ‘at’ symbol identifies a message as a MQTT request: it has to be addressed only to that particular client and request. #msg-id is an optional parameter to ensure that a certain reply is for a very particular request. Under some conditions we can count on this (qos > 0). Messages may get lost, for which timeouts are implemented. In case of a series of packets lost before a timeout, a client may interpret a wrong order, thus failing. So this little overhead for request/reply is really useful.

Replyer requests must indicate –somehow– the clientId and the messageId. We have to take into account the the messageId parameter in the packet is not always mandatory (qos 0), so depending in qos for a request we have or have not to append it.

mqtt/api/path + @client-id/message-id

On a request if qos === 2 message id would never be necessary.

MQTT URLs

Now that we can make requests to an API and receive an answer on plain MQTT protocol, we could make use of HTTP URL scheme to indicate resources.

This is the skeleton of a MQTT URL #### mqtt://host:port/path/to/api/call/@issuer/mid as emitter URL

mqtt://host:port/@issuer/mid/ as listener URL

Next steps

  • [ ] Use MqEmitter to better listen for requests
  • [ ] Improve scheme and API
  • [ ] Increase examples and tests
  • Write blog post

The code has tried to follow MQTT best practices as in http://www.hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices