Socket
Socket sink connector
Support Those Engines
Spark
Flink
SeaTunnel Zeta
Key features
Description
Used to send data to a socket server in streaming or batch mode. Each SeaTunnel row is serialized to a
JSON object via JsonSerializationSchema and written to the configured TCP port. The connector does
not append any delimiter at all — neither a newline, nor any other separator between records. Multiple
records therefore travel as one undelimited, continuous TCP byte stream of concatenated JSON objects
(for example {"a":1}{"a":2}{"a":3}). The output is explicitly not line-framed JSON, so the peer
must handle framing itself: parse consecutive JSON values with a streaming JSON parser (such as
Jackson's MappingIterator) rather than a line-oriented parser. Tools like nc -l only echo the raw
concatenated bytes, so they are useful for a quick single-row check but cannot split records on their
own.
For example, if the data from upstream is [
age: 12, name: jared], the content send to socket server is the following:{"name":"jared","age":17}
Sink Options
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| host | String | Yes | socket server host | |
| port | Integer | Yes | socket server port | |
| max_retries | Integer | No | 3 | The number of retries to send record failed. Set to -1 to retry indefinitely, or 0 to fail immediately. |
| common-options | No | - | Sink plugin common parameters, please refer to Sink Common Options for details |
Socket sink is mainly used for local debugging and simple integrations. It reconnects and retries failed writes according to max_retries, but it does not provide exactly-once delivery. The TCP client
opens one connection per writer; host/port are the server endpoint that this client connects to.
Task Example
This is randomly generated data written to the Socket side
env {
parallelism = 1
job.mode = "STREAMING"
}
source {
FakeSource {
plugin_output = "fake"
schema = {
fields {
name = "string"
age = "int"
}
}
}
}
sink {
Socket {
host = "localhost"
port = 9999
max_retries = 3
}
}
- Start a port listening
nc -l -v 9999
Start a SeaTunnel task
Socket Server Console print data. No delimiter is appended, so multiple rows arrive as concatenated JSON objects in the raw byte stream (line breaks shown here only for readability):
{"name":"jared","age":17}{"name":"jared","age":18}...
Changelog
Change Log
| Change | Commit | Version |
|---|---|---|
| [improve] socket options (#9517) | https://github.com/apache/seatunnel/commit/af83a302cf | 2.3.12 |
| [Feature][Restapi] Allow metrics information to be associated to logical plan nodes (#7786) | https://github.com/apache/seatunnel/commit/6b7c53d03c | 2.3.9 |
[Improve] Remove use SeaTunnelSink::getConsumedType method and mark it as deprecated (#5755) | https://github.com/apache/seatunnel/commit/8de7408100 | 2.3.4 |
| [Improve][build] Give the maven module a human readable name (#4114) | https://github.com/apache/seatunnel/commit/d7cd601051 | 2.3.1 |
| [Improve][Project] Code format with spotless plugin. (#4101) | https://github.com/apache/seatunnel/commit/a2ab166561 | 2.3.1 |
| [Feature][Connector] add get source method to all source connector (#3846) | https://github.com/apache/seatunnel/commit/417178fb84 | 2.3.1 |
| [Hotfix][OptionRule] Fix option rule about all connectors (#3592) | https://github.com/apache/seatunnel/commit/226dc6a119 | 2.3.0 |
| [Improve][Connector-V2][Socket] Unified exception for socket source & sink connector (#3511) | https://github.com/apache/seatunnel/commit/581292f210 | 2.3.0 |
| [feature][connector][socket] Add Socket Connector Option Rules (#3317) | https://github.com/apache/seatunnel/commit/b85317bcbe | 2.3.0 |
| [Improve][all] change Log to @Slf4j (#3001) | https://github.com/apache/seatunnel/commit/6016100f12 | 2.3.0-beta |
| [DEV][Api] Replace SeaTunnelContext with JobContext and remove singleton pattern (#2706) | https://github.com/apache/seatunnel/commit/cbf82f755c | 2.2.0-beta |
| [#2606]Dependency management split (#2630) | https://github.com/apache/seatunnel/commit/fc047be69b | 2.2.0-beta |
| [Feature][Connector-V2] Socket Connector Sink (#2549) | https://github.com/apache/seatunnel/commit/94f4600a4e | 2.2.0-beta |
| [api-draft][Optimize] Optimize module name (#2062) | https://github.com/apache/seatunnel/commit/f79e3112b1 | 2.2.0-beta |