All Projects → ostdotcom → notification

ostdotcom / notification

Licence: LGPL-3.0 license
OST Notification helps publish critical events for cross platform communications

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to notification

base
OST Base provides advanced Promise Queue Manager and other utilities.
Stars: ✭ 19 (-5%)
Mutual labels:  ost, openst
Mitt
🥊 Tiny 200 byte functional event emitter / pubsub.
Stars: ✭ 6,945 (+34625%)
Mutual labels:  pubsub, eventemitter
dead-simple
💀💡 Dead simple PubSub and EventEmitter in JavaScript
Stars: ✭ 21 (+5%)
Mutual labels:  pubsub, eventemitter
trainmanjs
TrainmanJS - Cross-Origin Communication Library
Stars: ✭ 16 (-20%)
Mutual labels:  eventemitter
twitch api2
Rust library for talking with the Twitch API aka. "Helix", TMI and more! Use Twitch endpoints fearlessly!
Stars: ✭ 91 (+355%)
Mutual labels:  pubsub
uorb
C++ inter-thread publish/subscribe middleware ported from PX4 and redesigned based on POSIX
Stars: ✭ 35 (+75%)
Mutual labels:  pubsub
ost-wallet-sdk-android
OST Platform Wallet SDK for Android
Stars: ✭ 15 (-25%)
Mutual labels:  ost
windowed-observable
Messaging lib using a pub/sub observable scoped by namespaces.
Stars: ✭ 132 (+560%)
Mutual labels:  pubsub
portara-website
Portara dashboard controller to change rate limit settings without redeploying your app
Stars: ✭ 42 (+110%)
Mutual labels:  pubsub
twurple
Interact with Twitch's API, chat and subscribe to events via PubSub and EventSub.
Stars: ✭ 479 (+2295%)
Mutual labels:  pubsub
gobroker
golang wrapper for all (to-be) kinds of message brokers
Stars: ✭ 15 (-25%)
Mutual labels:  pubsub
lila-ws
Lichess' websocket server
Stars: ✭ 99 (+395%)
Mutual labels:  pubsub
webfunc
Universal Serverless Web Framework. Write Express apps ready to be deployed to Zeit-Now, Google Cloud Functions (incl. functions reacting to Pub/Sub topics or Storage changes), and AWS Lambdas.
Stars: ✭ 71 (+255%)
Mutual labels:  pubsub
pulsar-io-kafka
Pulsar IO Kafka Connector
Stars: ✭ 24 (+20%)
Mutual labels:  pubsub
ipfs-pubsub-chatroom
Simple IPFS Pubsub chatroom built on React
Stars: ✭ 45 (+125%)
Mutual labels:  pubsub
network-monorepo
Monorepo containing all the main components of Streamr Network.
Stars: ✭ 223 (+1015%)
Mutual labels:  pubsub
tips
TiKV based Pub/Sub server
Stars: ✭ 31 (+55%)
Mutual labels:  pubsub
angular-PubSub
Angular 1.x implementation of the Publish–Subscribe pattern.
Stars: ✭ 32 (+60%)
Mutual labels:  pubsub
fastapi websocket pubsub
A fast and durable Pub/Sub channel over Websockets. FastAPI + WebSockets + PubSub == ⚡ 💪 ❤️
Stars: ✭ 255 (+1175%)
Mutual labels:  pubsub
smartacus-mqtt-broker
smartacus-mqtt-broker is a Java-based open source MQTT broker that fully supports MQTT 3.x .Using Netty 4.1.37
Stars: ✭ 25 (+25%)
Mutual labels:  pubsub

Notification

Latest version Build Status Downloads per month

OST Notification helps publish critical events using EventEmitter and RabbmitMQ. All events get published using node EventEmitter and, if configured, events are also published through RabbitMQ, using topic-based exchange.

Install

npm install @ostdotcom/notification --save

Examples:

Subscribe to events published through RabbitMQ:

  • Basic example on how to listen a specific event. Arguments passed are:
    • Events [Array] (mandatory) - List of events to subscribe to
    • Options [object] (mandatory) -
      • queue [string] (optional) - Name of the queue on which you want to receive all your subscribed events. These queues and events, published in them, have TTL of 6 days. If a queue name is not passed, a queue with a unique name is created and is deleted when the subscriber gets disconnected.
      • ackRequired [number] - (optional) - The delivered message needs ack if passed 1 ( default 0 ). if 1 passed and ack not done, message will redeliver.
      • prefetch [number] (optional) - The number of messages released from queue in parallel. In case of ackRequired=1, queue will pause unless delivered messages are acknowledged.
    • Callback [function] (mandatory) - Callback method will be invoked whenever there is a new notification
// Config Strategy for OST Notification.
configStrategy = {
	"rabbitmq": {
        "username": "guest",
        "password": "guest",
        "host": "127.0.0.1",
        "port": "5672",
        "heartbeats": "30"
    }
};
// Import the notification module.
const OSTNotification = require('@ostdotcom/notification');
let unAckCount = 0; //Number of unacknowledged messages.

const subscribe = async function() {
  let ostNotificationInstance = await OSTNotification.getInstance(configStrategy);
  ostNotificationInstance.subscribeEvent.rabbit(
    ["event.ProposedBrandedToken"],
    {
      queue: 'myQueue',
      ackRequired: 1, // When set to 1, all delivered messages MUST get acknowledge.
      broadcastSubscription: 1, // When set to 1, it will subscribe to broadcast channel and receive all broadcasted messages. 
      prefetch:10
    }, 
    function(msgContent){
      // Please make sure to return promise in callback function. 
      // On resolving the promise, the message will get acknowledged.
      // On rejecting the promise, the message will be re-queued (noAck)
      return new Promise(async function(onResolve, onReject) {
        // Incrementing unacknowledged message count.
        unAckCount++;
        console.log('Consumed message -> ', msgContent);
        response = await processMessage(msgContent);
        
        // Complete the task and in the end of all tasks done
        if(response == success){
          // The message MUST be acknowledged here.
          // To acknowledge the message, call onResolve
          // Decrementing unacknowledged message count.
          unAckCount--;
          onResolve();   
        } else {
          //in case of failure to requeue same message.
          onReject();
        }
       
      })
    
    });
};
// Gracefully handle SIGINT, SIGTERM signals.
// Once SIGINT/SIGTERM signal is received, programme will stop consuming new messages. 
// But, the current process MUST handle unacknowledged queued messages.
process.on('SIGINT', function () {
  console.log('Received SIGINT, checking unAckCount.');
  const f = function(){
    if (unAckCount === 0) {
      process.exit(1);
    } else {
      console.log('waiting for open tasks to be done.');
      setTimeout(f, 1000);
    }
  };
  setTimeout(f, 1000);
});

function ostRmqError(err) {
  logger.info('ostRmqError occured.', err);
  process.emit('SIGINT');
}
// Event published from package in case of internal error.
process.on('ost_rmq_error', ostRmqError);
subscribe();
  • Example on how to listen to multiple events with one subscriber.
// Config Strategy for OST Notification.
configStrategy = {
	"rabbitmq": {
        "username": "guest",
        "password": "guest",
        "host": "127.0.0.1",
        "port": "5672",
        "heartbeats": "30"
    }
};
// Import the notification module.
const OSTNotification = require('@ostdotcom/notification');
const subscribeMultiple = async function() {
  let ostNotificationInstance = await OSTNotification.getInstance(configStrategy);
  ostNotificationInstance.subscribeEvent.rabbit(
    ["event.ProposedBrandedToken", "obBoarding.registerBrandedToken"],
    {}, 
    function(msgContent){
      console.log('Consumed message -> ', msgContent)
    });
  };
subscribeMultiple();

Subscribe to local events published through EventEmitter:

  • Basic example on how to listen a specific event. Arguments passed are:
    • Events (mandatory) - List of events to subscribe to
    • Callback (mandatory) - Callback method will be invoked whenever there is a new notification
// Config Strategy for OST Notification.
configStrategy = {
	"rabbitmq": {
        "username": "guest",
        "password": "guest",
        "host": "127.0.0.1",
        "port": "5672",
        "heartbeats": "30"
    }
};
// Import the notification module.
const OSTNotification = require('@ostdotcom/notification');
const subscribeLocal = async function() {
  let ostNotificationInstance = await OSTNotification.getInstance(configStrategy);
  ostNotificationInstance.subscribeEvent.local(["event.ProposedBrandedToken"], 
  function(msgContent){
    console.log('Consumed message -> ', msgContent)
  });
  };
subscribeLocal();

Publish Notifications:

  • All events are by default published using EventEmitter and if configured, through RabbmitMQ as well.
// Config Strategy for OST Notification.
configStrategy = {
	"rabbitmq": {
        "username": "guest",
        "password": "guest",
        "host": "127.0.0.1",
        "port": "5672",
        "heartbeats": "30"
    }
};
// Import the notification module.
const OSTNotification = require('@ostdotcom/notification');
const publish = async function() {
  let ostNotificationInstance = await OSTNotification.getInstance(configStrategy);
  ostNotificationInstance.publishEvent.perform(
    {
      topics:["event.ProposedBrandedToken"],
      broadcast: 1, // When set to 1 message will be broadcasted to all channels. 'topics' parameter should not be sent.
      publishAfter: 1000, // message to be sent after milliseconds.
      publisher: 'MyPublisher',
      message: {
  	  kind: "event_received",
  	  payload: {
  		event_name: 'ProposedBrandedToken',
  		params: {
  		  //params of the event
  		},
          contract_address: 'contract address',
          chain_id: 'Chain id',
          chain_kind: 'kind of the chain'
  	  }
  	}
    });
};
publish();

Pause and Restart queue consumption:

  • We also support pause and start queue consumption. According to your logical condition, you can fire below events from your process to cancel or restart consumption respectively.
// Config Strategy for OST Notification.
let configStrategy = {
	"rabbitmq": {
        "username": "guest",
        "password": "guest",
        "host": "127.0.0.1",
        "port": "5672",
        "heartbeats": "30"
    }
};
let queueConsumerTag = null;
// Import the notification module.
const OSTNotification = require('@ostdotcom/notification');
const subscribePauseRestartConsume = async function() {
  let ostNotificationInstance = await OSTNotification.getInstance(configStrategy);
  ostNotificationInstance.subscribeEvent.rabbit(
    ["event.ProposedBrandedToken", "obBoarding.registerBrandedToken"],
    {}, 
    function(msgContent){
      console.log('Consumed message -> ', msgContent);
      
      if(some_failure_condition){
        process.emit('CANCEL_CONSUME', queueConsumerTag);
      }
      
      if(failure_resolve_detected){
        process.emit('RESUME_CONSUME', queueConsumerTag);
      }
    },
    function(consumerTag) {
      queueConsumerTag = consumerTag;
    }
    );
  };
subscribePauseRestartConsume();
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].