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 🙏

© 2026 – Pkg Stats / Ryan Hefner

microcom

v1.0.2

Published

Lightweight microservice communication package with Pub/Sub and RPC over AMQP

Downloads

14

Readme

Microcom

Microcom is a lightweight TypeScript library for microservice communication over AMQP.
It provides a simple, unified interface for both Pub/Sub (event-driven) and RPC (request-response) messaging patterns — built for services that run independently but need to stay in sync.

It supports RabbitMQ, LavinMQ, and other AMQP-compliant brokers out of the box.


Features

  • Shared AMQP connection reused across services.
  • Built-in Pub/Sub for event-driven systems.
  • Built-in RPC for request/response patterns.
  • Offline-first Pub/Sub: messages persist when a service is offline and are consumed when it comes back online.
  • Configurable queues per service (durable or transient).
  • Written entirely in TypeScript, with type-safe interfaces.
  • Supports distributed tracing (correlation IDs, trace IDs, etc.).

Installation

npm install microcom

Quick Start

RPC Example

import { MicrocomConnection, MicrocomRPC } from "microcom";

(async () => {
  // 1. Establish a shared AMQP connection
  const conn = await MicrocomConnection.create({
    amqpUrl: "amqp://localhost",
    queueName: "rpc_service_queue",
    queueProps: {
      exclusive: true,
      autoDelete: true,
    },
  });

  console.log("RPC connection established.");

  // 2. Create RPC instance
  const rpc = new MicrocomRPC(conn);

  // 3. Listen for incoming RPC requests
  rpc.respond(async (req) => {
    console.log("Received RPC request:", req);
    return { success: true, user: { id: req.userId, name: "John Doe" } };
  });

  // 4. Send an RPC request to another service
  const response = await rpc.request({
    method: "getUser",
    path: "users/getById",
    data: { userId: 101 },
  });

  console.log("RPC response:", response);
})();

Pub/Sub Example

import { MicrocomConnection, MicrocomPubSub } from "microcom";

(async () => {
  // 1. Establish a shared connection
  const conn = await MicrocomConnection.create({
    amqpUrl: "amqp://localhost",
    queueName: "user_service_queue",
    queueProps: {
      durable: true,        // ensures persistence
      exclusive: false,
      autoDelete: false,
    },
  });

  console.log("Pub/Sub connection established.");

  // 2. Initialize Pub/Sub with an exchange name
  const pubsub = await MicrocomPubSub.create(conn, "user_events", "topic");

  // 3. Subscribe to user-related events
  await pubsub.subscribe(
    (message) => {
      console.log("Received event:", message);
    },
    "user.created"
  );

  // 4. Publish a new event
  await pubsub.publish({
    event: "user.created",
    data: { id: 42, name: "John" },
  });

  console.log("Event published.");
})();

Behavior and Reliability

  • Offline-first design:
    Durable queues ensure that messages are not lost if a service goes down. When it restarts, all pending messages will be delivered automatically.

  • Exchange setup:
    Each Pub/Sub instance creates or connects to its own exchange (topic type by default).

  • AMQP compatibility:
    Works seamlessly with RabbitMQ, LavinMQ, and other AMQP 0.9.1 compatible brokers.


Configuration

MicrocomConnection.create(options)

{
  amqpUrl: string;                 // AMQP broker URL
  queueName: string;               // Service-specific queue name
  queueProps?: AMQPQueueParams;    // Optional queue parameters (durable, autoDelete, etc.)
}

MicrocomPubSub.create(connection, exchangeName, type)

exchangeName: string;  // Exchange name (e.g., "user_events")
type?: "topic" | "direct" | "fanout";  // Default is "topic"

Error Handling

Microcom methods return Promises and should be used with try/catch:

try {
  const response = await rpc.request({ method: "findUser", data: { id: 5 } });
} catch (err) {
  console.error("RPC request failed:", err);
}

Issue Reporting

If you encounter issues, please open an issue on GitHub and include:

  • Steps to reproduce
  • Expected behavior
  • Actual behavior
  • Node.js version
  • AMQP broker (RabbitMQ, LavinMQ, etc.)
  • Logs (if available)

License

MIT License © 2025