Skip to main content

Tools to create code to do IPC over MQTT

Project description

Stinger IPC

StingerIPC provides inter-process communications (IPC) between a server and multiple clients running on the same or separate hosts. It uses an MQTT server to pass messages between processes, implementing several IPC patterns: signals, properties, and proceedures.

Project Status

This project is in early stages of active development. You should not use it in any of your projects, both because it doesn't have enough features yet to be useful, and also because things will probably be horribly broken on future updates.

Interface Description

StingerIPC takes a interface description file (.singeripc), and will generate code and documentation from it. A very brief example of a interface description is:

stingeripc:
  version: 0.0.7

interface:
  name: Example
  version: 0.0.1

signals:

  foo:
    payload:
      - name: message
        type: string

methods:

  addNumbers:
    arguments:
      - name: left
        type: integer
      - name: right
        type: integer
    returnValues:
      - name: sum
        type: integer

First class code generation

From the StingerIPC description file, we directly generate server and client code for these languages: Python3, C++11, and Rust.

Server Code

From the above description file, StingerIPC generates server code, which can be used like this:

# Python
conn = MqttConnection('localhost', 1883)
server = ExampleServer(conn)

server.emit_foo("Hello World")

@server.handle_add_numbers
def add_numbers(left: int, right: int) -> int:
    return left + right
// C++
auto conn = std::make_shared<DefaultConnection>("localhost", 1883);
ExampleServer server(conn);
server.emitFoo("Hello World").wait();

server.registerAddNumbersHandler([](int left, int right) -> int
{
  return left + right;
});
// Rust
let connection = Connection::new(String::from("tcp://localhost:1883"));
let mut server = SignalOnlyServer::new(connection);
server.emit_foo("Hello World".to_string());

server.register_add_numbers_handler(|left, right| {
    left + right
});

Client Code

From the above description file, StingerIPC generates client code which can be used like this:

# Python
conn = MqttConnection('localhost', 1883)
client = ExampleClient(conn)

@client.receive_foo
def print_foo_receipt(message):
    print(f"Got a 'foo' signal with message: {message}")

future = client.add_numbers(1, 2)
timeout = 5
print(future.result(timeout))
// C++
auto conn = std::make_shared<DefaultConnection>("localhost", 1883);
ExampleClient client(conn);
client.registerFooCallback([](const std::string& message) {
    std::cout << message << std::endl;
});

std::cout << "One plus three is " << client.addNumbers(1, 3).wait() << std::endl;
// Rust
let connection = Connection::new(String::from("tcp://localhost:1883"));
let mut client = ExampleClient::new(connection);
client.set_signal_recv_callbacks_for_foo(|message| {
    println!("{}", message);
});

client.add_numbers(1, 4);

AsyncAPI and second-class code generation

AsyncAPI is a specification format for describing asynchronous message APIs. Since StingerIPC uses and abstracts asynchonous messages between server and clients, we can describe a StingerIPC system with an AsyncAPI document.

From that AsyncAPI document, we can generate code and documentation in additional languages. While this code generation won't implement our standard IPC design patterns, it does make accessing the communications more easy.

Inter-process communication (IPC)

The motivation for this project is that I've seen embedded Linux projects that run several daemons that need to talk to each other, and for whatever reasons D-Bus wasn't a good option.

So this project is a way for those daemons/programs to communicate with each other through an MQTT broker running on the same device. The design goals of this project have been tuned toward this use case.

That being said, there is nothing prohibiting Stinger-IPC to be used for RPC: remote proceedure calls. RPC typically involves being able to call into a system from a different system. That certainly can be done by having the remote systems connect into the same MQTT broker as the local system. However, this isn't the primary use case, and design goals aren't geared to make Stinger-IPC the best solution for RPC (though don't let that stop you from using it that way). Specifically, Stinger-IPC requires the server and all clients to be running the same version of code. For systems where all the software ships together, this usually isn't a problem, but could be a problem for systems with remote connections.

Comparison to gRPC

gRPC is probably a better solution for handling RPC and connections from remote clients. It does a much better job at handling compatibility between different versions, supporting a wider number of languages, and transports messages more efficiently.

But gRPC, as most typically deployed, provide some challenges for use inside an embedded Linux system. gRPC typically wants secured HTTP/2 connections, which are just overkill for communications within a single device. Additionally, the protobuf code generation is just more complicated.

Design goals

  • Low learning curve.
  • No fancy/tricky code. Generated code should look like a a human wrote it for humans to use it.
  • Useable for embedded Linux systems.
  • Be described by an AsyncAPI spec.

License

LGPLv2

Project details


Release history Release notifications | RSS feed

This version

0.0.7

Download files

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

Source Distribution

stinger_ipc-0.0.7.tar.gz (61.6 kB view details)

Uploaded Source

Built Distribution

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

stinger_ipc-0.0.7-py3-none-any.whl (80.7 kB view details)

Uploaded Python 3

File details

Details for the file stinger_ipc-0.0.7.tar.gz.

File metadata

  • Download URL: stinger_ipc-0.0.7.tar.gz
  • Upload date:
  • Size: 61.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.13

File hashes

Hashes for stinger_ipc-0.0.7.tar.gz
Algorithm Hash digest
SHA256 4bae7d7a696da694e8b0599e16c3e3ec9b367fcef98b98559646884b5aa0c540
MD5 5d51640324abdfd901bd24f2a6329ca0
BLAKE2b-256 576360038f6969e70c154ebb72e573f51361fea69ce90067be368f5c6e67242c

See more details on using hashes here.

File details

Details for the file stinger_ipc-0.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for stinger_ipc-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 ae99ee8e91b5edbcc50600dccef5173ec415db295429bd5492c78d4c17de6d79
MD5 20bbc9ef2b29634d94dae894dba6e75c
BLAKE2b-256 4e5b198751823dc964d76fc1182647bdd260134a6cff7a6206fdbef86d3a017e

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