项目作者: ProdioDesignWorks

项目描述 :
Simple Wrapper to communicate with Google Pub/Sub
高级语言: JavaScript
项目地址: git://github.com/ProdioDesignWorks/EventBus.git
创建时间: 2019-02-14T11:37:39Z
项目社区:https://github.com/ProdioDesignWorks/EventBus

开源协议:MIT License

下载


EventBus

License: MIT

EventBus is a nodejs wrapper to communicate with Google Pub/Sub.

  • Simple API’s to publish and subscribe,
  • etc.

New Features!

  • You can publish message to any topic
  • Subscribe to any subscription ( For now, limited to only single subscription )

You can also:

  • Check subscription status
  • Unsubscribe with a single API
  • Create multiple instances of event bus

Goal

Expose simple API’s for communication with Google Pub/Sub

Prerequisites

Installation

EventBus-Prodio requires Node.js v6+ to run.

Install the dependencies and devDependencies and start the server.

  1. $ git clone https://github.com/ProdioDesignWorks/EventBus.git
  2. $ cd EventBus
  3. $ npm install

For production environments…

  1. $ npm install EventBus-Prodio --save

Plugins

EventBus-Prodio is extended with the following plugins. Instructions on how to use them in your own application are linked below.

Plugin README
Google PubSub PubSub GitHub

How to use

  1. const EventBus = require('EventBus-Prodio');
  2. // google config file
  3. const Bus = new EventBus({
  4. projectId: 'projectId',
  5. keyFilename: 'projectId-keyFile.json'
  6. });

For Subscribing to a subscription

  1. const subscriptionName = "subscriptionName";
  2. const autoAck = true;
  3. //If autoAck is set, then message's are auto acknowledged as soon as message is received
  4. //If autoAck is not set, then subscriber has to explicitly acknowledge the message
  5. const onMessage = (message) => console.log(message);
  6. Bus.subscribe({ subscriptionName, autoAck }, onMessage);

For Publishing message on topic

  1. const topicName = "topicName";
  2. const message = "User registered";
  3. const customAttributes = {
  4. serviceId: 'REGISTRATION-SERVICE',
  5. user: {
  6. name: 'John Doe',
  7. email: 'johndoe@example.com'
  8. }
  9. };
  10. //async await
  11. const messageId = await Bus.publish(topicName, msg, customAttributes);
  12. //promise
  13. Bus.publish(topicName, msg, customAttributes).then(
  14. messageId => console.log(messageId)
  15. ).catch(
  16. error => console.error(error)
  17. );

Please refer examples for more details

Development

Want to contribute? Great!

EventBus-Prodio uses Babel + Eslint for fast developing.
Make a change in your file and instantanously see your updates!

Open your favorite Terminal and run these commands.

Todos

  • Write MORE Tests
  • Add multiple subscriptions support
  • Create Topic & Subscription API’s
  • Ordered events

License

MIT

Free Software, Hell Yeah!