Coder Social home page Coder Social logo

coconspirators's Introduction

coconspirators

coconspirators is a microservice framework for RabbitMQ written in TypeScript. Under the hood it uses qmqp.node, the battle-tested AMQP client, under the hood to communicate with RabbitMQ and has best-practices baked in. Features include:

  • Simple API for subscribing, publishing and replying
  • Middleware Support
  • TypeScript First

Install

npm i coconspirators --S

Building

npm run build

Usage

import { Rabbit, json } from 'coconspirators';

const client = new Rabbit({
  // url of the rabbit server
  url: 'amqp://rabbitmq:5672',

  // supports conole and winston loggers
  logger: console
});

// Global Middleware
client.use(json());

// Connect!
await client.connect();

// Explicit Invoking Queues
const queue = client.queue('foo');
queue.subscribe(({ response, message }) => console.log(response, message));
queue.publish({ foo: true });

// Implicit Invoking Queues from client instance
client.subscribe('foo', ({ response, message }) => console.log(response, message));
client.publish('foo', { foo: true });

// Queue Middleware Usage
const queue = client.queue('foo', {}, json());

// Custom Queue Middleware
function myJson() {
  return {
    subscribe: async (msg) => {
      const content = msg.content.toString();
      return JSON.parse(content);
    },
    publish: async (msg) => {
      const json = JSON.stringify(msg);
      return new Buffer(json);
    }
  }
}

const queue = client.queue('foo', {}, myJson());

// RPC
const queue = client.queue('foo', { reply: true });
const result = client.publish('foo', { foo: true });
const reply = await client.replyOf(result.correlationId)

// Events
client.on('connected', () => console.log('connected!'))
client.on('disconnected', () => console.log('disconnected!'))

Similar

Credits

coconspirators is a Swimlane open-source project; we believe in giving back to the open-source community by sharing some of the projects we build for our application. Swimlane is an automated cyber security operations and incident response platform that enables cyber security teams to leverage threat intelligence, speed up incident response and automate security operations.

coconspirators's People

Contributors

amcdnl avatar

Watchers

beeman avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.