Giter Club home page Giter Club logo

redis-messaging-manager-examples's Introduction

redis-messaging-manager-examples

Examples for using redis-mesagging-manager library.

Installation

Clone the repository, and run npm install

git clone https://github.com/tomyitav/redis-messaging-manager-examples.git
npm install
tsc

Basic setup

Make sure a redis broker instance is up on localhost. You can configure a different ip address in messenger.ts file

Creating PubsubManager instance

  import {PubsubManager} from 'redis-messaging-manager';

  let messenger = new PubsubManager({
      host: 'localhost'
  });
  export default messenger;

receiver demo

The following code snippet shows how to subscribe to a topic, (or channel) named "redis"

  import messenger from "../messenger";

  console.log('consuming messages..!');
  messenger.consume('redis')
      .subscribe(msg => {
          console.log('Got message- ', msg);
      });

Run command:

node dist\basic-pubsub\receiver.js

Running publisher

This is how we publish a message on the channel "redis":

import messenger from '../messenger';

messenger.publish('redis', 'Hello redis messenger!');

Run command:

node dist\basic-pubsub\publisher.js

And the message will now be published to the receiver.

Publishing a bulk of messages

Publishing multiple messages on a channel is supported in redis-messaging-manager by using publishBulk. This is implemented by using Redis Pipeline functionality to boost performance.

import messenger from '../messenger';

let bulkOfMessages: Array<string> = [
    "hello redis 1",
    "hello redis 2",
    "hello redis 3",
    "hello redis 4",
    "hello redis 5"
]

messenger.publishBulk('redis', bulkOfMessages);

Run command:

node dist\basic-pubsub\publish-bulk.js

Now all 5 Messages from the publisher will appear in the receiver console.

Subscribe to server events

By using the getServerEventStream method, we get an Observable that acts as a stream of events from the Redis server instance.

import messenger from '../messenger';

messenger.getServerEventStream('error')
    .subscribe(() => {
        console.log('Got error event');
    })

Run command:

node dist\events\event-listener.js

redis-messaging-manager-examples's People

Contributors

tomyitav avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.