Code Monkey home page Code Monkey logo

cpp_rt_pubsub's Introduction

cpp_rt_pubsub: C++ real-time publish-subscribe (CRPS)

A minimal real-time publish-subscribe mechanism with a central broker implemented in modern C++.

Design

  • General
    • A node is a process using CRPS.
    • Topics have priorities. Higher priority topics are always handled before lower priority ones in both broker and nodes.
  • Broker
    • Central broker. All data passes through the broker. Publishers send data to the broker. The broker distributes the data to the subscribers.
  • Publishers/Subscribers
    • Each process using CRPS must create a Node instance that manages the publishers and subscribes in this process.
  • Communication
    • Single network connection between node and broker
    • Control: Register Node, add publisher/subscriber, ...
      • Variable length JSON
    • Data: Send/receive data to/from topic
      • Fixed size messages

Limitations / Potential improvements

  • Implementation is rather a proof of concept than production-ready
  • Single-threaded
  • Single broker (instead of one broker per host to keep communication between nodes on same host local)
  • IPv4 only
  • No DNS support, only IP addresses
  • No support for "latch" / "transient local durability" topics (i.e. deliver latest published message to subscribers that subscribe to topic at later point in time)

Notes

  • While the target platform is Linux, the code should be easy to port to other POSIX platforms by implementing interfaces in os.h and network.h
  • To ease detailed analysis, this project intentionally does not make use of external libraries, e.g. Boost.Asio

TODOs

  • Real-time on Linux
    • Thread scheduler class and thread priorities
    • Memory management (mlockall, mallopt, pre-load stack, ...)
  • All TODOs in the code ;)
  • Tests
  • Documentation
  • Implement Node (and hence Publisher and Subscriber) unregister
  • Implement API to query Broker, e.g. about nodes, topics, message types, publishers, subscribers, etc.
  • Sort source file content (e.g. method order).
  • General cleanup
  • Implement Network::Protocol::TCP
  • Handle wrap around of BpHeader::counter
  • Make implementation robust against corrupted / not well-formed messages, esp. BpType::Control.
  • Distinct error_codes in Control JSON
  • Accept dependency on Boost.Program_options and cleanup *_main.cpp(?)
  • Isolate BpType::Data processing from BpType::Control processing in broker.
  • Increment and monitor BpHeader::counter also in direction broker->node (not just node->broker); Counter should be unique per node
  • Add node liveliness monitoring. Either continuous (heartbeat from node to broker) or sporadic (broker polling node on demand, e.g. when node with same name tries to register)
  • Add a Broker->Node API?
  • Add a Node->(Broker->)Node API?
  • No-subscriber-optimization (i.e. don't publish data to broker that has no subscribers (unless topic is "latching"))
  • Add an example pub/sub that shows how to use CRPS with a proper (fixed sized) message serialization library (e.g. ROS2, FlatBuffers or Protocol Buffers) on top. Include a Publisher/Subscriber class, templated on the message type, that use Publisher/Subscriber internally, but hide all the raw buffer operations from the user.

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.