Skip to content

[Phase 5] Implement TCP server mode (Rust) #18

@konard

Description

@konard

Summary

Implement standalone TCP server mode for Rust, enabling Links Queue to run as a separate service that clients connect to.

Background

Server mode allows Links Queue to be deployed as a standalone service, separate from the application. Communication uses Links Notation protocol over TCP.

Requirements

Server Features

  • TCP listener with configurable bind address/port using tokio
  • Connection handling with concurrent clients
  • Request routing to queue operations
  • Connection pooling
  • Graceful shutdown with drain period
  • Health check endpoint

Protocol

  • Links Notation message framing over TCP
  • Request/response pattern
  • Bidirectional streaming for subscriptions
  • Heartbeat/ping-pong for connection health

Implementation

use links_queue::server::{LinksQueueServer, ServerConfig};

let server = LinksQueueServer::new(ServerConfig {
    host: "0.0.0.0".to_string(),
    port: 5000,
    backend: BackendConfig::LinkCli {
        path: PathBuf::from("./data/db.links"),
    },
    max_connections: 1000,
    idle_timeout: Duration::from_secs(60),
});

server.on_connection(|client| {
    println!("Client connected: {}", client.id());
});

server.start().await?;
println!("Server listening on port 5000");

// Graceful shutdown
tokio::select! {
    _ = shutdown_signal() => {
        server.shutdown(Duration::from_secs(30)).await?;
    }
}

Client Library

use links_queue::client::LinksQueueClient;

let client = LinksQueueClient::connect("tcp://localhost:5000").await?;

// Queue operations over network
client.enqueue("tasks", Link::new("job", "run")).await?;
let link = client.dequeue("tasks").await?;

// Subscribe to queue
let mut subscription = client.subscribe("tasks").await?;
while let Some(link) = subscription.next().await {
    println!("Received: {:?}", link);
    client.acknowledge("tasks", link.id).await?;
}

client.disconnect().await?;

Deliverables

  1. src/server/mod.rs - TCP server implementation
  2. src/server/connection.rs - Connection handling
  3. src/server/router.rs - Request routing
  4. src/client/mod.rs - Client library
  5. src/client/connection.rs - Client connection handling
  6. Unit tests with mock connections
  7. Integration tests with real server/client
  8. CLI: links-queue server --config config.json

Dependencies

Can Be Worked In Parallel With

  • JavaScript server mode (separate codebase)

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions