Giter Site home page Giter Site logo

binarskugga / webmesh Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 1.0 86 KB

Connects microservices through a mesh of websockets

License: Apache License 2.0

Python 100.00%
microservice mesh websocket python3 python msgpack parallelism zlib websockets websocket-server websocket-library mesh-network

webmesh's Introduction

WebMesh

Deploy

WebMesh is a WebSocket based communication library for microservices. It uses a WebSocket server based on wsproto that distributes clients on a thread pool to achieve high parallelism and performance. It aims at providing the building blocks to inter-connect multiple services at the application level seamlessly. (corporate lorem ipsum ends here).

Design

[TODO]

Todo before first release

  • Add SSL Support
  • Improve Failure Resilience (retrying connections etc..)
  • Path arguments and resolution for consumers
  • Implement a Subscription System
  • Node discovery and status reporting
    • Testaments & Last Will maybe ?
  • Implement a class that regroups a server and multiple clients to each peers (WebMesh(server, *peers) ?)

Tests & Lint

Install nox: pip install nox

Execute all the session at the root of the project: nox

Install

Simply execute: pip install webmesh

WebMesh Server

WebMesh's server works like a standard HTTP server. It uses a declarative syntax with decorators defining callbacks on routes. Here's the basic example for a locally accessible echo server:

from typing import Any

from webmesh.websocket.abstract_websocket_connection import AbstractWebSocketConnection
from webmesh.webmesh_server import WebMeshServer

server = WebMeshServer()


@server.on('/')
def echo(payload: Any, path: str, client: AbstractWebSocketConnection):
  return payload


server.listen()
server.await_started()

# Server is ready and running in its own thread

server.close()

This is all good and pretty but by default, WebMesh uses msgpack and zlib to communicate which makes it hard to manually use. You can change the serialization layer by providing an implementation of the AbstractMessageSerializer class. WebMesh provides a simple JSON serializer that you can pass into your server's constructor:

from webmesh.webmesh_server import WebMeshServer
from webmesh.message_serializers import StandardJsonSerializer

server = WebMeshServer(serializer_type=StandardJsonSerializer)

Note: We are using the class and not an instance. This is because the websocket backend uses processes for parallelism. This limits us as to what we can use because it requires to be pickled. By passing the class, we can instantiate the serializer inside the process and have more flexibility.

webmesh's People

Contributors

binarskugga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

webclinic017

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.