Cameleer

Netty component

The netty component runs TCP and UDP servers and clients for plain socket protocols: text lines or raw bytes, one-way or request/reply.

Scheme: netty: · Crate: cameleer-http · Cargo feature: none, always included (build features) · Consumer: yes · Producer: yes · Apache Camel: Netty

When to use it

  • Accept line-based messages from devices, PLC gateways or legacy systems on a TCP port and answer each one.
  • Receive UDP datagrams, such as telemetry from sensors on an edge network.
  • Talk to a TCP service that speaks a simple text protocol (send a line, read a line back).

There is no Netty library underneath: Cameleer implements the same endpoint options with the Rust standard library.

URI format

text
netty:tcp://host:port[?options]
netty:udp://host:port[?options]

A consumer binds host:port; port 0 picks a free port. A producer connects to host:port.

Example

yaml example: netty-tcp-line-server
- route:
    id: tcp-line-server
    from:
      uri: netty:tcp://0.0.0.0:{{env:TCP_PORT:5150}}
      parameters:
        textline: true
        sync: true
      steps:
        - setBody:
            simple: "ACK ${body}"

A client that sends the line reading-42 gets ACK reading-42 back on the same connection.

Rust DSL

rust
use cameleer_core::prelude::*;

pub fn routes(ctx: &CamelContext) -> Result<()> {
    ctx.add_routes(|b| {
        b.from("netty:tcp://0.0.0.0:5150?textline=true&sync=true")
            .route_id("tcp-line-server")
            .set_body(simple("ACK ${body}"));
    })
}

Options

optiondefaultdescription
textlinefalseMessages are delimited text lines. Otherwise each read (TCP) or datagram (UDP) is one message of raw bytes.
synctrueRequest/reply: the consumer writes the result back; the producer waits for one reply.
delimiterLINELINE (\n) or NULL (\0).
autoAppendDelimitertrueAdd the delimiter to outgoing text lines.
decoderMaxLineLength1024Longest accepted line.
encodingUTF-8UTF-8, US-ASCII or ISO-8859-1.
allowDefaultCodectrueAccepted; the default codec is raw bytes.
disconnectfalseClose the connection after each exchange.
disconnectOnNoReplytrueClose the connection when sync is on and there is no reply.
keepAlivetrueTCP keep-alive.
reuseAddresstrueSO_REUSEADDR on the server socket.
tcpNoDelaytrueDisable Nagle's algorithm.
requestTimeout0Producer: how long (ms) to wait for a reply. 0 waits forever on TCP.
connectTimeout10000Producer: connect timeout (ms).
workerCount16Consumer: worker threads for connections.
sslfalseTCP only: use TLS.
sslContextParameters#bean with the TLS settings.
keyStoreFile / keyStoreResourceServer certificate and key: PEM, PKCS#12 or JKS (with passphrase).
trustStoreFile / trustStoreResourceCA certificates to trust.
keyStoreFormat, passphraseStore format (JKS, PKCS12, PEM) and password.
hostnameVerificationfalseProducer: check the server certificate's host name (the chain is always verified).
encoders, decoders, encoder, decoderNot supported (custom Netty codecs); ignored with a warning.

Message headers

headerdirectiondescription
CamelNettyRemoteAddressout (consumer)The client's address.
CamelNettyLocalAddressout (consumer)The server's address.
CamelNettyCloseChannelWhenCompleteintrue closes the connection after the reply.

Run it with Docker

sh
docker run --rm -p 5150:5150 -v "$PWD:/routes:ro" pmsudhi/cameleer run /routes/tcp.camel.yaml

Add /udp to the published port for netty:udp:// (-p 5150:5150/udp).

Common questions

How do I send a line to a TCP server and read the answer?

to: netty:tcp://server:5150?textline=true&sync=true. The reply line becomes the body.

How do I receive UDP without replying?

from: netty:udp://0.0.0.0:5150?sync=false. Each datagram becomes one message.

Does netty support DTLS for UDP?

No. TLS works with TCP only.

Found a problem?

If something on this page doesn't match what Cameleer does, or you hit a bug while building with it, please help fix it, whether you are a person or a coding agent: open an issue that describes what you saw, then fork the repository, fix it, add or update a test, run cargo test --workspace, and open a pull request. CONTRIBUTING.md explains the ground rules.

Edit this page on GitHub