This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

ya-pubsub

0.2.5 • Public • Published

Ya PubSub is a topic-based publish/subscribe library for Node js.

Works well with ya-rfc.

Key Features

  • asynchronous
  • embeddable
  • designed for micro-services

Basic Example

PubSub over tcp:

const net = require('net')
const ya = require('../index.js')

const broker = ya.broker()
broker.plug(ya.plugins.net(net.Server().listen(8000)))

const client1 = ya.client.net({ host: 'localhost', port: 8000 })

client1.publish('some-topic', { hello: 'world1' })

const client2 = ya.client.net({ host: 'localhost', port: 8000 })
client2.subscribe('some-topic', (message) => {
  console.log(message)
})

client1.publish('some-topic', { hello: 'world2' })

/* output:
{ hello: 'world1' }
{ hello: 'world2' }
*/

PubSub over websockets

const { WebSocketServer } = require('ws')
const ya = require('../index.js')

const broker = ya.broker()
broker.plug(ya.plugins.ws(new WebSocketServer({ port: 8001 })))
broker.publish('some-topic', 'hello')

const client1 = ya.client.ws({ host: 'localhost', port: 8001 })
const client2 = ya.client.ws({ host: 'localhost', port: 8001 })

client2.publish('some-topic', { hello: 'world1' })

client2.subscribe('some-topic', (message) => {
  console.log(message)
})

setTimeout(() => {
  client1.publish('some-topic', { hello: 'world2' })
}, 50)

/* output:
hello
{ hello: 'world1' }
{ hello: 'world2' }
*/

PubSub locally (same process)

const pubsub = require('../index.js')

const broker = pubsub.broker()

broker.publish('some-topic', 'hello')

broker.subscribe('some-topic', (message) => {
  console.log('received from first subscriber', message)
})

broker.subscribe('some-topic', (message) => {
  console.log('received from second subscriber', message)
})

setTimeout(() => {
  broker.publish('some-topic', { hello: 'world2' })
}, 50)

/* output:
received from first subscriber hello
received from second subscriber hello
received from first subscriber { hello: 'world2' }
received from second subscriber { hello: 'world2' }
*/

Topic Filtering

Versioning

Yaps-node uses Semantic Versioning for predictable versioning.

Alternatives

These are a few alternative projects that also implement topic based publish subscribe in JavaScript.

/ya-pubsub/

    Package Sidebar

    Install

    npm i ya-pubsub

    Weekly Downloads

    0

    Version

    0.2.5

    License

    MIT

    Unpacked Size

    21.2 kB

    Total Files

    12

    Last publish

    Collaborators

    • nicocoul