DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Replacing JSON With Protobuf in Your Microservice Mesh: A Zero-Downtime Migration Blueprint
  • Node.js Microservices Architecture: A Complete Guide
  • Deploying a Spring Boot Microservice on AWS Fargate: Lessons From the Outage That Forced Me to Get It Right
  • Refresh Token Rotation in Node.js: Stopping Token Theft Without Logging Users Out

Trending

  • Closing the Drift Loop: An AI Agent That Drafts Terraform Fixes
  • The Window Closes: Why I Switched to Kotlin Before the Codebase Got Too Big
  • Batching Strategies: Throughput vs Latency in Practice
  • Designing Frontend Applications for Failure, Not Just Success

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. Data
  4. Understanding Microservices Choreography Using RabbitMQ and Node.js

Understanding Microservices Choreography Using RabbitMQ and Node.js

We take a brief look at the concept of microservices choreography and how this would work in an app using RabbitMQ and Node.js.

By 
Danesh Hussain Zaki
·
Updated Feb. 20, 20 · Analysis
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
21.1K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

A colleague and I had discussed the choreography of microservices a while ago and the topic came up for discussion again recently. In order to ensure that I understood the nuances correctly, I decided to write some code to implement the approach. Here are the tools/technologies that I chose:

  • Node.js for building the microservices.
  • Restify for exposing Restful APIs.
  • CloudAMQP — a RabbitMQ as a service offering as the integration bus.
  • amqp.node — a Node.js client library for RabbitMQ.

CloudAMQP offers a free tier good enough for learning and trying things out. It also comes with an easy to use management console that gives good statistics. The tutorials and articles are useful too. There is a host of options for the Node.js RabbitMQ client libraries. I tried a few and then settled with amqp.node as the RabbitMQ site had their tutorials based on it. The library comes in two flavors, one with callbacks and the other with promises. Being comfortable with callbacks, I opted for it.

Microservices architecture

Microservices architecture

The approach that I followed was to mimic a part of the order management process where a POST method triggers the order creation service. The service processes the order, creates an entry in the order management database and sends a message to a RabbitMQ topic. Another service listens to the topic for a specific key that denotes that the order creation is complete and gets triggered when a message with that key is published. This service checks for inventory and either calls a service to replenish stock if it is low or calls an order shipment service if the stock is available. It also publishes a message on the topic with the respective keys to trigger the following services.

Apache Kafka can be used as an alternative to RabbitMQ as an event bus. This approach is suitable while creating new microservices as they can be made to start on the basis of an event.

Full code is available here.

“The views expressed in this article are mine and my employer does not subscribe to the substance or veracity of my views.”

microservice Node.js

Published at DZone with permission of Danesh Hussain Zaki. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Replacing JSON With Protobuf in Your Microservice Mesh: A Zero-Downtime Migration Blueprint
  • Node.js Microservices Architecture: A Complete Guide
  • Deploying a Spring Boot Microservice on AWS Fargate: Lessons From the Outage That Forced Me to Get It Right
  • Refresh Token Rotation in Node.js: Stopping Token Theft Without Logging Users Out

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook