Skip to content

willowHB/debezium-datetime-converter-master

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

参考大牛的源码 Debezium architecture

Build Status(https://github.com/holmofy/debezium-datetime-converter/actions/workflows/release.yml/badge.svg)

debezium-datetime-converter

Debezium custom converter is used to deal with mysql datetime type problems .

mysql binlog-connector debezium schema
date
(2021-01-28)
LocalDate
(2021-01-28)
Integer
(18655)
io.debezium.time.Date
time
(17:29:04)
Duration
(PT17H29M4S)
Long
(62944000000)
io.debezium.time.Time
timestamp
(2021-01-28 17:29:04)
ZonedDateTime
(2021-01-28T09:29:04Z)
String
(2021-01-28T09:29:04Z)
io.debezium.time.ZonedTimestamp
Datetime
(2021-01-28 17:29:04)
LocalDateTime
(2021-01-28T17:29:04)
Long
(1611854944000)
io.debezium.time.Timestamp

For details, please refer to this article

在此基础上,我对代码进行了改造,我需要把MySql的Datetime类型转成时间戳,即long类型数值,然后存入es.(其他类型也已修改,使用前,请充分测试!!!)

Usage

  1. Download the extended jar package and put it in the same level directory of the debezium plugin.或者debezium的lib目录下,当然debezium本身也是在plugin目录下的。

  2. In debezium-connector,如果想把时间转换成string类型的格式, Add the following configuration:

"connector.class": "io.debezium.connector.mysql.MySqlConnector",
# ...
"converters": "datetime",
"datetime.type": "com.darcytech.debezium.converter.MySqlDateTimeConverter",
"datetime.format": "yyyy-MM-dd",
"datetime.format.time": "HH:mm:ss",
"datetime.format.datetime": "yyyy-MM-dd HH:mm:ss",
"datetime.format.timestamp": "yyyy-MM-dd HH:mm:ss",
"datetime.format.timestamp.zone": "UTC+8"
  1. In debezium-connector, 如果想把时间转换成timestamp,Add the following configuration:
"connector.class": "io.debezium.connector.mysql.MySqlConnector",
# ...
"converters": "datetime",
"datetime.type": "com.darcytech.debezium.converter.MySqlDateTime2TimestampConverter",
"datetime.format": "yyyy-MM-dd",
"datetime.format.time": "HH:mm:ss",
"datetime.format.datetime": "yyyy-MM-dd HH:mm:ss",
"datetime.format.timestamp": "yyyy-MM-dd HH:mm:ss",
"datetime.format.timestamp.zone": "+08:00"

同步前mysql数据:(mysql时区:北京时间) image

同步后数据: image

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages