Skip to main content

Reliable message passing in distributed systems.

Project description

buildstatus coverage codecov nala

⚽ Messi

Reliable message passing in distributed systems.

Highlights:

  • Guaranteed in order message delivery.

  • Client automatically reconnects when the server connection is lost.

  • Protocols defined in Googles Protocol Buffers language version 3.

  • Designed to work in resource constrained systems.

  • C and Python source code generators.

Project homepage: https://github.com/eerimoq/messi

Installation

$ pip install messi

C source code

Generate server and client side C source code.

$ messi generate_c_source examples/my_protocol/my_protocol.proto

Use -p/--platform to select which platform to generate code for.

Use -s/--side to select which side (client and/or server) to generate code for.

Supported platforms:

The generated code is not thread safe.

Known limitations:

  • The connection is immediately dropped if write() does not accept exaxtly given amount of bytes. Buffering of remaining data may be added at some point.

Linux client side

See tests/files/my_protocol/linux/my_protocol_client.h for the generated code and examples/my_protocol/client/linux/main.c for example usage.

Linux server side

See tests/files/my_protocol/linux/my_protocol_server.h for the generated code and examples/my_protocol/server/linux/main.c for example usage.

Async client side

See tests/files/my_protocol/async/my_protocol_client.h for the generated code and examples/my_protocol/client/async/main.c for example usage.

Python source code

Generate client side Python source code.

$ messi generate_py_source examples/my_protocol/my_protocol.proto

Use -s/--side to select which side (client and/or server) to generate code for.

Client side

See tests/files/my_protocol/my_protocol_client.py for the generated code and examples/my_protocol/client/python/main.py for example usage.

Server side

Not yet implemented.

Architecture

A Messi system consists of servers and clients. Once a client has successfully connected to a server, messages defined in their protocol specification can be reliably sent between them.

Messi guarantees that all sent messages are delivered in order to the peer. However, just as for TCP, any data/messages in flight when the connection is lost will likely be lost.

Below is a sequence diagram showing typical communication between a server and a client. The messages FooReq, FooRsp, BarInd, FieReq and FieRsp are defined in the protocol my_protocol, which is defined later in this document.

Each step (1 to 6) is described in detail after the sequence diagram.

              +--------+                               +--------+
              | client |                               | server |
              +--------+                               +--------+
                  |             1. TCP connect              |
                  |========================================>|
   on_connected() |                2. ping                  | on_client_connected()
                  |---------------------------------------->|
                  |                   pong                  |
                  |<----------------------------------------|
           send() |               3. FooReq                 |
                  |========================================>|
                  |                  FooRsp                 | reply()
                  |<========================================|
           send() |               4. BarInd                 |
                  |========================================>|
           send() |                  BarInd                 |
                  |========================================>|
                  |               5. FieReq                 | send()
                  |<========================================|
           send() |                  FieRsp                 |
                  |========================================>|
                  .                                         .
                  .                                         .
                  .                                         .
                  |                6. ping                  |
                  |---------------------------------------->|
                  .                                         .
on_disconnected() .                                         . on_client_disconnected()
                  .                                         .

Legend:

  ---: Background communication. No user interaction needed.

  ===: User initiated communication.

Step by step description:

  1. The client connects to the server. on_connected() and on_client_connected() are called to notify the user that the connection has been established.

  2. The client sends a ping message to the server, which responds with a pong message. This is done in the background. No user interaction needed.

  3. The client sends FooReq to the server, which responds with FooRsp.

  4. The client sends BarInd twice to the server. No response is defined.

  5. The server sends FieReq to the client, which responds with FieRsp.

  6. The client sends another ping message. This time the server does not respond. on_disconnected() and on_client_disconnected() are called to notify the user about the disconnection.

Messi protocol specification

All messages sent on the wire consists of a type, a size and optional payload. This enables both streaming and packet based transport protocols. The transport protocol must be reliable (guaranteed in order delivery).

Type and size are in network byte order (big endian).

+---------+---------+-----------------+
| 1b type | 3b size | <size>b payload |
+---------+---------+-----------------+

TYPE  SIZE  DESCRIPTION
------------------------------------------------------------------
   1     n  Client to server user message (client --> server).

            Encoded "message ClientToServer" messages.

   2     n  Server to client user message (server --> client).

            Encoded "message ServerToClient" messages.

   3     0  Ping message (client --> server).
   4     0  Pong message (server --> client).

User messages

User messages are defined in Googles Protocol Buffers language version 3.

Here is an example defining a protocol called my_protocol. The two messages ClientToServer and ServerToClient must be present in every protocol specification. ClientToServer contains all messages sent from clients to servers, and ServerToClient contains all messages sent from servers to clients.

syntax = "proto3";

// The protocol name.
package my_protocol;

// Messages sent from client to server.
message ClientToServer {
    oneof messages {
        FooReq foo_req = 1;
        BarInd bar_ind = 2;
        FieRsp fie_rsp = 3;
    }
}

// Messages sent from server to client.
message ServerToClient {
    oneof messages {
        FooRsp foo_rsp = 1;
        FieReq fie_req = 2;
    }
}

// Message definitions.
message FooReq {
}

message FooRsp {
}

message BarInd {
}

message FieReq {
}

message FieRsp {
}

Ping and pong messages

A client pings its server periodically. A client will close the connection and report an error if the server does not answer with pong within given time. Likewise, the server will close the connection and report an error if it does not receive ping within given time.

The ping-pong mechanism is only used if the transport layer does not provide equivalent functionality.

Error handling

Messi aims to minimize the amount of error handling code in the user application. Almost all functions always succeeds from the caller point of view. For example, my_protocol_client_send() returns void. If an error occurs, likely a connection issue, the disconnect callback is called to notify the user that the connection was dropped.

Similar solutions

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

messi-0.29.0.tar.gz (52.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

messi-0.29.0-py3-none-any.whl (31.6 kB view details)

Uploaded Python 3

File details

Details for the file messi-0.29.0.tar.gz.

File metadata

  • Download URL: messi-0.29.0.tar.gz
  • Upload date:
  • Size: 52.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.1

File hashes

Hashes for messi-0.29.0.tar.gz
Algorithm Hash digest
SHA256 1a14c94057c8f0900752421f26e3fce489b8c56d8ab2c3df3b93c5532fe71735
MD5 b31fda35022c2b66c44a8488a9bb1b32
BLAKE2b-256 dc5388b0d0c88d98d95e17662850dfb5c3efbd8748d1f3fbf37ff9e2e5951105

See more details on using hashes here.

File details

Details for the file messi-0.29.0-py3-none-any.whl.

File metadata

  • Download URL: messi-0.29.0-py3-none-any.whl
  • Upload date:
  • Size: 31.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.1

File hashes

Hashes for messi-0.29.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5ee1b6e2d7e27f700ede2b93813fa31d4b28c82eb7688c5e45a5039c2ef5d46c
MD5 422fdafdfd3a7d528b5d3238c0eff3d9
BLAKE2b-256 df31ee71cdc5b6a874c37f44274ae4f70a24195dbfb84ed4de2b6259f441295a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page