Skip to content

[Phase 5] Implement TCP server mode (JavaScript) #17

@konard

Description

@konard

Summary

Implement standalone TCP server mode for JavaScript, 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
  • 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

import { LinksQueueServer } from 'links-queue/server';

const server = new LinksQueueServer({
  host: '0.0.0.0',
  port: 5000,
  backend: { type: 'link-cli', path: './data/db.links' },
  maxConnections: 1000,
  idleTimeout: 60000
});

server.on('connection', (client) => {
  console.log('Client connected:', client.id);
});

server.on('error', (error) => {
  console.error('Server error:', error);
});

await server.start();
console.log('Server listening on port 5000');

// Graceful shutdown
process.on('SIGTERM', async () => {
  await server.shutdown({ drainTimeout: 30000 });
});

Client Library

import { LinksQueueClient } from 'links-queue/client';

const client = new LinksQueueClient('tcp://localhost:5000');
await client.connect();

// Queue operations over network
await client.enqueue('tasks', { source: 'job', target: 'run' });
const link = await client.dequeue('tasks');

// Subscribe to queue
const subscription = client.subscribe('tasks', async (link) => {
  console.log('Received:', link);
  await client.acknowledge('tasks', link.id);
});

await client.disconnect();

Deliverables

  1. src/server/server.ts - TCP server implementation
  2. src/server/connection.ts - Connection handling
  3. src/server/router.ts - Request routing
  4. src/client/client.ts - Client library
  5. src/client/connection.ts - 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

  • Rust 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