Skip to main content
Version: Next

RocketMQ

RocketMQ source connector

Support Apache RocketMQ Version

  • 4.9.0 or newer

Support These Engines

Spark
Flink
SeaTunnel Zeta

Key Features

Description

Reads messages from Apache RocketMQ topics. The connector can read one or more topics with one schema, or use tables_configs to read multiple topics with different schemas.

Source Options

NameTypeRequiredDefaultDescription
name.srv.addrStringyes-RocketMQ name server address, for example localhost:9876.
topicsStringno-Topic name list separated by commas, for example "topic_a,topic_b". Configure only one of topics, tables_configs, and table_list.
tables_configsListno-Multi-table read configuration. Each item must contain topics and can contain format, schema, tags, start.mode, start.mode.timestamp, start.mode.offsets, and ignore_parse_errors.
table_listListno-Deprecated. Use tables_configs instead.
tagsStringno-Tag list separated by commas. Only messages whose RocketMQ tag exactly matches one configured value are consumed.
acl.enabledBooleannofalseWhether to enable RocketMQ ACL authentication.
access.keyStringno-Access key. Required when acl.enabled is true.
secret.keyStringno-Secret key. Required when acl.enabled is true.
batch.sizeintno100Maximum number of messages pulled each time.
consumer.groupStringnoSeaTunnel-Consumer-GroupRocketMQ consumer group ID.
commit.on.checkpointBooleannotrueWhether to commit offsets when SeaTunnel checkpoints are completed.
schemaconfigno-Message schema. See Schema Feature. If omitted, the connector reads message bodies as text.
formatStringnojsonMessage format. Supported values are json and text.
field.delimiterStringno,Field delimiter used when format = text.
start.modeStringnoCONSUME_FROM_GROUP_OFFSETSStartup position. Supported values: CONSUME_FROM_LAST_OFFSET, CONSUME_FROM_FIRST_OFFSET, CONSUME_FROM_GROUP_OFFSETS, CONSUME_FROM_TIMESTAMP, CONSUME_FROM_SPECIFIC_OFFSETS.
start.mode.offsetsMapno-Required when start.mode = CONSUME_FROM_SPECIFIC_OFFSETS. The key format is topic-queueId, for example test_topic-0.
start.mode.timestampLongno-Required when start.mode = CONSUME_FROM_TIMESTAMP. Use a millisecond timestamp.
partition.discovery.interval.millislongno-1Topic and partition discovery interval in milliseconds. -1 disables dynamic discovery.
ignore_parse_errorsBooleannofalseWhether to skip JSON messages that cannot be parsed.
consumer.poll.timeout.millislongno5000Pull timeout in milliseconds.
common-optionsconfigno-Source common options. See Source Common Options.

Option Notes

Startup Position

start.mode controls where the source starts reading:

  • CONSUME_FROM_GROUP_OFFSETS: start from committed offsets of the consumer group.
  • CONSUME_FROM_FIRST_OFFSET: start from the earliest available offset.
  • CONSUME_FROM_LAST_OFFSET: start from the latest available offset.
  • CONSUME_FROM_TIMESTAMP: start from the first offset at or after start.mode.timestamp.
  • CONSUME_FROM_SPECIFIC_OFFSETS: start from the offsets in start.mode.offsets.

When start.mode = CONSUME_FROM_TIMESTAMP, start.mode.timestamp must be a non-negative millisecond timestamp and cannot be later than the current time of the running job.

start.mode = "CONSUME_FROM_SPECIFIC_OFFSETS"
start.mode.offsets = {
test_topic-0 = 50
}
start.mode = "CONSUME_FROM_TIMESTAMP"
start.mode.timestamp = 1667179890315

Message Format

When format = json, define schema so that SeaTunnel can parse the JSON message body into typed fields. ignore_parse_errors = true can be used to skip invalid JSON messages instead of failing the job.

When format = text, SeaTunnel splits the message body by field.delimiter and maps the values to fields in schema order. If schema is omitted, the message body is read as a single text value.

Tags

tags uses a comma-separated list such as tag_a,tag_b. The connector compares the pulled message tag with these values, so do not use RocketMQ tag expression syntax such as tag_a || tag_b here. In multi-table jobs, each tables_configs entry can set its own tags filter.

Multi-Table Read

Use tables_configs when different topics have different schemas. Each item must contain topics and can define its own schema, format, tags, and startup position. If schema.table is not set, the output table name defaults to the topic name.

topics, tables_configs, and the deprecated table_list are mutually exclusive. In tables_configs, options that are not set on an item inherit the top-level defaults, so each item only needs to override the topic-specific schema, tags, or startup position.

When a tables_configs item uses start.mode = CONSUME_FROM_TIMESTAMP, it must also set start.mode.timestamp. When it uses start.mode = CONSUME_FROM_SPECIFIC_OFFSETS, it must also set a non-empty start.mode.offsets map.

Task Examples

Read JSON Messages

env {
parallelism = 1
job.mode = "BATCH"
}

source {
Rocketmq {
name.srv.addr = "rocketmq-e2e:9876"
topics = "test_topic_json"
plugin_output = "rocketmq_table"
format = json
schema = {
fields {
id = bigint
c_string = string
c_int = int
c_timestamp = timestamp
}
}
}
}

sink {
Console {
plugin_input = "rocketmq_table"
}
}

Read Text Messages With Tags

env {
parallelism = 1
job.mode = "BATCH"
}

source {
Rocketmq {
name.srv.addr = "rocketmq-e2e:9876"
topics = "test_topic_text"
plugin_output = "rocketmq_table"
format = text
field.delimiter = ","
tags = "tag_a,tag_b"
schema = {
fields {
id = bigint
content = string
}
}
}
}

sink {
Console {
plugin_input = "rocketmq_table"
}
}

Read From Specific Offsets

env {
parallelism = 1
job.mode = "BATCH"
}

source {
Rocketmq {
name.srv.addr = "rocketmq-e2e:9876"
topics = "test_topic_source"
plugin_output = "rocketmq_table"
format = json
start.mode = "CONSUME_FROM_SPECIFIC_OFFSETS"
start.mode.offsets = {
test_topic_source-0 = 50
}
schema = {
fields {
id = bigint
}
}
}
}

sink {
Console {
plugin_input = "rocketmq_table"
}
}

Read Multiple Topics With Different Schemas

env {
parallelism = 1
job.mode = "BATCH"
}

source {
Rocketmq {
name.srv.addr = "rocketmq-e2e:9876"
start.mode = "CONSUME_FROM_LAST_OFFSET"
tables_configs = [
{
topics = "test_topic_multi_a"
start.mode = "CONSUME_FROM_FIRST_OFFSET"
format = json
schema = {
fields {
id = bigint
c_string = string
}
}
},
{
topics = "test_topic_multi_b"
start.mode = "CONSUME_FROM_FIRST_OFFSET"
tags = "tag_b"
format = json
schema = {
table = "rocketmq_multi_custom"
fields {
id = bigint
description = string
}
}
}
]
}
}

sink {
Console {}
}

Read From a Timestamp

env {
parallelism = 1
job.mode = "BATCH"
}

source {
Rocketmq {
name.srv.addr = "rocketmq-e2e:9876"
topics = "test_topic_source"
plugin_output = "rocketmq_table"
format = json
start.mode = "CONSUME_FROM_TIMESTAMP"
start.mode.timestamp = 1667179890315
schema = {
fields {
id = bigint
}
}
}
}

sink {
Console {
plugin_input = "rocketmq_table"
}
}

Changelog

Change Log
ChangeCommitVersion
[Improve][API] Optimize the enumerator API semantics and reduce lock calls at the connector level (#9671)https://github.com/apache/seatunnel/commit/9212a771402.3.12
[improve] rocketmq options (#9251)https://github.com/apache/seatunnel/commit/4cbe3b91722.3.12
[Feature][Checkpoint] Add check script for source/sink state class serialVersionUID missing (#9118)https://github.com/apache/seatunnel/commit/4f5adeb1c72.3.11
[Improve][Connector-V2] RocketMQ Source add message tag config (#8825)https://github.com/apache/seatunnel/commit/5913e8c35f2.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/701f17b5d42.3.10
[Improve][Connector-V2] RocketMQ Sink add message tag config (#7996)https://github.com/apache/seatunnel/commit/97a1b00e482.3.9
[Feature][Restapi] Allow metrics information to be associated to logical plan nodes (#7786)https://github.com/apache/seatunnel/commit/6b7c53d03c2.3.9
[Fix][Connector-V2] Fix some throwable error not be caught (#7657)https://github.com/apache/seatunnel/commit/e19d73282e2.3.8
[Feature][Kafka] Support multi-table source read (#5992)https://github.com/apache/seatunnel/commit/60104602d12.3.6
[Fix][connector-rocketmq] commit a correct offset to broker & reduce ThreadInterruptedException log (#6668)https://github.com/apache/seatunnel/commit/b7480e1a892.3.6
[fix][connector-rocketmq]Fix a NPE problem when checkpoint.interval is set too small(#6624) (#6625)https://github.com/apache/seatunnel/commit/6e0c81d4922.3.5
[Test][E2E] Add thread leak check for connector (#5773)https://github.com/apache/seatunnel/commit/1f2f3fc5f02.3.4
[Fix][Connector] Rocketmq source startOffset greater than endOffset error (#6287)https://github.com/apache/seatunnel/commit/cd44b5894e2.3.4
[Improve][Common] Introduce new error define rule (#5793)https://github.com/apache/seatunnel/commit/9d1b2582b22.3.4
[Improve] Remove use SeaTunnelSink::getConsumedType method and mark it as deprecated (#5755)https://github.com/apache/seatunnel/commit/8de74081002.3.4
[Improve][CheckStyle] Remove useless 'SuppressWarnings' annotation of checkstyle. (#5260)https://github.com/apache/seatunnel/commit/51c0d709ba2.3.4
[Improve][pom] Formatting pom (#4761)https://github.com/apache/seatunnel/commit/1d6d3815ec2.3.2
[Hotfix][Connector-V2][RocketMQ] Fix rocketmq spark e2e test cases (#4583)https://github.com/apache/seatunnel/commit/e711f6ef4c2.3.2
[Feature][Connector-V2] Add rocketmq source and sink (#4007)https://github.com/apache/seatunnel/commit/e3338975522.3.2