TCP¶
Raw TCP server and client with pluggable codecs. Use it for low-level communication, custom binary protocols, or interop with NestJS TCP microservices.
Server Configuration¶
connector "tcp_server" {
type = "tcp"
driver = "server"
host = "0.0.0.0"
port = 9000
protocol = "json" # "json", "msgpack", "nestjs"
}
Client Configuration¶
connector "tcp_client" {
type = "tcp"
driver = "client"
host = "localhost"
port = 9000
protocol = "json"
connect_timeout = "10s"
}
Options¶
| Option | Type | Default | Description |
|---|---|---|---|
driver |
string | — | server or client |
host |
string | "0.0.0.0" |
Bind address (server) |
port |
int | — | Listen port (server) |
protocol |
string | "json" |
Wire format: json, msgpack, nestjs |
msgpack is MessagePack as the specification defines it, so the peer can be
anything that implements it. Before 2.19.0 it encoded JSON under that name:
two Mycel services configured for it did understand each other — both were
sending JSON — and nothing else could read a word of it.
| timeout | duration | "10s" | Connection timeout (client) |
Operations¶
Server (source): Message pattern matching — incoming messages are routed by their pattern field.
Client (target): Send messages to the remote TCP server.
Example¶
flow "handle_tcp_message" {
from {
connector = "tcp_server"
operation = "get_users"
}
to {
connector = "db"
target = "users"
}
}
flow "forward_to_tcp" {
from {
connector = "api"
operation = "POST /send"
}
to {
connector = "tcp_client"
operation = "process"
}
}
See the tcp example for a complete working setup.
Full configuration reference: See TCP in the Configuration Reference.