Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fr.juanwolf:mysql-binlog-replicator

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fr.juanwolf:mysql-binlog-replicator

Create the ORM between events received from the mysql-binlog-java library and spring repositories.

  • 1.0.8
  • Source
  • Maven
  • Socket score

Version published
Maintainers
1
Source

MySQL BinLog Replicator Build Status Coverage Status

This library will give you the ability to create a real time feeding from a mysql database to an ElasticSearch etc... (all repository available in spring which extend the CRUDRepository interface in fact)

Install

Maven

<dependency>
    <groupId>fr.juanwolf</groupId>
    <artifactId>mysql-binlog-replicator</artifactId>
    <version>1.0.7</version>
</dependency>

Setup the MYSQL server

First, configure your server to activate the replication.

To activate replication on the master, add this configuration to your mysql configuration file :

[mysqld]
server-id        = 1
log_bin          = /var/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size  = 100M
binlog-format    = row # important to detect write and update event.

WARNING :

As says in mysql-binlog-connector-java, Make sure that the user you're using has the REPLICATION SLAVE and REPLICATION CLIENT privileges.

Setup the mysql-binlog-replicator

Create a mysql-binlog-replicator.properties with the mysql configuration :

mysql.host=localhost
mysql.port=3306
# Tables that you want to track changes separated by commas
mysql.schema=user
# The package where you keep all your pojos
mysql.scanmapping=fr.juanwolf.mysqlbinlogreplicator.domain
# The user with replication access
mysql.user=replicator
# The password for the user with replication access
mysql.password=Bernard Lama

Setup modules configuration

ElasticSearch configuration

Make sure that you configured this variable to connect the service to your ElasticSearch :

spring.data.elasticsearch.cluster-nodes=localhost:9300

Create POJO's

Use @MysqlMapping

Make sure you're using the @MysqlMapping annotation. It will bind the pojo to a specific table name and to your dao (repository).

For example a class for accounts would look like :

@MysqlMapping(table = "user", repository="userRepository")
public class Account {
    @Id
    String id;

    @Field(type = FieldType.Long, index = FieldIndex.analyzed)
    long identifier;

    @Field(type = FieldType.String, index = FieldIndex.analyzed)
    String mail;

    @Field(index = FieldIndex.analyzed, type = FieldType.Date)
    Date creationDate;

    @Field(index = FieldIndex.analyzed, type = FieldType.Float)
    float cartAmount;

    public Account() {}

    public float getCartAmount() {
        return cartAmount;
    }

    public Date getCreationDate() {
        return creationDate;
    }

    public void setMail(String mail) {
        this.mail = mail;
    }

    public long getIdentifier() {
        return identifier;
    }
}

As you can see we keep the spring configuration for the elasticsearch repository AND the mysqlMapping annotation for the service.

Type Mapping

You can convert different SQL types to java types. Only this ones are available :

SQL typesJava typesConditions
DATEDateFor yyyy-MM-dd SQL format
DATETIMEDate
DATETIMEStringNeed date.output format in config file
TIMESTAMPsql.TimestampFor yyyy-MM-dd hh:mm:ss SQL format
TIMEsql.TimeFor hh:MM:ss SQL format
BITboolean
TINYboolean
INTint
LONGlong
FLOATfloat
VARCHARString
LONGTEXTString
TINYTEXTString

If you need any other mapping, please open issue.

Use the annotations for the repositories you'll use on your POJOs###

ElasticSearch

Add to your pojos annotations needed by the ElasticSearch Repository, example for the user class above :

@Document(indexName = "user")
@Mapping(mappingPath = "user")
@MysqlMapping(table = "user", repository="userRepository")
public class Account {
    ...
}

Create your main

  • Autowire the mysqlBinLogService
  • Create the main which call mysqlBinLogService.startReplication()
  • It should work (if not please open an issue or/and contribute :D)

How it works

Thanks to shykio and his mysql-binlog-connector-java, the mysql-binlog-replicator will detect every update of the binlog file from your mysqll server and then replicate it to your CRUD repository.

Example

You can find an example of how to use it here : mysql-binlog-replicator-example

Enhancement

The project does not support nested documents and does not apply indexes (could be a feature in next releases).

FAQs

Package last updated on 26 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc