Skip to content

The central hub for MicroStream, a lightweight, real-time communication system for microservices. Routes messages between services, handles service discovery, and ensures seamless communication with WebSockets. Perfect for building scalable, event-driven architectures.

License

Notifications You must be signed in to change notification settings

arijitcodes/microstream-hub

Repository files navigation

MicroStream Hub 🏒

The central hub for Microstream, a lightweight, real-time communication system for microservices. Routes messages between services, handles service discovery, and ensures seamless communication with WebSockets. Perfect for building scalable, event-driven architectures.

Author: Arijit Banerjee
License: MIT

GitHub Repository Link Β Β 

GitHub License Β  GitHub language count Β  GitHub top language Β  GitHub last commit (branch) Β 

GitHub contributors Β  GitHub pull requests Β  GitHub issues Β  GitHub repo size Β  GitHub code size Β 

Semantic-Release Badge Β  Commitizen Friendly Β  Conventional Commits Badge Β 


Table of Contents πŸ“š


Features ✨

  • 🏒 Central WebSocket server for real-time communication between microservices.
  • πŸ”— Service discovery and registration.
  • πŸ“‘ Request routing and response handling.
  • ❀️ Heartbeat mechanism to detect and remove inactive services.
  • πŸ“Š Configurable logging for better observability.
  • πŸ”„ Real-time inter-service communication using WebSockets.
  • ⚑ Synchronous request-response pattern without HTTP overhead.
  • πŸ” Auto-discovery and connection management.

How Does It Work? 🌟

MicroStream simplifies communication between microservices using a centralized hub-and-spoke architecture, also known as a star network. In this model, the MicroStream Hub acts as the central communication point, and your microservices, equipped with the MicroStream Client, connect to the Hub and communicate through it.

Here's how it works:

🌟 The Star Network Concept

Imagine a star:

MicroStream Star Network Diagram

In this setup:

  • The Hub acts as the central communication point.
  • Services (nodes) connect to the Hub and communicate through it, not directly with each other.

πŸš€ How It Works in Practice

  1. Service Registration:

    • Each microservice connects to the Hub using the MicroStream Client.
    • The Hub automatically detects and registers the service.
  2. Request-Response Communication in Real-Time:

    • When Service A needs to talk to Service B, it sends a request to the Hub.
    • The Hub routes the request to Service B.
    • Service B processes the request and sends a response back through the Hub.
    • All communication happens in real-time over WebSockets, ensuring fast and reliable data exchange.
  3. Auto-Discovery:

    • Once connected, the Hub keeps track of all connected services, so you don’t need to manually configure connections between services. However, you still need to specify the target service and method when sending a request.
  4. Heartbeat Mechanism:

    • Services send regular "heartbeats" to the Hub to confirm they’re active.
    • If a service stops sending heartbeats, the Hub removes it from the network.

✨ Why Choose MicroStream?

MicroStream is designed to make microservice communication simple, efficient, and scalable. Here’s why you’ll love it:

  • Easy Setup: Minimal configuration required to get started.
  • Real-Time Request-Response Communication: Built on WebSockets for instant, reliable data exchange.
  • Auto-Service-Management: Once connected, the Hub keeps track of all services, simplifying network management.
  • Scalable: Easily add more services without reconfiguring the network.
  • Lightweight: Minimal overhead compared to traditional REST or gRPC.
  • Flexible: Works seamlessly with any microservice architecture.

Deployment πŸš€

Running via Docker 🐳

docker compose up --build

To change the port in Docker Compose, you can set the PORT environment variable in the docker-compose.yml file:

version: "3.8"
services:
  microstream-hub:
    build: .
    ports:
      - "${PORT:-3000}:3000"
    environment:
      - PORT=3000
    restart: unless-stopped

Running Locally πŸƒβ€β™‚οΈ

Installation πŸ› οΈ

npm install

Running the Hub

node src/hub.js

Configuration Example

To change the port, you can set the PORT environment variable:

PORT=4000 node src/hub.js

Client SDK πŸš€

We provide a client SDK for easy integration with the MicroStream Hub.


Author πŸ‘¨β€πŸ’»

Author: Arijit Banerjee

About: Full Stack Web Developer | Cyber Security Enthusiast | Actor

Social Media: Β  Instagram Instagram Β  Linkedin LinkedIn Β  GitHub GitHub Β  Website Website

Email: [email protected]


Contributing 🀝

We welcome contributions! Please see our CONTRIBUTING.md for guidelines on how to contribute to this project.


License πŸ“œ

This project is licensed under the MIT License. See the LICENSE file for details.


About

The central hub for MicroStream, a lightweight, real-time communication system for microservices. Routes messages between services, handles service discovery, and ensures seamless communication with WebSockets. Perfect for building scalable, event-driven architectures.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published