camel-component-ws
WebSocket client/server component for rust-camel
Overview
camel-component-ws adds WebSocket endpoints to rust-camel for both inbound server consumers and outbound client producers.
URI Format
ws://host:port/path[?options]
wss://host:port/path[?options]
Features
- Server Consumer: accept incoming WebSocket connections and feed route exchanges
- Client Producer: connect to remote WebSocket endpoints and send/receive frames
- Server-send mode: send to all local clients (broadcast) or specific connections
- TLS: secure server/client URIs via
wss://(rustls, no OpenSSL dependency) - Runtime enforcement: max connections, message size, heartbeat, and idle timeout
Installation
Add to your Cargo.toml:
[]
= "0.5"
URI Parameters
| Parameter | Default | Description |
|---|---|---|
maxConnections |
100 |
Maximum concurrent connections for the endpoint path |
maxMessageSize |
65536 |
Maximum inbound message size (bytes) |
sendToAll |
false |
Default producer behavior for local server-send mode |
heartbeatIntervalMs |
0 |
Ping interval in milliseconds (0 disables heartbeat) |
idleTimeoutMs |
0 |
Idle timeout in milliseconds (0 disables timeout) |
connectTimeoutMs |
10000 |
Client connect timeout in milliseconds (10s) |
responseTimeoutMs |
30000 |
Client response timeout in milliseconds |
allowOrigin |
* |
Allowed Origin header for WS upgrade requests |
tlsCert |
(none) | TLS certificate path (required for wss consumer) |
tlsKey |
(none) | TLS private key path (required for wss consumer) |
Exchange Headers
| Header | Direction | Description |
|---|---|---|
CamelWsConnectionKey |
Consumer → route | Unique connection key for the current client |
CamelWsPath |
Consumer → route | Request path that received the message |
CamelWsRemoteAddress |
Consumer → route | Remote peer socket address |
CamelWsSendToAll |
Route → producer | If true, producer broadcasts to all local clients |
sendToAll |
Route → producer | Fallback for CamelWsSendToAll (checked if not set) |
CamelWsMessageType |
Route → producer | Outbound type: text (default) or binary |
Usage (DSL)
WebSocket Consumer Route
use RouteBuilder;
use WsComponent;
use CamelContext;
let mut ctx = new;
ctx.register_component;
ctx.add_route.await?;
WebSocket Client Producer
let route = from
.to
.build?;
Local Server Broadcast
use Value;
let route = from
.set_header
.set_header
.to
.build?;
Local Server Targeted Send
use Value;
let route = from
.set_header
.to
.build?;
Secure WSS Consumer
let route = from
.build?;
Camel.toml Example
[]
= 200
= 131072
= 15000
= 60000
= 5000
= 10000
URI parameters still take precedence over global defaults.
Note: Global config from Camel.toml is parsed but not yet applied to endpoints. Currently only URI parameters and code defaults are active. Full 3-tier override (defaults → Camel.toml → URI) is planned.
Documentation
License
Apache-2.0
Contributing
Contributions are welcome! Please see the main repository for details.