Skip to content

Commit bc7e230

Browse files
authored
Updated readme.md after shyiko#141 repo structure changes
1 parent 3709c96 commit bc7e230

File tree

1 file changed

+93
-46
lines changed

1 file changed

+93
-46
lines changed

readme.md

+93-46
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1-
# mysql-binlog-connector-java [![Build Status](https://travis-ci.org/shyiko/mysql-binlog-connector-java.png?branch=master)](https://travis-ci.org/shyiko/mysql-binlog-connector-java) [![Coverage Status](https://coveralls.io/repos/shyiko/mysql-binlog-connector-java/badge.png?branch=master)](https://coveralls.io/r/shyiko/mysql-binlog-connector-java?branch=master)
1+
# mysql-binlog-connector-java [![Build Status](https://travis-ci.org/shyiko/mysql-binlog-connector-java.svg?branch=master)](https://travis-ci.org/shyiko/mysql-binlog-connector-java) [![Coverage Status](https://coveralls.io/repos/shyiko/mysql-binlog-connector-java/badge.svg?branch=master)](https://coveralls.io/r/shyiko/mysql-binlog-connector-java?branch=master) [![Maven Central](http://img.shields.io/badge/maven_central-0.7.3-blue.svg?style=flat)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.github.shyiko%22%20AND%20a%3A%22mysql-binlog-connector-java%22)
22

33
MySQL Binary Log connector.
44

5-
Initially project was started as a fork of [open-replicator](https://code.google.com/p/open-replicator), but ended up as a complete rewrite. Key differences/features:
5+
Initially project was started as a fork of [open-replicator](https://code.google.com/p/open-replicator),
6+
but ended up as a complete rewrite. Key differences/features:
67

7-
- automatic binlog filename/position resolution
8+
- automatic binlog filename/position | GTID resolution
89
- resumable disconnects
910
- plugable failover strategies
10-
- JMX exposure (optionally with statistics)
11+
- binlog_checksum=CRC32 support (for MySQL 5.6.2+ users)
12+
- secure communication over the TLS
13+
- JMX-friendly
14+
- real-time stats
1115
- availability in Maven Central
1216
- no third-party dependencies
13-
- binlog_checksum support (for MySQL 5.6.2+ users)
1417
- test suite over different versions of MySQL releases
1518

19+
> If you are looking for something similar in other languages - check out
20+
[siddontang/go-mysql](https://github.com/siddontang/go-mysql) (Go),
21+
[noplay/python-mysql-replication](https://github.com/noplay/python-mysql-replication) (Python).
22+
1623
## Usage
1724

1825
Get the latest JAR(s) from [here](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.github.shyiko%22%20AND%20a%3A%22mysql-binlog-connector-java%22). Alternatively you can include following Maven dependency (available through Maven Central):
@@ -21,36 +28,11 @@ Get the latest JAR(s) from [here](http://search.maven.org/#search%7Cga%7C1%7Cg%3
2128
<dependency>
2229
<groupId>com.github.shyiko</groupId>
2330
<artifactId>mysql-binlog-connector-java</artifactId>
24-
<version>0.2.2</version>
31+
<version>0.7.3</version>
2532
</dependency>
2633
```
2734

28-
The latest development version always available through Sonatype Snapshots repository (as shown below).
29-
30-
```xml
31-
<dependencies>
32-
<dependency>
33-
<groupId>com.github.shyiko</groupId>
34-
<artifactId>mysql-binlog-connector-java</artifactId>
35-
<version>0.2.3-SNAPSHOT</version>
36-
</dependency>
37-
</dependencies>
38-
39-
<repositories>
40-
<repository>
41-
<id>sonatype-snapshots</id>
42-
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
43-
<snapshots>
44-
<enabled>true</enabled>
45-
</snapshots>
46-
<releases>
47-
<enabled>false</enabled>
48-
</releases>
49-
</repository>
50-
</repositories>
51-
```
52-
53-
### Reading Binary Log file
35+
#### Reading binary log file
5436

5537
```java
5638
File binlogFile = ...
@@ -64,7 +46,7 @@ try {
6446
}
6547
```
6648

67-
### Tapping into MySQL replication stream
49+
#### Tapping into MySQL replication stream
6850

6951
> PREREQUISITES: Whichever user you plan to use for the BinaryLogClient, he MUST have [REPLICATION SLAVE](http://dev.mysql.com/doc/refman/5.5/en/privileges-provided.html#priv_replication-slave) privilege. Unless you specify binlogFilename/binlogPosition yourself (in which case automatic resolution won't kick in), you'll need [REPLICATION CLIENT](http://dev.mysql.com/doc/refman/5.5/en/privileges-provided.html#priv_replication-client) granted as well.
7052
@@ -86,7 +68,13 @@ kick off from a specific filename or position, use `client.setBinlogFilename(fil
8668
> `client.connect()` is blocking (meaning that client will listen for events in the current thread).
8769
`client.connect(timeout)`, on the other hand, spawns a separate thread.
8870

89-
### Controlling event deserialization
71+
#### Controlling event deserialization
72+
73+
> You might need it for several reasons:
74+
you don't want to waste time deserializing events you won't need;
75+
there is no EventDataDeserializer defined for the event type you are interested in (or there is but it contains a bug);
76+
you want certain type of events to be deserialized in a different way (perhaps *RowsEventData should contain table
77+
name and not id?); etc.
9078

9179
```java
9280
EventDeserializer eventDeserializer = new EventDeserializer();
@@ -109,7 +97,7 @@ BinaryLogClient client = ...
10997
client.setEventDeserializer(eventDeserializer);
11098
```
11199

112-
### Making client available through JMX
100+
#### Exposing BinaryLogClient through JMX
113101

114102
```java
115103
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
@@ -125,19 +113,84 @@ ObjectName statsObjectName = new ObjectName("mysql.binlog:type=BinaryLogClientSt
125113
mBeanServer.registerMBean(stats, statsObjectName);
126114
```
127115

116+
#### Using SSL
117+
118+
> Introduced in 0.4.0.
119+
120+
TLSv1.1 & TLSv1.2 require [JDK 7](http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6916074)+.
121+
Prior to MySQL 5.7.10, MySQL supported only TLSv1
122+
(see [Secure Connection Protocols and Ciphers](http://dev.mysql.com/doc/refman/5.7/en/secure-connection-protocols-ciphers.html)).
123+
124+
> To check that MySQL server is [properly configured with SSL support](http://dev.mysql.com/doc/refman/5.7/en/using-secure-connections.html) -
125+
`mysql -h host -u root -ptypeyourpasswordmaybe -e "show global variables like 'have_%ssl';"` ("Value"
126+
should be "YES"). State of the current session can be determined using `\s` ("SSL" should not be blank).
127+
128+
```java
129+
System.setProperty("javax.net.ssl.trustStore", "/path/to/truststore.jks");
130+
System.setProperty("javax.net.ssl.trustStorePassword","truststore.password");
131+
System.setProperty("javax.net.ssl.keyStore", "/path/to/keystore.jks");
132+
System.setProperty("javax.net.ssl.keyStorePassword", "keystore.password");
133+
134+
BinaryLogClient client = ...
135+
client.setSSLMode(SSLMode.VERIFY_IDENTITY);
136+
```
137+
128138
## Implementation notes
129139

130-
- data of numeric types (tinyint, etc) always returned signed(!) regardless of whether column definition includes "unsigned" keyword or not
131-
- data of \*text/\*blob types always returned as a byte array
140+
- data of numeric types (tinyint, etc) always returned signed(!) regardless of whether column definition includes "unsigned" keyword or not.
141+
- data of var\*/\*text/\*blob types always returned as a byte array (for var\* this is true starting from 1.0.0).
132142

133143
## Frequently Asked Questions
134144

135-
Q: How do I get column names of a table?
136-
A: The easiest way is to use JDBC (as described [here](https://github.com/shyiko/mysql-binlog-connector-java/issues/24#issuecomment-43747417)). Binary log itself does not contain that piece of information.
145+
**Q**. How does a typical transaction look like?
146+
147+
**A**. GTID event (if gtid_mode=ON) -> QUERY event with "BEGIN" as sql -> ... -> XID event | QUERY event with "COMMIT" or "ROLLBACK" as sql.
148+
149+
**Q**. EventData for inserted/updated/deleted rows has no information about table (except for some weird id).
150+
How do I make sense out of it?
151+
152+
**A**. Each [WriteRowsEventData](https://github.com/shyiko/mysql-binlog-connector-java/blob/master/src/main/java/com/github/shyiko/mysql/binlog/event/WriteRowsEventData.java)/[UpdateRowsEventData](https://github.com/shyiko/mysql-binlog-connector-java/blob/master/src/main/java/com/github/shyiko/mysql/binlog/event/UpdateRowsEventData.java)/[DeleteRowsEventData](https://github.com/shyiko/mysql-binlog-connector-java/blob/master/src/main/java/com/github/shyiko/mysql/binlog/event/DeleteRowsEventData.java) event is preceded by [TableMapEventData](https://github.com/shyiko/mysql-binlog-connector-java/blob/master/src/main/java/com/github/shyiko/mysql/binlog/event/TableMapEventData.java) which
153+
contains schema & table name. If for some reason you need to know column names (types, etc). - the easiest way is to
154+
155+
```sql
156+
select TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, ORDINAL_POSITION, COLUMN_DEFAULT, IS_NULLABLE,
157+
DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, CHARACTER_OCTET_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE,
158+
CHARACTER_SET_NAME, COLLATION_NAME from INFORMATION_SCHEMA.COLUMNS;
159+
# see https://dev.mysql.com/doc/refman/5.6/en/columns-table.html for more information
160+
```
161+
162+
(yes, binary log DOES NOT include that piece of information).
163+
164+
You can find JDBC snippet [here](https://github.com/shyiko/mysql-binlog-connector-java/issues/24#issuecomment-43747417).
137165

138166
## Documentation
139167

140-
For the insight into the internals of MySQL look [here](https://dev.mysql.com/doc/internals/en/index.html). [MySQL Client/Server Protocol](http://dev.mysql.com/doc/internals/en/client-server-protocol.html) and [The Binary Log](http://dev.mysql.com/doc/internals/en/binary-log.html) sections are particularly useful as a reference documentation for the `com.**.mysql.binlog.network` and `com.**.mysql.binlog.event` packages.
168+
#### API overview
169+
170+
There are two entry points - [BinaryLogClient](https://github.com/shyiko/mysql-binlog-connector-java/blob/master/src/main/java/com/github/shyiko/mysql/binlog/BinaryLogClient.java) (which you can use to read binary logs from a MySQL server) and
171+
[BinaryLogFileReader](https://github.com/shyiko/mysql-binlog-connector-java/blob/master/src/main/java/com/github/shyiko/mysql/binlog/BinaryLogFileReader.java) (for offline log processing). Both of them rely on [EventDeserializer](https://github.com/shyiko/mysql-binlog-connector-java/blob/master/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/EventDeserializer.java) to deserialize
172+
stream of events. Each [Event](https://github.com/shyiko/mysql-binlog-connector-java/blob/master/src/main/java/com/github/shyiko/mysql/binlog/event/Event.java) consists of [EventHeader](https://github.com/shyiko/mysql-binlog-connector-java/blob/master/src/main/java/com/github/shyiko/mysql/binlog/event/EventHeader.java) (containing among other things reference to [EventType](https://github.com/shyiko/mysql-binlog-connector-java/blob/master/src/main/java/com/github/shyiko/mysql/binlog/event/EventType.java)) and
173+
[EventData](https://github.com/shyiko/mysql-binlog-connector-java/blob/master/src/main/java/com/github/shyiko/mysql/binlog/event/EventData.java). The aforementioned EventDeserializer has one [EventHeaderDeserializer](https://github.com/shyiko/mysql-binlog-connector-java/blob/master/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/EventHeaderDeserializer.java) ([EventHeaderV4Deserializer](https://github.com/shyiko/mysql-binlog-connector-java/blob/master/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/EventHeaderV4Deserializer.java) by default)
174+
and [a collection of EventDataDeserializer|s](https://github.com/shyiko/mysql-binlog-connector-java/blob/master/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/EventDeserializer.java#L82). If there is no EventDataDeserializer registered for
175+
some particular type of Event - default EventDataDeserializer kicks in ([NullEventDataDeserializer](https://github.com/shyiko/mysql-binlog-connector-java/blob/master/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/NullEventDataDeserializer.java)).
176+
177+
#### MySQL Internals Manual
178+
179+
For the insight into the internals of MySQL look [here](https://dev.mysql.com/doc/internals/en/index.html). [MySQL Client/Server Protocol](http://dev.mysql.com/doc/internals/en/client-server-protocol.html) and [The Binary Log](http://dev.mysql.com/doc/internals/en/binary-log.html) sections are particularly useful as a reference documentation for the `**.binlog.network` and `**.binlog.event` packages.
180+
181+
## Real-world applications
182+
183+
Some of the OSS using / built on top of mysql-binlog-conector-java:
184+
* [debezium](https://github.com/debezium/debezium) A low latency data streaming platform for change data capture (CDC).
185+
* [mavenlink/changestream](https://github.com/mavenlink/changestream) - A stream of changes for MySQL built on Akka.
186+
* [mardambey/mypipe](https://github.com/mardambey/mypipe) MySQL binary log consumer with the ability to act on changed rows and publish changes to different systems with emphasis on Apache Kafka.
187+
* [ngocdaothanh/mydit](https://github.com/ngocdaothanh/mydit) MySQL to MongoDB data replicator.
188+
* [sharetribe/dumpr](https://github.com/sharetribe/dumpr) A Clojure library for live replicating data from a MySQL database.
189+
* [shyiko/rook](https://github.com/shyiko/rook) Generic Change Data Capture (CDC) toolkit.
190+
* [streamsets/datacollector](https://github.com/streamsets/datacollector) Continuous big data ingestion infrastructure.
191+
* [twingly/ecco](https://github.com/twingly/ecco) MySQL replication binlog parser in JRuby.
192+
193+
It's also used [on a large scale](https://twitter.com/atwinmutt/status/626816601078300672) in MailChimp. You can read about it [here](http://devs.mailchimp.com/blog/powering-mailchimp-pro-reporting/).
141194

142195
## Development
143196

@@ -147,12 +200,6 @@ cd mysql-binlog-connector-java
147200
mvn # shows how to build, test, etc. project
148201
```
149202

150-
## Used by
151-
152-
* [shyiko/rook](https://github.com/shyiko/rook) - Change Data Capture (CDC) toolkit for keeping system layers in sync with the database.
153-
* [ngocdaothanh/mydit](https://github.com/ngocdaothanh/mydit) - MySQL to MongoDB data replicator.
154-
* [mardambey/mypipe](https://github.com/mardambey/mypipe) - MySQL binary log consumer with the ability to act on changed rows and publish changes to different systems with emphasis on Apache Kafka.
155-
156203
## Contributing
157204

158205
In lieu of a formal styleguide, please take care to maintain the existing coding style.

0 commit comments

Comments
 (0)