A simple, multi-threaded TCP message queue server written in Rust. This project demonstrates a basic implementation of a publish-retrieve message system using a shared in-memory queue.
The workspace consists of two main components:
tcp-server: The main application that runs a TCP server on127.0.0.1:8080. It handles concurrent client connections and manages the shared message queue.simpleDB: A library crate responsible for parsing commands (PUBLISH,RETRIEVE) and handling protocol logic.
- Multi-threaded Server: Handles multiple client connections simultaneously using
std::thread. - In-Memory Queue: Messages are stored in a thread-safe
Vecprotected by aMutex. - Simple Protocol: Text-based protocol for easy interaction.
- Rust (latest stable version)
To build the entire workspace:
cargo buildTo start the TCP server:
cargo run -p tcp-serverThe server will start listening on 127.0.0.1:8080.
You can interact with the server using tools like netcat (nc) or telnet.
-
PUBLISH
- Syntax:
PUBLISH <message> - Description: Adds a message to the queue.
- Example:
PUBLISH Hello World
- Syntax:
-
RETRIEVE
- Syntax:
RETRIEVE - Description: Removes and returns the last message from the queue (LIFO).
- Example:
RETRIEVE
- Syntax:
Terminal 1 (Server):
cargo run -p tcp-serverTerminal 2 (Client):
$ nc localhost 8080
PUBLISH First Message
PUBLISH Second Message
RETRIEVE
Second Message/n
RETRIEVE
First Message/nTo run the tests for the simpleDB library:
cargo test -p simple_db