mysql-binlog-stream-shared


License

License

MIT
Categories

Categories

MySQL Data Databases
GroupId

GroupId

io.laserdisc
ArtifactId

ArtifactId

mysql-binlog-stream-shared_2.12
Last Version

Last Version

0.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

mysql-binlog-stream-shared
mysql-binlog-stream-shared
Project URL

Project URL

https://github.com/laserdisc-io/fs2-aws
Project Organization

Project Organization

io.laserdisc
Source Code Management

Source Code Management

https://github.com/laserdisc-io/mysql-binlog-stream

Download mysql-binlog-stream-shared_2.12

How to add to project

<!-- https://jarcasting.com/artifacts/io.laserdisc/mysql-binlog-stream-shared_2.12/ -->
<dependency>
    <groupId>io.laserdisc</groupId>
    <artifactId>mysql-binlog-stream-shared_2.12</artifactId>
    <version>0.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.laserdisc/mysql-binlog-stream-shared_2.12/
implementation 'io.laserdisc:mysql-binlog-stream-shared_2.12:0.2.0'
// https://jarcasting.com/artifacts/io.laserdisc/mysql-binlog-stream-shared_2.12/
implementation ("io.laserdisc:mysql-binlog-stream-shared_2.12:0.2.0")
'io.laserdisc:mysql-binlog-stream-shared_2.12:jar:0.2.0'
<dependency org="io.laserdisc" name="mysql-binlog-stream-shared_2.12" rev="0.2.0">
  <artifact name="mysql-binlog-stream-shared_2.12" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.laserdisc', module='mysql-binlog-stream-shared_2.12', version='0.2.0')
)
libraryDependencies += "io.laserdisc" % "mysql-binlog-stream-shared_2.12" % "0.2.0"
[io.laserdisc/mysql-binlog-stream-shared_2.12 "0.2.0"]

Dependencies

compile (5)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.12.11
io.circe : circe-core_2.12 jar 0.13.0
io.circe : circe-generic_2.12 jar 0.13.0
io.circe : circe-parser_2.12 jar 0.13.0
org.typelevel : cats-effect_2.12 jar 2.3.1

test (6)

Group / Artifact Type Version
org.scalamock : scalamock_2.12 jar 5.1.0
org.scalatest : scalatest_2.12 jar 3.2.3
com.dimafeng : testcontainers-scala_2.12 jar 0.38.8
org.testcontainers : mysql jar 1.15.1
org.testcontainers : testcontainers jar 1.15.1
io.circe : circe-optics_2.12 jar 0.13.0

Project Modules

There are no modules declared in this project.

Motivation

Stream in real-time the MySQL database events, such as CRUD and DDL. That may be useful for building Data Warehouse, integration with monolith application on the database level, etc.

Example

MysqlBinlogStream
              .rawEvents[IO](binlogClient)
              .through(streamEvents[IO](transactionState))
              .evalTap(msg => logger.info(s"received $msg"))

Refer to examples for complete snippet

How to build and launch example

  • build docker image
sbt "project mysql-binlog-stream-examples" clean  "docker:publishLocal"
  • run docker compose with MySql and example service
cd mysql-binlog-stream-examples
docker-compose -f docker-compose-mysql-it-mac.yaml up
  • open new console
  • in new console
mysql -u 'root' --host=0.0.0.0 --port=3307 --password=''
  • try to insert new row in SKU or VARIANT table
use test;
insert into sku(id, sku) values(3, '123');
  • in the docker-compose console you should see
example_1  | 02:35:58.734 [ioapp-compute-2] INFO application - received EventMessage(sku,1589596558000,create,8908ecfb63e4-bin.000007,415,true,{
example_1  |   "id" : 3
example_1  | },{
example_1  |   "before" : null,
example_1  |   "after" : {
example_1  |     "id" : 3,
example_1  |     "sku" : "123"
example_1  |   }
example_1  | })

try to update some row and see what happens

Event examples

Create:

{
  "table" : "sku",
  "timestamp" : 1554754028000,
  "action" : "create",
  "fileName" : "acd03b3a873f-bin.000003",
  "offset" : 2177,
  "endOfTransaction" : false,
  "pk" : {
    "id" : 5
  },
  "row" : {
    "before" : null,
    "after" : {
      "id" : 5,
      "sku" : "sku5"
    }
  }
}

Update:

{
  "table" : "sku",
  "timestamp" : 1554754028000,
  "action" : "create",
  "fileName" : "acd03b3a873f-bin.000003",
  "offset" : 2177,
  "endOfTransaction" : false,
  "pk" : {
    "id" : 5
  },
  "row" : {
    "before" : {
      "id" : 5,
      "sku" : "sku5"
    },
    "after" : {
      "id" : 5,
      "sku" : "new sku 5"
    }
  }
}

Delete:

{
  "table" : "sku",
  "timestamp" : 1554754028000,
  "action" : "create",
  "fileName" : "acd03b3a873f-bin.000003",
  "offset" : 2177,
  "endOfTransaction" : false,
  "pk" : {
    "id" : 5
  },
  "row" : {
    "before" : {
      "id" : 5,
      "sku" : "new sku 5"
    },
    "after" : null
  }
}

Truncate:

{
  "table" : "sku",
  "timestamp" : 1554754028000,
  "action" : "truncate",
  "fileName" : "acd03b3a873f-bin.000003",
  "offset" : 2497,
  "endOfTransaction" : true,
  "pk" : null,
  "row" : null
}

Tech Stack

  • Scala
  • FS2 Functional Streams for Scala
  • circe - json streaming encoder/decoder
  • doobie - database integration layer

Support

YourKit Image

This project is supported by YourKit with monitoring and profiling Tools. YourKit supports open source with innovative and intelligent tools for monitoring and profiling Java and .NET applications. YourKit is the creator of YourKit Java Profiler, YourKit .NET Profiler, and YourKit YouMonitor.

io.laserdisc

Versions

Version
0.2.0
0.1.9
0.1.8
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0