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

ng2-simple-mq

v11.2.9

Published

Angular 2 simple message queue for inter-component communication

Downloads

59

Readme

A message queue service for Angular inter-component communication base on RxJS.

Name/ID(string) base API. RxJS object not exposed.

(This package does not communicate with RabbitMQ or any other message queue software/service.)

ng2-simple-mq uses Angular CLI starting 8.2.0. New repository github.com/J-Siu/ng2-simple-mq-lib contains both library and example.

Version < 8.2.0 are in old repository github.com/J-Siu/ng2-simple-mq

Install

npm install ng2-simple-mq

Usage

ng2-simple-mq is implemented as Angular 2 injectable service name SimpleMQ.

Module

Add SimpleMQ into module providers (eg. app.module.ts.

import { SimpleMQ } from 'ng2-simple-mq';

@NgModule({
  providers: [SimpleMQ]
})

Component

import { SimpleMQ } from 'ng2-simple-mq';

export class ChildComponent {

  constructor(private smq: SimpleMQ) { }

}

API

newQueue(name: string): boolean

newQueue will create queue name.

Return false if queue name exist.

this.smq.newQueue('broadcast');

delQueue(name: string): boolean

delQueue will delete queue name.

Return false if queue name does not exist.

this.smq.delQueue('broadcast');

getQueue(): string[]

getQueue will return all queue name in string array.

let q: string[] = this.smq.getQueue();

getSubscription(): string[]

getSubscription will return all subscription id in string array.

let ids: string[] = this.st.getSubscription();

publish(name: string, msg: any, lazy = true): boolean

publish will put msg into queue name.

If lazy = true(default), queue name will be created automatically if not exist yet.

Return true if successful.

Return false if any of following is true:

  • lazy = false, and queue name does not exist.
  • name is undefined.
  • msg is undefined.
// lazy mode
message = 'This is a broadcast message';
this.smq.publish('broadcast',message);

subscribe(name: string, callback: (any) => void, lazy = true): string

subscribe will link callback function to queue name. Whenever queue name receive a new message, callback will be invoked.

If lazy = true(default), queue name will be created automatically if not exist yet.

Return subscription id if successful.

Return empty string if any of following is true:

  • lazy = false, and queue name does not exist.
  • name is undefined.
  • callback is undefined.

Either use Lambda(fat arrow) in typescript to pass in callback or bind this to another variable in javascript, else this scope will be lost.

Lambda(fat arrow)

broadcastMsg;

ngOnInit() {
  // lazy mode
  this.smq.subscribe('broadcast', e => this.receiveBroadcast(e));
}

receiveBroadcast(m) {
  this.broadcastMsg = m;
}

unsubscribe(id: string): boolean

unsubscribe will cancel subscription using id.

unsubscribe will return false if id is undefined or id is not found in subscription list.

id: string;

this.st.unsubscribe(this.id);

Example

You will need Angular CLI to build the library and run the example.

git clone https://github.com/J-Siu/ng2-simple-mq-lib.git
cd ng2-simple-mq-lib
npm i
ng build ng2-simple-mq
ng serve --open

Repository

Contributors

Changelog

  • 0.1.0-alpha - Initial
  • 0.1.1-alpha - Add Readme.md
  • 0.1.2-alpha - Readme.md fix
  • 0.1.3-alpha - Fix components.js
  • 0.2.0
    • Complete Readme.md
    • Fix index.js and index.d.ts
  • 0.2.1
    • API change
    • newQueue return boolean
    • API new
    • delQueue
    • getSubscription
    • unsubscribe
  • 0.2.2
    • Support Angular2 RC5
  • 0.2.3
    • Fix Readme.md
  • 1.2.4
    • Support Angular2 ^2.0.0
    • Clean up package
  • 1.2.5
    • Add Plunker example
  • 1.2.6
    • Support Angular2 ^2.4.1
    • Replace node-uuid with angular2-uuid
    • Add instruction for "noImplicitAny": false *- 1.2.7
    • Due to the rapid release cycle of Angular, to minimize update purely due to peerDependencies, it is modified as follow: "peerDependencies": { "@angular/core": ">2.4.1" }
  • 1.2.8
    • Update to support Angular 4.3.1. Please use previous version for Angular 2.x.x.
  • 1.2.9
    • Fix issue#2 delQueue
  • 8.2.0
    • Support Angular 8.2.0
    • Switch to Angular Cli for faster update
    • Include example
  • 8.2.1
    • README.md clean up
  • 9.1.0
    • Support Angular 9.1.0
  • 11.2.9
    • Support Angular 11.2.9

License

The MIT License

Copyright (c) 2021

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.