Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@GuangYaoLee92
Copy link
Contributor

issue: #2173
canal 向 mq 发送消息时,可以根据不同的 topic 配置相应的 partitionNum

在 instance.properties 配置文件中新增如下配置项:

#canal.mq.dynamicTopicPartitionNum=test.*:4,mycanal:6

支持以正则表达式的方式,为不同的 topic 指定专属 partitionNum
一条规则中,分号前是 topic 或者 topic 的正则表达式,分号后是 partitionNum
多条规则以逗号分隔
大家可以结合自己的业务需求,设置匹配规则,多条匹配规则之间是按照顺序进行匹配(命中一条规则就返回)

例子1: test.*:4,mycanal:6 前缀为test的topic分区数是4,topic mycanal指定分区数为6
例子2: test1|mycanal:6 指定 topic test1 或者 topic mycanal 分区数为6
例子3: 匹配规则啥都不写,或者未匹配上,则 topic 的默认分区数是 canal.mq.partitionsNum

@GuangYaoLee92
Copy link
Contributor Author

@rewerma @agapple 管理员们好,这是一个支持为 kafka/RocketMQ 的不同 topic 以正则的方式设置不同分区数的pr。烦请管理员大大百忙之中抽空 review 一下~

@mhfc007
Copy link

mhfc007 commented Feb 24, 2020

各位好,这儿能不能不指定分区数目。

Kafka的API中 可以指定写入哪个分区
但是如果不指定,客户端会自动根据key算出来写到那个分区,目前是必须配置。

final int partition = canalDestination.getPartition() != null ? canalDestination.getPartition() : 0;

在这儿看到的是 没有设置分区 就写到第0个分区

这样做的目的是 保证消息顺序么?

@agapple
Copy link
Member

agapple commented Feb 28, 2020

@GuangYaoLee92 挺好的想法,目前MQ结构做了下SPI设计,代码和现在的结构略有冲突,请先解决一下冲突

@codecov-io
Copy link

codecov-io commented Feb 29, 2020

Codecov Report

Merging #2479 into master will increase coverage by 0.11%.
The diff coverage is 0.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##             master   #2479      +/-   ##
===========================================
+ Coverage      4.77%   4.89%   +0.11%     
  Complexity      239     239              
===========================================
  Files           392     365      -27     
  Lines         35614   34624     -990     
  Branches       5546    5392     -154     
===========================================
- Hits           1702    1694       -8     
+ Misses        33663   32681     -982     
  Partials        249     249              
Impacted Files Coverage Δ Complexity Δ
...ibaba/otter/canal/instance/core/CanalMQConfig.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...com/alibaba/otter/canal/common/MQMessageUtils.java 0.00% <0.00%> (ø) 0.00 <0.00> (?)
...a/com/alibaba/otter/canal/common/MQProperties.java 0.00% <0.00%> (ø) 0.00 <0.00> (?)
.../alibaba/otter/canal/kafka/CanalKafkaProducer.java 0.00% <0.00%> (ø) 0.00 <0.00> (?)
...ba/otter/canal/rocketmq/CanalRocketMQProducer.java 0.00% <0.00%> (ø) 0.00 <0.00> (?)
...com/alibaba/otter/canal/server/CanalMQStarter.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...al/parse/inbound/mysql/tsdb/DatabaseTableMeta.java 14.36% <0.00%> (-0.05%) 21.00% <0.00%> (ø%)
...a/com/alibaba/otter/canal/filter/PatternUtils.java 50.00% <0.00%> (ø) 0.00% <0.00%> (ø%)
...aba/otter/canal/prometheus/impl/SinkCollector.java 0.00% <0.00%> (ø) 0.00% <0.00%> (ø%)
... and 72 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 30a1b06...33d8c6a. Read the comment docs.

@GuangYaoLee92 GuangYaoLee92 force-pushed the master branch 2 times, most recently from fd2f2da to 3643588 Compare March 1, 2020 02:38
@GuangYaoLee92
Copy link
Contributor Author

@agapple 冲突已解决,殷盼管理员百忙之中抽空 review 一下。

@CLAassistant
Copy link

CLA assistant check
All committers have signed the CLA.

@agapple agapple force-pushed the master branch 2 times, most recently from bef08c8 to b79af46 Compare August 22, 2020 05:07
@agapple agapple merged commit b81e9df into alibaba:master Aug 22, 2020
@agapple
Copy link
Member

agapple commented Aug 22, 2020

tks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants