ecco 0.2.0-java → 0.3.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 157c4e03dee92292c296a3f0b0e975df321f2f34
4
- data.tar.gz: f68e4c333a01a822fbecc0d6e4b201e463e2ac35
3
+ metadata.gz: 6f4a0245571c04cc31f3cc7947a554f54887b53d
4
+ data.tar.gz: 2241f6cbe3c33667307800674d0946eda93b98c2
5
5
  SHA512:
6
- metadata.gz: 2b2587a55fbcc9995da5859b945d571940b9ebee4fbe3388ac659090d716164ca9a304d50cc1eb2430f42e28aa6c858c91b9ff5b2d997f5ddced45c78c038615
7
- data.tar.gz: 3210701a7f2a2125f522e6ac8b47fa032198af10e03422f660c252532e15b128141142cd978e5dff2c416b7e482d9a548553f536a112db99a39b587457666489
6
+ metadata.gz: cd75f05d92a2b859e18bb17d0b4634f8fbe0040dce4186c14663992f2dd3e3ce7cb3a8a15b7929420cbf4c41c786257f5a6ec295548c0d9c857f46d8c8f4bd07
7
+ data.tar.gz: a3d63407dad5620630f5310fbf57a266ca7872622ae4ceb80c7a48b70fd69a4d460bc4062a45d8cca2ea3ba5a6fb354df8ae3308ba66d36ec0a4352363d73088
data/.travis.yml CHANGED
@@ -1,4 +1,13 @@
1
1
  language: ruby
2
- rvm:
3
- - 2.2.3
4
2
  before_install: gem install bundler -v 1.10.6
3
+ notifications:
4
+ email: false
5
+ hipchat:
6
+ on_success: never
7
+ on_failure: change
8
+ template:
9
+ - '%{repository}#%{build_number} (%{branch} - %{commit} : %{author}): %{message}
10
+ (<a href="%{build_url}">Details</a>/<a href="%{compare_url}">Change view</a>)'
11
+ format: html
12
+ rooms:
13
+ secure: J7yYVGr6NQ0rOA6WdOVxiB4XxPJJDcQG7R0fgAXxtAzQNun+QHLBH9Yu7NN7kaJrVU69oIMrAw2e7EGSh9mnQ3fmGyA/z9Xu5+3GYjGuN3QDLGA8kbnDggIeo8vZrTZYL9aITVHMUH/6oKwAtg4Q5Tx4ftguj4zvMMWiZTFHuv05V0FgyoQkSggKLE3w8ZndEjZfaBbtgUeN/eGeAl2oeP8w53eM4ebh2+VNYNVGr+5zr1VGkkXz1SoRT3YEJtSjH0DvinZDrsU3VZZY9hIcUKu3dzhPuwZFMIDGshDxVqf/0XADOFUqgYFeHmg64O+ikIye4MiuBKw/miqSvx6lZSdjlsYyHruYFCbjcZue/WIKAw5nWZNQ+YZmzxMWZV4czImO8q2ljMOXUluVgW78mZMYsqzsoE5tX6PVO4I7aVL4L9mnb01nPDAPgJAXCGfudOkHfUi6jaVTkvLqSJvifbCzhsRvaPCA2VAQGUTssv9pm2YkCP5rOOeasU+XgJtLJif8Uv1g/zNjNajNU19A1PLCSNgdvX381Dgd3NS/DjMtNtgTXxGjSpHwQM54aL/lp6a2XhCpSpBZBcBz01KQJGsgLUgDDQJSzO1e8OdiP6YQHIGEA0OM4Wfoq2I3TLWMSlGSzJBvUBHJwstPMjTbH+1HM2AOY80orVHQWzttZlc=
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Ecco
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ecco`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ [![Build Status](https://travis-ci.org/twingly/ecco.svg?branch=master)](https://travis-ci.org/twingly/ecco)
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ MySQL replication binlog parser using [mysql-binlog-connector-java].
6
6
 
7
7
  ## Installation
8
8
 
@@ -22,22 +22,73 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ ```ruby
26
+ require "ecco"
27
+
28
+ hostname = "localhost" # Optional
29
+ port = 3306 # Optional
30
+ username = "username"
31
+ password = "password"
32
+
33
+ client = Ecco::Client.new(hostname: hostname, port: port, username: username, password: password)
34
+
35
+ client.on_row_event do |row_event|
36
+ type = row_event.type
37
+ database = row_event.database
38
+ table = row_event.table
39
+ rows = row_event.rows
40
+
41
+ next unless database == "FooDatabase"
42
+ next unless table == "FooTable"
43
+
44
+ second_column = rows.first[1]
45
+
46
+ puts "Row event: #{database} #{table} #{type} #{second_column}"
47
+ end
48
+
49
+ client.on_save_position do |filename, position|
50
+ puts "Save event: #{filename} #{position}"
51
+ end
52
+
53
+ # Optionally set a starting position
54
+ client.set_binlog_filename("mysql-bin.000009")
55
+ client.set_binlog_position(276753)
56
+
57
+ client.start
58
+ ```
26
59
 
27
60
  ## Development
28
61
 
29
- To download a new version of [mysql-binlog-connector-java](https://github.com/shyiko/mysql-binlog-connector-java).
62
+ To download a new version of [mysql-binlog-connector-java]
30
63
 
31
64
  rake maven:dependencies
32
65
 
33
- You need Maven.
66
+ Note: You need Maven to download
34
67
 
35
68
  brew install maven
36
69
 
37
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
70
+ Run the tests
71
+
72
+ jruby --dev -G -S rake
73
+
74
+ For an interactive prompt
75
+
76
+ bin/console
77
+
78
+ To install this gem onto your local machine
38
79
 
39
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
80
+ bundle exec rake install
81
+
82
+ ## Release
83
+
84
+ To release a new version, update the version number in `version.rb`, and then run
85
+
86
+ bundle exec rake release
87
+
88
+ which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
40
89
 
41
90
  ## License
42
91
 
43
92
  The gem is available as open source under the terms of the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0).
93
+
94
+ [mysql-binlog-connector-java]: https://github.com/shyiko/mysql-binlog-connector-java
data/lib/ecco.rb CHANGED
@@ -1,6 +1,2 @@
1
+ require "ecco/client"
1
2
  require "ecco/version"
2
- require "ext/mysql-binlog-connector-java-#{Ecco::MYSQL_BINLOG_CONNECTOR_VERSION}.jar"
3
-
4
- module Ecco
5
- # Your code goes here...
6
- end
@@ -0,0 +1,36 @@
1
+ require "ext/mysql-binlog-connector-java-#{Ecco::MYSQL_BINLOG_CONNECTOR_VERSION}.jar"
2
+ require "ecco/row_event_listener"
3
+ require "ecco/save_event_listener"
4
+
5
+ module Ecco
6
+ class Client
7
+ extend Forwardable
8
+ def_delegators :@client, :set_server_id, :get_server_id
9
+ def_delegators :@client, :set_binlog_filename, :get_binlog_filename
10
+ def_delegators :@client, :set_binlog_position, :get_binlog_position
11
+
12
+ java_import com.github.shyiko.mysql.binlog.BinaryLogClient
13
+
14
+ def initialize(hostname: "localhost", port: 3306, username:, password:)
15
+ @client = BinaryLogClient.new(hostname, port, username, password)
16
+
17
+ @save_event_listener = SaveEventListener.new(self)
18
+ @client.register_event_listener(@save_event_listener)
19
+
20
+ @row_event_listener = RowEventListener.new(self)
21
+ @client.register_event_listener(@row_event_listener)
22
+ end
23
+
24
+ def on_save_position(&block)
25
+ @save_event_listener.callback = block
26
+ end
27
+
28
+ def on_row_event(&block)
29
+ @row_event_listener.callback = block
30
+ end
31
+
32
+ def start
33
+ @client.connect
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,17 @@
1
+ module Ecco
2
+ class EventListener
3
+ include com.github.shyiko.mysql.binlog.BinaryLogClient::EventListener
4
+ java_import com.github.shyiko.mysql.binlog.event.EventType
5
+
6
+ attr_writer :callback
7
+
8
+ def initialize(client)
9
+ @client = client
10
+ @callback = Proc.new {}
11
+ end
12
+
13
+ def on_event(event)
14
+ raise NotImplementedError
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module Ecco
2
+ RowEvent = Struct.new(:type, :table_id, :database, :table, :rows)
3
+ end
@@ -0,0 +1,44 @@
1
+ require "ecco/event_listener"
2
+ require "ecco/row_event"
3
+
4
+ module Ecco
5
+ class RowEventListener < EventListener
6
+ ROW_EVENTS = [
7
+ EventType::WRITE_ROWS,
8
+ EventType::UPDATE_ROWS,
9
+ EventType::DELETE_ROWS,
10
+ ]
11
+
12
+ def table_event
13
+ EventType::TABLE_MAP
14
+ end
15
+
16
+ def accepted_events
17
+ ROW_EVENTS
18
+ end
19
+
20
+ def on_event(event)
21
+ data = event.get_data
22
+ type = event.get_header.get_event_type
23
+
24
+ case type
25
+ when table_event
26
+ @table_map_event = event
27
+ when *accepted_events
28
+ row_event = Ecco::RowEvent.new
29
+ row_event.type = type.to_s
30
+ row_event.table_id = data.get_table_id
31
+ row_event.rows = data.rows
32
+
33
+ if @table_map_event
34
+ event_data = @table_map_event.get_data
35
+
36
+ row_event.database = event_data.get_database
37
+ row_event.table = event_data.get_table
38
+ end
39
+
40
+ @callback.call(row_event)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,29 @@
1
+ require "ecco/event_listener"
2
+
3
+ module Ecco
4
+ class SaveEventListener < EventListener
5
+ SAVE_EVENTS = [
6
+ EventType::QUERY,
7
+ EventType::ROTATE,
8
+ EventType::WRITE_ROWS,
9
+ EventType::UPDATE_ROWS,
10
+ EventType::DELETE_ROWS,
11
+ ]
12
+
13
+ def accepted_events
14
+ SAVE_EVENTS
15
+ end
16
+
17
+ def on_event(event)
18
+ type = event.get_header.get_event_type
19
+
20
+ case type
21
+ when *accepted_events
22
+ filename = @client.get_binlog_filename
23
+ position = @client.get_binlog_position
24
+
25
+ @callback.call(filename, position)
26
+ end
27
+ end
28
+ end
29
+ end
data/lib/ecco/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Ecco
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  MYSQL_BINLOG_CONNECTOR_VERSION = "0.2.4"
4
4
  end
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecco
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: java
6
6
  authors:
7
7
  - Twingly AB
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-27 00:00:00.000000000 Z
11
+ date: 2015-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
14
20
  requirement: !ruby/object:Gem::Requirement
15
21
  requirements:
16
22
  - - "~>"
17
23
  - !ruby/object:Gem::Version
18
24
  version: '1.10'
19
- name: bundler
20
25
  prerelease: false
21
26
  type: :development
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
22
29
  version_requirements: !ruby/object:Gem::Requirement
23
30
  requirements:
24
31
  - - "~>"
25
32
  - !ruby/object:Gem::Version
26
- version: '1.10'
27
- - !ruby/object:Gem::Dependency
33
+ version: '10.0'
28
34
  requirement: !ruby/object:Gem::Requirement
29
35
  requirements:
30
36
  - - "~>"
31
37
  - !ruby/object:Gem::Version
32
38
  version: '10.0'
33
- name: rake
34
39
  prerelease: false
35
40
  type: :development
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
36
43
  version_requirements: !ruby/object:Gem::Requirement
37
44
  requirements:
38
- - - "~>"
45
+ - - ">="
39
46
  - !ruby/object:Gem::Version
40
- version: '10.0'
41
- - !ruby/object:Gem::Dependency
47
+ version: '0'
42
48
  requirement: !ruby/object:Gem::Requirement
43
49
  requirements:
44
50
  - - ">="
45
51
  - !ruby/object:Gem::Version
46
52
  version: '0'
47
- name: rspec
48
53
  prerelease: false
49
54
  type: :development
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
55
  description: MySQL replication binlog parser using mysql-binlog-connector-java.
56
56
  email:
57
57
  - support@twingly.com
@@ -67,9 +67,13 @@ files:
67
67
  - README.md
68
68
  - Rakefile
69
69
  - bin/console
70
- - bin/setup
71
70
  - ecco.gemspec
72
71
  - lib/ecco.rb
72
+ - lib/ecco/client.rb
73
+ - lib/ecco/event_listener.rb
74
+ - lib/ecco/row_event.rb
75
+ - lib/ecco/row_event_listener.rb
76
+ - lib/ecco/save_event_listener.rb
73
77
  - lib/ecco/version.rb
74
78
  - lib/ext/mysql-binlog-connector-java-0.2.4.jar
75
79
  - pom.xml
data/bin/setup DELETED
@@ -1,7 +0,0 @@
1
- #!/bin/bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
-
5
- bundle install
6
-
7
- # Do any other automated setup that you need to do here