Monday, October 22, 2018

Angular Message Queue for Asynchronous Processing (ngx-message-queue)

ngx-message-queue

A message queue library for Angular 2+ application components to communication each other. ngx-message-queue library supports message headers and message payload. It also supports message selectors for subscribers to subscribe to only messages with specific message header via msgSelector.
Selectors are a way of attaching a filter to a subscription to perform content based routing. Selectors are typically apply to message headers, If no headers are attached to the message then all the messages will be delivered to subscriber by default. If subscriber is not configuring the msgSelector then all the messages will be delivered to the subscribers i.e. no filters are applied.
Multiple conditions are allowed in the msgSelector.

ngx-message-queue was previously knowns as ng2-message-queue.
Example of a message selectors
LogLevel=fatal

age > 13

age>=13 & gender=M

Filter expression can be grouped using parenthesis

age<=5 & ((gender=M & state=NJ) | gender=F)
Supported Operators
=, !=, >, <, >=, <=, &, |
Message header supports only JSON object. Multiple header properties can be posted with single JSON object
{
"id": "1234567890",
"age": "20"
}

Message payload can be of any type (string, integer, object, JSON etc)

Index

Install

npm install ngx-message-queue

Usage

Import into Angular 2+ application (typescript)

ngx-message-queue is implemented as Angular 2+ injectable service name NgxMessageQueue.
For apps using angular version 6+
NgxMessageQueue is Injectable as root so no additional decalaration is required in any module.
For apps using angular version prior to 6
Add NgxMessageQueue into module providers.
import { NgxMessageQueue } from 'ngx-message-queue';

@NgModule({
 providers: [NgxMessageQueue]
})
Each component to use NgxMessageQueue
import { NgxMessageQueue } from 'ngx-message-queue';

export class MyComponent {

 constructor(private messageQueue: NgxMessageQueue) { }

}

API

createQueue(name: string): boolean
createQueue will create queue name.
Return false if queue name exist.
this.messageQueue.createQueue('myQueue');
deleteQueue(name: string): boolean
deleteQueue will delete queue name.
Return false if queue name does not exist.
this.messageQueue.deleteQueue('myQueue');
getQueueNames(): string[]
getQueueNames will return all queue name in string array.
let qNames: string[] = this.messageQueue.getQueueNames();
getSubscribers(): string[]
getSubscribers will return all subscribers id in string array.
let ids: string[] = this.messageQueue.getSubscribers();
publish(name: string, headers: any, message: any, lazy = true): boolean
publish will put message into queue name. It will also put headers into queue if any. headers are optional but it is best way to process/route/filter the messages quickly without parsing the message payload.
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.
  • message is undefined.
// lazy mode
message = 'This is a test message';
this.mq.publish('myQueue', {}, message);
subscribe(name: string, msgSelector: string, callback: (any, any) => void, lazy = true): string
subscribe will subscribe for the message posted on the queue name. Whenever queue name receives a new message, callback will be invoked. The callback will return both headers and message payload.
Subscribers can subscribe to only certain messages within the same queue. Let us say you have multiple subscribers listening for log messages with different logging level (debug, info, warn, fatal etc). If you want to configure high priority subscriber who listens for logs with 'fatal' level then use msgSelector as loglevel=fatal
this.mq.subscribe('myQueue', 'loglevel=fatal', (headers, message) => this.handleMessage(headers, message));
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)
ngOnInit() {
 this.mq.subscribe('testqueue', '', (headers, message) => this.handleMessage(headers, message));
}

handleMessage(headers, message) {
 console.log(message);
}
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.messageQueue.unsubscribe(this.id);

Example

77 comments:

  1. This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to article very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
    DedicatedHosting4u.com

    ReplyDelete
  2. I appreciate your efforts because it conveys the message of what you are trying to say. It's a great skill to make even the person who doesn't know about the subject could able to understand the subject . Your blogs are understandable and also elaborately described. I hope to read more and more interesting articles from your blog. All the best.
    Software testing online training
    Software testing certification training
    Software testing online course
    Software testing training course

    ReplyDelete
  3. I just got to this amazing site not long ago. I was actually captured with the piece of resources you have got here. Big thumbs up for making such wonderful blog page!
    data science course in mumbai

    ReplyDelete
  4. Impressive! I finally found great post here. Nice article on data science . It's really a nice experience to read your post. Thanks for sharing your innovative ideas to our vision.
    Data Science Course
    Data Science Course in Marathahalli

    ReplyDelete
  5. Wow! This article is jam-packed full of useful information. The points made here are clear, concise, readable and poignant. I honestly like your writing style.
    SAP training in Kolkata
    Best SAP training in Kolkata
    SAP training institute in Kolkata

    ReplyDelete
  6. I am incessantly thought about this, thanks for putting up. website design company nyc

    ReplyDelete
  7. Found your weblog and decided to have a study on it, not what I usually do, but this blog is wonderful. Awesome to see a site that’s not spammed, and actually makes some sense. Anyway, great write up. web design manhattan

    ReplyDelete
  8. very nice post, i actually love this web site, keep on it branding agencies in san francisco

    ReplyDelete
  9. Great post, you have pointed out some fantastic details , I besides believe this s a very great website. branding firms san francisco

    ReplyDelete
  10. Truly, this article is really one of the very best in the history of articles. I am a antique ’Article’ collector and I sometimes read some new articles if I find them interesting. And I found this one pretty fascinating and it should go into my collection. Very good work!
    PMP Certification
    PMP Course
    PMP Course in Malaysia
    PMP Training in Malaysia
    PMP Training

    ReplyDelete

  11. I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work.
    360DigiTMG PMP Certification

    ReplyDelete
  12. I am looking for and I love to post a comment that "The content of your post is awesome" Great work!data science course

    ReplyDelete
  13. Thanks for sharing great information. I like your blog and highly recommendData Science Training in Hyderabad

    ReplyDelete
  14. Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing.
    visit for more details

    ReplyDelete
  15. You really make it look so natural with your exhibition however I see this issue as really something which I figure I could never understand. It appears to be excessively entangled and incredibly expansive for me.360DigiTMG data scientist malaysia

    ReplyDelete
  16. Extraordinary post. I simply found your blog and expected to express that I have genuinely refreshing scrutinizing your blog sections.Huge thankful for the significant data.

    HRDF training

    ReplyDelete
  17. I found Hubwit as a transparent s ite, a social hub which is a conglomerate of Buyers and Sellers who are ready to offer online digital consultancy at decent cost.
    Best Institute for Data Science in Hyderabad

    ReplyDelete
  18. I will really appreciate the writer's choice for choosing this excellent article appropriate to my matter.Here is deep description about the article matter which helped me more.
    data scientist courses

    ReplyDelete
  19. This is my first time visit here. From the tremendous measures of comments on your articles.I deduce I am not only one having all the fulfillment legitimately here!
    internet of things malaysia

    ReplyDelete
  20. Thanks for sharing great information. I highly recommend you.data science courses

    ReplyDelete

  21. Thankful to you a particularly lot for ding the stunning situation here, everyone will surely like your post.
    iot certification courses

    ReplyDelete
  22. Plumbing & HVAC Services San Diego
    Air Star Heating guarantees reliability and quality for all equipment and services.
    Air Star Heating is specializing in providing top-quality heating, ventilating, air conditioning, and plumbing services to our customers and clients.
    Our company is leading the market right now. By using our seamless and huge array of services. Our customers can now have the privilege of taking benefit from our services very easily and swiftly. To cope up with the desires and needs of our clients we have built an excellent reputation. We are already having a huge list of satisfied customers that seem to be very pleased with our services.

    Plumbing & HVAC Services in San Diego. Call now (858) 900-9977 ✓Licensed & Insured ✓Certified Experts ✓Same Day Appointment ✓Original Parts Only ✓Warranty On Every Job.
    Visit:- https://airstarheating.com

    ReplyDelete
  23. Thanks for sharing such a useful content. I really liked it. Keep sharing more!
    Data Science Course in Hyderabad

    ReplyDelete
  24. This is a fabulous post I seen because of offer it. It is really what I expected to see trust in future you will continue in sharing such a mind boggling post
    data scientist training and placement

    ReplyDelete
  25. I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much. baixar whatsapp gb versão mais recente

    ReplyDelete
  26. I just found this blog and have high hopes for it to continue. Keep up the great work, its hard to find good ones. I have added to my favorites. Thank You.
    data science training in pune

    ReplyDelete
  27. You’re so interesting! I don’t believe I’ve truly read something like this before. So great to find someone with genuine thoughts on this issue. Really.. many thanks for starting this up. This website is something that’s needed on the internet, someone with some originality!

    CBSE Schools In Attapur
    CBSE Schools In Bachupally
    CBSE Schools In Banjara Hills
    CBSE Schools In Begumpet
    CBSE Schools In Bowenpally
    CBSE Schools In Budgam
    CBSE Schools In Hyderabad
    CBSE Schools In Chintal
    CBSE Schools In ECIL
    CBSE Schools In Gachibowli

    ReplyDelete
  28. Thanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for. how to start a payment processing company

    ReplyDelete
  29. I really enjoy reading and also appreciate your work.
    data science course in pune

    ReplyDelete
  30. poker onlineพร้อมวิธีเล่นโป๊กเกอร์ออนไลน์ และเทคนิค เล่นไพ่

    ReplyDelete
  31. Wow its a very good post. The information provided by you is really very good and helpful for me. Keep sharing good information. SEO Gloucester

    ReplyDelete
  32. I have read your excellent post. This is a great job. I have enjoyed reading your post first time. I want to say thanks for this post. Thank you... business analytics course in mysore

    ReplyDelete
  33. There is no one-size-fits-all answer to this question, as the role of a payment processor can vary depending on the size and scope of the business. However, some tips on How to be a Payment Processor include understanding the payment processing industry, being able to identify potential risks associated with payments.

    ReplyDelete
  34. Express VPN Activation Code for PC gives you you with biggest IP Hiding service that nobody can conduct. The software’s popularity and need to get is soaring day by day. It is usually VPN tool which conceal your all duties from hackers

    ReplyDelete
  35. slot pay4D terpercaya bonus 100% didepan ANZSLOT deposit pulsa 24 jam tanpa potongan paling gacor se Indonesia.

    ReplyDelete
  36. Truly exceptionally interesting post. I was searching for such a data and enjoyed investigating this one. Continue to post. Appreciative for sharing.data scientist course in bhopal

    ReplyDelete
  37. Any creature can look at the WiFi Password Hacker Online section in the diagram and would like to use it for free. Online Wifi Hacker

    ReplyDelete
  38. Get intelligent suggestions in the Editor Overview pane in Word and let Editor assist you across documents, email, and on the web Download MS Office 2016 With Crack

    ReplyDelete
  39. Deep Dark Love Quotes quotations area unit simply phrases or quotes concerning deep love with such a splash of romance, tranquilly, and joy thrown certain smart live. True Love Dark Love Quotes

    ReplyDelete
  40. Great Information sharing .. I am very happy to read this article .. thanks for giving us go through info.Fantastic nice. I appreciate this post.
    cyber security course

    ReplyDelete
  41. รูปแบบเกมเล่นง่าย ไม่จำเจ เปลี่ยนการเล่นรูปแบบเดิมๆ ให้สนุกมากขึ้น ที่สุดแห่งแจ็กพ็อตแตกง่าย แตกบ่อย ไม่ต้องฝาก ไม่ต้องแชร์ เล่นได้เลยตอนนี้ผ่านเว็บไซต์ PGSLOTGAMES ทำกำไรได้อย่างรวดเร็ว รวยไปกับการเล่นจากทาง พีจี ไปเลยทันที PGทางเข้า

    ReplyDelete
  42. พร้อมรับความรวยได้เลย PG ทางเข้า เล่นเกมได้ง่ายผ่านทางเข้า PG ลุ้นรับโบนัสก้อนโต เล่นได้ก่อนใคร ทำกำไรได้ดั่งใจ พร้อมรับโบนัสใหม่ๆได้ทันที สมัครสมาชิกง่าย โดยไม่ต้องเสียค่าใช้จ่าย มีโปรโมชั่นให้เลือกมากมาย เริ่มตั้งแต่สมัครสมาชิก รับ 100 บาททันที

    ReplyDelete
  43. It’s awesome to pay a visit to this web page and reading the views of all friends regarding this paragraph, while I am also eager of getting experience
    Azure Data Factory course in hyderabad
    Azure Data Engineer Training Online Hyderabad
    azure training in hyderabad ameerpet
    Azure Data Factory online Training in Hyderabad
    Microsoft Azure Data Factory in hyderabad

    ReplyDelete
  44. เปิดกระเป๋าสตางค์ของคุณและดูเงิน คุณไม่มีเงินใช้สักบาทใช่ไหม ลองมาเล่นเกมกับเราและดูแล้วคุณจะมีเงินใช้ แวะเข้าไปเล่น ทางเข้าเล่นpg https://www.pgslot168game.com/login-pgslot/ เพื่อเล่นเกมสล็อตออนไลน์ง่ายๆ เล่นไม่ยาก ไม่ซับซ้อน แค่หมุนก็มีสิทธิ์ลุ้นรางวัลใหญ่และรางวัลใหญ่อีกมากมายจากางค่าย PG ที่ได้รวบรวมเกมดีมาให้เล่นได้อย่างไม่มีเบื่อ

    ReplyDelete
  45. Thank you for sharing your thoughts.
    Wise Care 365 Pro Crack Key
    https://freeproversion.com/wise-care-365-pro-crack-key-latest/

    ReplyDelete
  46. I think I have never seen such blogs ever before that has complete things with all details which I want. So kindly update this ever for us.
    full stack developer course with placement

    ReplyDelete
  47. Wow, this is a fantastic post. Your information is pretty excellent and beneficial to me. Share more accurate information. If anyone wants to learn data science visit at data science course in bhopal

    ReplyDelete
  48. We are also provide crack software. It has a wonderful feature. This is a good job. It is easy to use.
    https://azanpc.com/wondershare-filmora-11-crack-download-latest-version/

    ReplyDelete
  49. Historically, many casinos, each online and offline, have been unwilling to publish particular person sport RTP figures, making it inconceivable for the player to know whether or not they are enjoying in} a "free" or a "tight" sport. It is important that the machine accommodates a high-quality RNG implementation. Because all PRNGs must eventually repeat their casino.edu.kg quantity sequence and, if the period is brief or the PRNG is otherwise flawed, an advanced player may be able to|could possibly|might be able to} "predict" the following outcome.

    ReplyDelete
  50. Microsoft Office 2010
    Microsoft Office 2010 is great software which is use to enhance the working in system.

    ReplyDelete
  51. This comment has been removed by the author.

    ReplyDelete
  52. This comment has been removed by the author.

    ReplyDelete
  53. Top 3 psychiatrist in Lucknow
    Top 3 psychiatrist in Lucknow
    Managing and enhancing mental health depend on getting professional help from a psychiatrist. In this article, we will examine how to locate the Top 3 psychiatrist in Lucknow near you. We will also review a psychiatrist's training, job duties, appropriate times to see one, and what to expect at your first appointment. We'll also talk about the queries and exams a psychiatrist in Lucknow
    might use.

    ReplyDelete
  54. This is nice Artical and informative for me,.. imranpc.com

    ReplyDelete