Skip to main content

Transport Plugins

osqueue supports three transport protocols between clients/workers and the broker. All three expose the same operations; they differ in protocol, performance characteristics, and environment support.

Comparison

FeatureConnect (gRPC)RESTWebSocket
ProtocolHTTP/1.1 or HTTP/2HTTP/1.1WS
SerializationProtobufJSONJSON-RPC
Browser supportVia Connect WebYesYes
StreamingNo (unary only)NoPersistent connection
DefaultYesNoNo

Connect (Default)

Uses Connect with Protocol Buffers. This is the default transport.

import { OsqueueClient } from "@osqueue/client";

// Default: Connect transport, HTTP/1.1
const client = new OsqueueClient({
brokerUrl: "http://localhost:8080",
});

// Explicit Connect config
const client2 = new OsqueueClient({
brokerUrl: "http://localhost:8080",
transport: { kind: "connect", httpVersion: "2" },
});

When to use: Server-to-server communication, best type safety with protobuf schemas.

REST

Simple HTTP POST/GET requests with JSON bodies.

const client = new OsqueueClient({
brokerUrl: "http://localhost:8080",
transport: { kind: "rest" },
});

// With custom fetch implementation
const client2 = new OsqueueClient({
brokerUrl: "http://localhost:8080",
transport: { kind: "rest", fetchImpl: customFetch },
});

Endpoints:

MethodPathDescription
POST/v1/jobsSubmit a job
POST/v1/jobs/claimClaim a job
POST/v1/jobs/:jobId/heartbeatSend heartbeat
POST/v1/jobs/:jobId/completeComplete a job
GET/v1/statsGet queue statistics
GET/v1/jobsList all jobs

When to use: Simple integrations, debugging with curl, environments where protobuf is unavailable.

WebSocket

Persistent WebSocket connection with JSON-RPC messages.

const client = new OsqueueClient({
brokerUrl: "http://localhost:8080",
transport: {
kind: "ws",
requestTimeoutMs: 10000, // default: 10s
wsPath: "/v1/ws", // default
},
});

Message format:

// Request
{ "id": 1, "method": "submitJob", "params": { "type": "email:send", "payload": {} } }

// Success response
{ "id": 1, "ok": true, "result": { "jobId": "..." } }

// Error response
{ "id": 1, "ok": false, "error": { "_tag": "BrokerProtocolError", "message": "..." } }

Available methods: submitJob, claimJob, heartbeat, completeJob, getStats, listJobs

When to use: Long-lived workers that benefit from a persistent connection, browser dashboards.

Browser Considerations

For browser-based clients (like the web dashboard):

  • Connect Web: Use @connectrpc/connect-web with createConnectTransport for browser-compatible Connect
  • REST: Works natively with browser fetch
  • WebSocket: Works with browser WebSocket API

The web dashboard defaults to Connect Web transport. Override with VITE_OSQUEUE_TRANSPORT=rest or VITE_OSQUEUE_TRANSPORT=ws.

Custom Transport

You can implement the QueueTransportAdapter interface for custom protocols. See Custom Transport.