Skip to content

emmanuel-sp/Distributed-Message-Passing

Repository files navigation

Distributed Message Passing

A publish-subscribe messaging system with a centralized coordinator, built in C++ using TCP sockets. Participants register with the coordinator and can send messages to all other active participants, with support for disconnect/reconnect and message expiration.

Features

  • Centralized coordinator: Manages participant registration and message routing
  • Publish-subscribe model: Messages sent by any participant are broadcast to all others
  • Message expiration (TTL): Messages expire after a configurable time-to-live duration; expired messages are not delivered on reconnect
  • Fault tolerance: Participants can disconnect and reconnect, receiving any missed messages that have not yet expired
  • Dual-socket architecture: Separate command and message sockets per participant
  • Thread pool concurrency: Both coordinator and participants use thread pools for handling concurrent connections and message delivery
  • Message logging: Participants log received messages to a local file

Architecture

  • coordinator -- Central server that accepts participant connections. Maintains a registry of active participants and their message file descriptors. When a participant sends a message, the coordinator broadcasts it to all other connected participants. Tracks which participants have received each message for reliable reconnect delivery.
  • participant -- Connects to the coordinator and provides an interactive command prompt. Opens a listening socket for receiving messages from the coordinator.

Protocol

Participants send #-delimited messages to the coordinator over the command socket: <id>#<command> [args]#<ip>. The coordinator parses these and dispatches to the appropriate handler (register, deregister, disconnect, reconnect, msend).

Building

make        # builds both coordinator and participant
make clean  # removes binaries and build artifacts

Requires a C++ compiler with C++20 support and pthreads.

Usage

  1. Start the coordinator:

    ./coordinator config/coordinator.txt
  2. In separate terminals, start participants:

    ./participant config/participant1.txt
    ./participant config/participant2.txt
  3. On each participant, register with the coordinator:

    participant> register <listen_port>
    
  4. Send messages:

    participant> msend Hello everyone
    
  5. Other commands:

    • disconnect -- Disconnect from the group (can reconnect later)
    • reconnect <listen_port> -- Rejoin and receive missed non-expired messages
    • deregister -- Permanently leave the group

Configuration Files

Coordinator config (config/coordinator.txt):

<port>
<message_ttl_seconds>

Participant config (config/participant1.txt):

<participant_id>
<log_file_name>
<coordinator_ip> <coordinator_port>

About

Distributed Message Passing implementation in C++

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors