Say hello to weave 👶🎉❤️

Say hello to weave 👶🎉❤️

A new progressive microservice framework

Kevin ries
Posted on 24. May 2019 | 3 Min

I would like to announce that as the outcome of a half year’s hard work I created a brand-new microservices framework for NodeJS.

What is Weave?

Weave is an open-source fast & flexible framework, licensed under MIT. It contains most of all important microservices features (service registry, auto-discovery, load balancing, circuit-breaker…etc).

The key features of NATS in combination with Hemera are:

  • Lightweight: The Hemera core is small as possible and provide an extensive plugin system.
  • Location transparency: A service may be instantiated in different locations at different times. An application interacting with an service and does not know the service physical location.
  • Service Discovery: You don't need a service discovery all subscriptions are managed by NATS.
  • Load Balancing: Requests are load balanced (random) by NATS mechanism of "queue groups".
  • Packages: We provide reliable and modern plugins to the community.
  • High performant: NATS is able to handle million of requests per second.
  • Scalability: Filtering on the subject name enables services to divide work (perhaps with locality).
  • Fault tolerance: Auto-heals when new services are added. Configure cluster mode to be more reliable.
  • Auto-pruning: NATS automatically handles a slow consumer and cut it off.
  • Pattern driven: Define RPC's in JSON and use the flexibility of pattern-matching.
  • Request & Reply: By default point-to-point involves the fastest or first to respond.
  • Publish & Subscribe: Hemera supports all features of NATS. This includes wildcards in subjects and normal publish and fanout mechanism.
  • Tracing: Builtin tracing capabilities but we also provide plugin for Jaeger.
  • Monitoring: NATS server can be monitored by cli or a dashboard.
  • Payload validation: Create your own validator or use existing plugins e.g hemera-joi or hemera-ajv.
  • Serialization: Use custom serializer e.g hemera-mgspack.
  • Metadata: Transfer metadata across services or attach contextual data to tracing systems.
  • Dependencies: NATS is a single binary of ~10MB and can be deployed in seconds.

Key features

  • Written in Javascript
  • Promise-based solution
  • request-reply concept
  • support event driven architecture with balancing
  • supports middlewares
  • built-in caching solution (memory, Redis)
  • pluggable transporters (NATS, Redis)
  • load balanced requests (round-robin, random)
  • auto discovery services
  • health monitoring, metrics & statistics

How to start

Weave is available as an npm package. You can install it with npm or yarn

$ npm install @weave-js/cli

Usage This simple example show you how easy it is to create a service in Weave and call it.

const { ServiceBroker } = require('@weave-js/core')
// Create broker
let broker = new ServiceBroker({ logger: console })
// Create a service
    name: "math",
    actions: {
        // You can call it as"math.add")
        add(ctx) {
            return Number(ctx.params.a) + Number(ctx.params.b);
// Start broker
// Call actions of service"math.add", { a: 5, b: 3 }).then(res => console.log("5 + 3 =", res))

As you can see above, we created a math service which has an addaction. This action is able to add two numbers, the values of “a” and “b” parameters. After it created, we can call it with method. The first parameter is the calling path (service name + action name), the second parameter is the params which is passed to the action handler wrapped to a Context object.

You can try it in your browser on Runkit!

How to create a project

Use the Weave CLI tool to create a new Weave based microservices project. Install Weave-cli globally

npm install Weave-cli -g
  1. Create a new project (named Weave-demo)
weave create project test-project

Press Yes on all questions.

This starter project template creates a sample service (greeter) with Jest tests and an API Gateway.

  1. Open project folder and start it
cd Weave-demo
npm run dev
  1. Open the http://localhost:3000/api/greeter/hello link in your browser. It will call the hello action of greeter service.
  2. Open the http://localhost:3000/api/greeter/welcome?name=world link to call the welcome action of greeter service.

Congratulations! You have just created your first Weave based microservices project. Welcome to the microservices world! If you want to learn more about the Weave framework, check out our website or github.