Skip to content

callummarshall9/Sharp-SQL

Repository files navigation

Simple In-Memory AMQP Server

A standalone AMQP server implementation in C# with in-memory queues that other applications can connect to for message queuing operations.

Prerequisites

  • .NET 9.0: Make sure you have .NET 9.0 SDK installed
  • No external dependencies: This is a self-contained server with in-memory storage

How to Run

  1. Navigate to the project directory
  2. Run the application:
    dotnet run
  3. Choose mode:
    • 1: Run as Server (hosts the AMQP service)
    • 2: Run as Client Demo (connects to a running server)

Server Mode

Management Commands

Once the server is running, you can use these management commands:

  • create <queue_name> - Create a new queue
  • delete <queue_name> - Delete an existing queue
  • list - List all queues with message counts and subscriber counts
  • status - Show server status (clients, queues, messages)
  • clients - Show connected clients
  • help - Show available commands
  • stop - Stop the server

Example Server Usage

> create myqueue
SUCCESS|Queue 'myqueue' created successfully

> list
SUCCESS|Queues: myqueue (0 messages, 0 subscribers)

> status
Server Status:
  Running: True
  Port: 5672
  Connected Clients: 1
  Total Queues: 1
  Total Messages: 0

> stop
Stopping server...

Client Mode

The server accepts TCP connections on port 5672 and uses a simple text-based protocol.

Client Protocol Commands

  • CREATE_QUEUE|<queue_name>
  • DELETE_QUEUE|<queue_name>
  • SEND_MESSAGE|<queue_name>|<message>
  • RECEIVE_MESSAGE|<queue_name>
  • SUBSCRIBE|<queue_name> (for real-time message notifications)
  • LIST_QUEUES

Client Demo Usage

client> create testqueue
Server response: SUCCESS|Queue 'testqueue' created successfully

client> send testqueue Hello World!
Server response: SUCCESS|Message sent to queue 'testqueue'

client> subscribe testqueue
Server response: SUCCESS|Subscribed to queue 'testqueue'
You will now receive real-time messages from this queue.

client> receive testqueue
Server response: SUCCESS|Hello World!

Programming with the Client Library

You can use the included SimpleAmqpClient class in your applications:

var client = new SimpleAmqpClient();
await client.ConnectAsync();

// Create a queue
await client.CreateQueueAsync("myqueue");

// Send a message
await client.SendMessageAsync("myqueue", "Hello World!");

// Subscribe to real-time messages
client.MessageReceived += (queueName, message) => {
    Console.WriteLine($"Received: {message}");
};
await client.SubscribeToQueueAsync("myqueue");

// Or poll for messages
var response = await client.ReceiveMessageAsync("myqueue");

Features

Server Features

  • In-Memory Queues: Fast, lightweight message storage
  • TCP Server: Accepts multiple client connections
  • Real-time Subscriptions: Clients can subscribe to queues for instant message delivery
  • Management Interface: Command-line interface for server administration
  • Thread-Safe: Concurrent queue operations using thread-safe collections

Client Features

  • Simple Protocol: Easy-to-implement text-based protocol
  • Real-time Messages: Event-based message notifications
  • Connection Management: Automatic reconnection handling
  • Async Operations: Full async/await support

Architecture

┌─────────────────┐    TCP/5672    ┌──────────────────┐
│   Client App    │◄──────────────►│   AMQP Server    │
└─────────────────┘                │                  │
┌─────────────────┐    TCP/5672    │  ┌─────────────┐ │
│   Client App    │◄──────────────►│  │ In-Memory   │ │
└─────────────────┘                │  │ Queues      │ │
┌─────────────────┐    TCP/5672    │  └─────────────┘ │
│   Client App    │◄──────────────►│                  │
└─────────────────┘                └──────────────────┘

Protocol Specification

Request Format

COMMAND|parameter1|parameter2|...

Response Format

STATUS|message

Where STATUS can be:

  • SUCCESS: Operation completed successfully
  • ERROR: Operation failed
  • INFO: Informational message

Real-time Messages

When subscribed to a queue, clients receive: MESSAGE|<queue_name>|<message_id>|<message_content>

Notes

  • In-Memory Storage: All data is lost when the server stops
  • No Persistence: Messages are not saved to disk
  • Simple Protocol: Easy to implement in any programming language
  • Thread-Safe: Supports concurrent operations from multiple clients
  • Port 5672: Uses the standard AMQP port for compatibility

About

An SQL Server implementation in C#

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages