RocketMQ
RocketMQ sink connector
Support Apache RocketMQ Version
- 4.9.0 or newer
Support These Engines
Spark
Flink
SeaTunnel Zeta
Key Features
Description
Writes SeaTunnel rows to an Apache RocketMQ topic. The sink supports JSON and text message bodies, optional message tags, synchronous sending, partition key fields, and transactional messages when exactly.once = true.
Sink Options
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| topic | String | yes | - | RocketMQ topic name. |
| name.srv.addr | String | yes | - | RocketMQ name server address, for example localhost:9876. |
| acl.enabled | Boolean | no | false | Whether to enable RocketMQ ACL authentication. |
| access.key | String | no | - | Access key. Required when acl.enabled is true. |
| secret.key | String | no | - | Secret key. Required when acl.enabled is true. |
| producer.group | String | no | SeaTunnel-Producer-Group | RocketMQ producer group ID. |
| tag | String | no | - | RocketMQ message tag written with each message. |
| partition.key.fields | List | no | - | Field names serialized as the RocketMQ message key. Every listed field must exist in the upstream schema. |
| format | String | no | json | Message format. Supported values are json and text. |
| field.delimiter | String | no | , | Field delimiter used when format = text. |
| producer.send.sync | Boolean | no | false | Whether to send messages synchronously. When false, messages are sent asynchronously. |
| exactly.once | Boolean | no | false | Whether to send transactional messages for exactly-once delivery. |
| max.message.size | int | no | 4194304 | Maximum message body size in bytes. |
| send.message.timeout | int | no | 3000 | Send timeout in milliseconds. |
| common-options | config | no | - | Sink common options. See Sink Common Options. |
Option Notes
partition.key.fields
partition.key.fields controls the RocketMQ message key. SeaTunnel serializes
the configured field values as JSON and writes that value to Message.keys. For
non-transactional sends, the same key is also used by RocketMQ's hash queue
selector, so rows with the same key are sent to the same queue. If this option is
not set, RocketMQ chooses the queue.
For example, if the input schema contains c_int, this configuration uses c_int to build the message key:
partition.key.fields = ["c_int"]
exactly.once
The sink supports exactly-once writes through RocketMQ transactional messages. This behavior is disabled by default. Set exactly.once = true when the RocketMQ cluster and the job checkpoint settings are ready for transactional writes.
When format = text, SeaTunnel serializes fields in the upstream schema order and joins them with field.delimiter. When format = json, each row is written as a JSON object.
producer.send.sync
producer.send.sync = true makes the producer wait for RocketMQ to acknowledge
each send request. With the default value false, messages are sent
asynchronously.
Task Examples
Write JSON Messages
env {
parallelism = 1
job.mode = "BATCH"
}
source {
FakeSource {
row.num = 10
schema = {
fields {
c_string = string
c_int = int
c_timestamp = timestamp
}
}
}
}
sink {
Rocketmq {
name.srv.addr = "rocketmq-e2e:9876"
topic = "test_topic"
partition.key.fields = ["c_int"]
producer.send.sync = true
}
}
Write Text Messages
env {
parallelism = 1
job.mode = "BATCH"
}
source {
FakeSource {
row.num = 10
schema = {
fields {
id = bigint
content = string
}
}
}
}
sink {
Rocketmq {
name.srv.addr = "rocketmq-e2e:9876"
topic = "test_text_topic"
format = text
field.delimiter = ","
producer.send.sync = true
}
}
Write Messages With a Tag
env {
parallelism = 1
job.mode = "BATCH"
}
source {
FakeSource {
row.num = 10
schema = {
fields {
c_string = string
c_int = int
}
}
}
}
sink {
Rocketmq {
name.srv.addr = "rocketmq-e2e:9876"
topic = "test_topic_message_tag"
tag = "test_tag"
partition.key.fields = ["c_string"]
producer.send.sync = true
}
}
Read and Write RocketMQ
env {
parallelism = 1
job.mode = "STREAMING"
checkpoint.interval = 5000
}
source {
Rocketmq {
name.srv.addr = "rocketmq-e2e:9876"
topics = "test_topic_source"
plugin_output = "rocketmq_table"
format = json
start.mode = "CONSUME_FROM_FIRST_OFFSET"
consumer.group = "rocketmq_to_rocketmq_group"
schema = {
fields {
id = bigint
c_string = string
}
}
}
}
sink {
Rocketmq {
plugin_input = "rocketmq_table"
name.srv.addr = "rocketmq-e2e:9876"
topic = "test_topic_sink"
partition.key.fields = ["id"]
exactly.once = true
}
}
Changelog
Change Log
| Change | Commit | Version |
|---|---|---|
| [Improve][API] Optimize the enumerator API semantics and reduce lock calls at the connector level (#9671) | https://github.com/apache/seatunnel/commit/9212a77140 | 2.3.12 |
| [improve] rocketmq options (#9251) | https://github.com/apache/seatunnel/commit/4cbe3b9172 | 2.3.12 |
| [Feature][Checkpoint] Add check script for source/sink state class serialVersionUID missing (#9118) | https://github.com/apache/seatunnel/commit/4f5adeb1c7 | 2.3.11 |
| [Improve][Connector-V2] RocketMQ Source add message tag config (#8825) | https://github.com/apache/seatunnel/commit/5913e8c35f | 2.3.10 |
| [Improve][Connector-V2] Add optional flag for rocketmq connector to skip parse errors instead of failing (#8737) | https://github.com/apache/seatunnel/commit/701f17b5d4 | 2.3.10 |
| [Improve][Connector-V2] RocketMQ Sink add message tag config (#7996) | https://github.com/apache/seatunnel/commit/97a1b00e48 | 2.3.9 |
| [Feature][Restapi] Allow metrics information to be associated to logical plan nodes (#7786) | https://github.com/apache/seatunnel/commit/6b7c53d03c | 2.3.9 |
| [Fix][Connector-V2] Fix some throwable error not be caught (#7657) | https://github.com/apache/seatunnel/commit/e19d73282e | 2.3.8 |
| [Feature][Kafka] Support multi-table source read (#5992) | https://github.com/apache/seatunnel/commit/60104602d1 | 2.3.6 |
| [Fix][connector-rocketmq] commit a correct offset to broker & reduce ThreadInterruptedException log (#6668) | https://github.com/apache/seatunnel/commit/b7480e1a89 | 2.3.6 |
| [fix][connector-rocketmq]Fix a NPE problem when checkpoint.interval is set too small(#6624) (#6625) | https://github.com/apache/seatunnel/commit/6e0c81d492 | 2.3.5 |
| [Test][E2E] Add thread leak check for connector (#5773) | https://github.com/apache/seatunnel/commit/1f2f3fc5f0 | 2.3.4 |
| [Fix][Connector] Rocketmq source startOffset greater than endOffset error (#6287) | https://github.com/apache/seatunnel/commit/cd44b5894e | 2.3.4 |
| [Improve][Common] Introduce new error define rule (#5793) | https://github.com/apache/seatunnel/commit/9d1b2582b2 | 2.3.4 |
[Improve] Remove use SeaTunnelSink::getConsumedType method and mark it as deprecated (#5755) | https://github.com/apache/seatunnel/commit/8de7408100 | 2.3.4 |
| [Improve][CheckStyle] Remove useless 'SuppressWarnings' annotation of checkstyle. (#5260) | https://github.com/apache/seatunnel/commit/51c0d709ba | 2.3.4 |
| [Improve][pom] Formatting pom (#4761) | https://github.com/apache/seatunnel/commit/1d6d3815ec | 2.3.2 |
| [Hotfix][Connector-V2][RocketMQ] Fix rocketmq spark e2e test cases (#4583) | https://github.com/apache/seatunnel/commit/e711f6ef4c | 2.3.2 |
| [Feature][Connector-V2] Add rocketmq source and sink (#4007) | https://github.com/apache/seatunnel/commit/e333897552 | 2.3.2 |