messaging 0.0.2 → 3.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +68 -0
  3. data/.gitignore +11 -0
  4. data/.rspec +2 -0
  5. data/.ruby-version +1 -0
  6. data/Gemfile +15 -0
  7. data/Gemfile.lock +222 -0
  8. data/README.md +53 -0
  9. data/Rakefile +5 -30
  10. data/_config.yml +1 -0
  11. data/bin/console +11 -0
  12. data/bin/setup +8 -0
  13. data/exe/messaging +11 -0
  14. data/lib/messaging.rb +62 -11
  15. data/lib/messaging/adapters.rb +35 -0
  16. data/lib/messaging/adapters/kafka.rb +55 -0
  17. data/lib/messaging/adapters/kafka/consumer.rb +101 -0
  18. data/lib/messaging/adapters/kafka/producer.rb +52 -0
  19. data/lib/messaging/adapters/postgres.rb +23 -0
  20. data/lib/messaging/adapters/postgres/advisory_transaction_lock.rb +28 -0
  21. data/lib/messaging/adapters/postgres/serialized_message.rb +74 -0
  22. data/lib/messaging/adapters/postgres/store.rb +66 -0
  23. data/lib/messaging/adapters/postgres/stream.rb +37 -0
  24. data/lib/messaging/adapters/postgres/streams.rb +27 -0
  25. data/lib/messaging/adapters/test.rb +59 -0
  26. data/lib/messaging/adapters/test/consumer.rb +46 -0
  27. data/lib/messaging/adapters/test/store.rb +67 -0
  28. data/lib/messaging/adapters/test/stream.rb +21 -0
  29. data/lib/messaging/base_handler.rb +45 -0
  30. data/lib/messaging/cli.rb +62 -0
  31. data/lib/messaging/config.rb +66 -0
  32. data/lib/messaging/consumer_supervisor.rb +63 -0
  33. data/lib/messaging/exception_handler.rb +15 -0
  34. data/lib/messaging/expected_version.rb +31 -0
  35. data/lib/messaging/instrumentation.rb +21 -0
  36. data/lib/messaging/message.rb +103 -0
  37. data/lib/messaging/message/from_json.rb +31 -0
  38. data/lib/messaging/meter.rb +113 -0
  39. data/lib/messaging/middleware.rb +14 -0
  40. data/lib/messaging/middleware/after_active_record_transaction.rb +13 -0
  41. data/lib/messaging/middleware/rails_wrapper.rb +22 -0
  42. data/lib/messaging/publish.rb +33 -0
  43. data/lib/messaging/rails/railtie.rb +36 -0
  44. data/lib/messaging/resque_worker.rb +11 -0
  45. data/lib/messaging/routes.rb +50 -0
  46. data/lib/messaging/routing.rb +67 -0
  47. data/lib/messaging/routing/background_job_subscriber.rb +11 -0
  48. data/lib/messaging/routing/enqueue_message_handler.rb +15 -0
  49. data/lib/messaging/routing/message_matcher.rb +62 -0
  50. data/lib/messaging/routing/subscriber.rb +35 -0
  51. data/lib/messaging/sidekiq_worker.rb +12 -0
  52. data/lib/messaging/version.rb +1 -1
  53. data/messaging.gemspec +40 -0
  54. metadata +299 -102
  55. data/MIT-LICENSE +0 -20
  56. data/app/models/message.rb +0 -5
  57. data/app/models/receipt.rb +0 -13
  58. data/app/uploaders/attachment_uploader.rb +0 -9
  59. data/db/migrate/20130801214110_initial_migration.rb +0 -22
  60. data/lib/generators/messaging/install_generator.rb +0 -26
  61. data/lib/generators/messaging/templates/initializer.rb +0 -11
  62. data/lib/messaging/concerns/configurable_mailer.rb +0 -13
  63. data/lib/messaging/engine.rb +0 -9
  64. data/lib/messaging/models/messageable.rb +0 -24
  65. data/lib/tasks/messaging_tasks.rake +0 -4
  66. data/test/dummy/README.rdoc +0 -28
  67. data/test/dummy/Rakefile +0 -6
  68. data/test/dummy/app/assets/javascripts/application.js +0 -13
  69. data/test/dummy/app/assets/stylesheets/application.css +0 -13
  70. data/test/dummy/app/controllers/application_controller.rb +0 -5
  71. data/test/dummy/app/helpers/application_helper.rb +0 -2
  72. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  73. data/test/dummy/bin/bundle +0 -3
  74. data/test/dummy/bin/rails +0 -4
  75. data/test/dummy/bin/rake +0 -4
  76. data/test/dummy/config.ru +0 -4
  77. data/test/dummy/config/application.rb +0 -23
  78. data/test/dummy/config/boot.rb +0 -5
  79. data/test/dummy/config/database.yml +0 -25
  80. data/test/dummy/config/environment.rb +0 -5
  81. data/test/dummy/config/environments/development.rb +0 -29
  82. data/test/dummy/config/environments/production.rb +0 -80
  83. data/test/dummy/config/environments/test.rb +0 -36
  84. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  85. data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  86. data/test/dummy/config/initializers/inflections.rb +0 -16
  87. data/test/dummy/config/initializers/mime_types.rb +0 -5
  88. data/test/dummy/config/initializers/secret_token.rb +0 -12
  89. data/test/dummy/config/initializers/session_store.rb +0 -3
  90. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  91. data/test/dummy/config/locales/en.yml +0 -23
  92. data/test/dummy/config/routes.rb +0 -56
  93. data/test/dummy/public/404.html +0 -58
  94. data/test/dummy/public/422.html +0 -58
  95. data/test/dummy/public/500.html +0 -57
  96. data/test/dummy/public/favicon.ico +0 -0
  97. data/test/messaging_test.rb +0 -7
  98. data/test/test_helper.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 02553f3704bec98c77470e0d8d8751edf6110edc
4
- data.tar.gz: baee1e9fd3b49d261325a2bb01058b4742842aef
3
+ metadata.gz: cd652caf5be10317afbfc217864ac1fa01ed0297
4
+ data.tar.gz: 729a4cefa5be12f689c670f5aa468641de2d9b46
5
5
  SHA512:
6
- metadata.gz: 96cab4c6886007dc3b90aec54a75b1b2c091107476e86b6dcfe33b90949f6f9466ea184b04d669ffc69ce7d1022111957cc7344f5829fd442923dc2a63c3c218
7
- data.tar.gz: 42420e8964c23379e8180c319c1d5ce98c5c17443f2ec5d96145e38aa616f3e443de4326da893b750ac6c550e8cecf1d3e9762fa95b900d9515539509230033a
6
+ metadata.gz: c7c2f6359c96e306acefa7df23306c0816da4badccb446a3f0be46a6d39328fb08d8bf5fceb09d450cc34ee41d43d8629c61c0b462c5ebe73c28a967862d355d
7
+ data.tar.gz: 3397a6507517bcbc5b599a68cf1bf7920134d60e89f1d8f901a610cb835cfc11d9ac2d3cbc38bf6f3f411b4d9b5466927ccaa87a82049dd8feba5f5fdef34a21
@@ -0,0 +1,68 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ # specify the version you desire here
10
+ - image: circleci/ruby:2.4.1-node-browsers
11
+ environment:
12
+ CC_TEST_REPORTER_ID: 94ada9b95ee3f232a6e984809d37917cfee90ac47805429e8c49742b2e8d2276
13
+ RAILS_ENV: test
14
+ - image: circleci/postgres:9.6.6-alpine
15
+ environment:
16
+ POSTGRES_USER: postgres
17
+
18
+ working_directory: ~/repo
19
+
20
+ steps:
21
+ - run:
22
+ name: Install aptitude because it has much more helpful error messages when ending up in dependency hell
23
+ command: sudo apt-get install --assume-yes aptitude
24
+
25
+ - run:
26
+ name: Install Postgres Client
27
+ command: sudo aptitude -y install postgresql-client
28
+
29
+ - checkout
30
+
31
+ - run:
32
+ name: Setup Code Climate test-reporter
33
+ command: |
34
+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
35
+ chmod +x ./cc-test-reporter
36
+
37
+ - restore_cache:
38
+ name: Restore Bundler Cache
39
+ key: messaging-bundle-{{ checksum "Gemfile.lock" }}
40
+
41
+ - run:
42
+ name: install dependencies
43
+ command: bundle install --jobs=4 --retry=3 --path vendor/bundle
44
+
45
+ - save_cache:
46
+ key: messagin-bundle-{{ checksum "Gemfile.lock" }}
47
+ paths:
48
+ - vendor/bundle
49
+
50
+ - run:
51
+ name: Database Setup
52
+ command: |
53
+ cd spec/example_app
54
+ bin/rails db:create
55
+ bin/rails db:migrate
56
+
57
+ - run:
58
+ name: run tests
59
+ command: |
60
+ ./cc-test-reporter before-build
61
+ bundle exec rspec --format RspecJunitFormatter
62
+ ./cc-test-reporter after-build --exit-code $?
63
+
64
+ workflows:
65
+ version: 2
66
+ messaging_specs:
67
+ jobs:
68
+ - build
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ **/.bundle/*
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |path| "https://github.com/#{path}.git" }
4
+
5
+ gem 'bootsnap', require: false
6
+ gem 'bukowskis_after_transaction', github: 'bukowskis/after_transaction'
7
+ gem 'bukowskis_method_object', github: 'bukowskis/method_object'
8
+ gem 'listen'
9
+ gem 'pg'
10
+ gem 'pry'
11
+ gem 'pry-rails'
12
+ gem 'railties'
13
+ gem 'sidekiq'
14
+
15
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,222 @@
1
+ GIT
2
+ remote: https://github.com/bukowskis/after_transaction.git
3
+ revision: d9c250d497b861cdeb1aa924d82bbc5d38cfc56a
4
+ specs:
5
+ bukowskis_after_transaction (0.0.1)
6
+ activerecord (< 6.0)
7
+
8
+ GIT
9
+ remote: https://github.com/bukowskis/method_object.git
10
+ revision: bfb21cabafceec3b191d5c42d681a8e99ff38e6d
11
+ specs:
12
+ bukowskis_method_object (0.0.1)
13
+ dry-initializer
14
+
15
+ PATH
16
+ remote: .
17
+ specs:
18
+ messaging (3.4.0)
19
+ activerecord
20
+ activesupport
21
+ bukowskis_after_transaction
22
+ concurrent-ruby (>= 1.0.2)
23
+ concurrent-ruby-ext (>= 1.0.2)
24
+ dry-configurable
25
+ dry-container
26
+ dry-equalizer
27
+ dry-initializer
28
+ meter (>= 1.2.1)
29
+ method_object
30
+ ruby-kafka (>= 0.5.3)
31
+ virtus
32
+
33
+ GEM
34
+ remote: https://rubygems.org/
35
+ specs:
36
+ actionpack (5.2.2)
37
+ actionview (= 5.2.2)
38
+ activesupport (= 5.2.2)
39
+ rack (~> 2.0)
40
+ rack-test (>= 0.6.3)
41
+ rails-dom-testing (~> 2.0)
42
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
43
+ actionview (5.2.2)
44
+ activesupport (= 5.2.2)
45
+ builder (~> 3.1)
46
+ erubi (~> 1.4)
47
+ rails-dom-testing (~> 2.0)
48
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
49
+ activemodel (5.2.2)
50
+ activesupport (= 5.2.2)
51
+ activerecord (5.2.2)
52
+ activemodel (= 5.2.2)
53
+ activesupport (= 5.2.2)
54
+ arel (>= 9.0)
55
+ activesupport (5.2.2)
56
+ concurrent-ruby (~> 1.0, >= 1.0.2)
57
+ i18n (>= 0.7, < 2)
58
+ minitest (~> 5.1)
59
+ tzinfo (~> 1.1)
60
+ arel (9.0.0)
61
+ axiom-types (0.1.1)
62
+ descendants_tracker (~> 0.0.4)
63
+ ice_nine (~> 0.11.0)
64
+ thread_safe (~> 0.3, >= 0.3.1)
65
+ bootsnap (1.3.2)
66
+ msgpack (~> 1.0)
67
+ builder (3.2.3)
68
+ coderay (1.1.2)
69
+ coercible (1.0.0)
70
+ descendants_tracker (~> 0.0.1)
71
+ concurrent-ruby (1.1.4)
72
+ concurrent-ruby-ext (1.1.4)
73
+ concurrent-ruby (= 1.1.4)
74
+ connection_pool (2.2.2)
75
+ crass (1.0.4)
76
+ descendants_tracker (0.0.4)
77
+ thread_safe (~> 0.3, >= 0.3.1)
78
+ diff-lcs (1.3)
79
+ digest-crc (0.4.1)
80
+ docile (1.3.1)
81
+ dry-configurable (0.8.3)
82
+ concurrent-ruby (~> 1.0)
83
+ dry-core (~> 0.4, >= 0.4.7)
84
+ dry-container (0.7.2)
85
+ concurrent-ruby (~> 1.0)
86
+ dry-configurable (~> 0.1, >= 0.1.3)
87
+ dry-core (0.4.9)
88
+ concurrent-ruby (~> 1.0)
89
+ dry-equalizer (0.2.2)
90
+ dry-initializer (2.5.0)
91
+ equalizer (0.0.11)
92
+ erubi (1.8.0)
93
+ ffi (1.10.0)
94
+ geocoder (1.2.13)
95
+ hashie (3.6.0)
96
+ i18n (1.5.3)
97
+ concurrent-ruby (~> 1.0)
98
+ ice_nine (0.11.2)
99
+ json (2.1.0)
100
+ listen (3.1.5)
101
+ rb-fsevent (~> 0.9, >= 0.9.4)
102
+ rb-inotify (~> 0.9, >= 0.9.7)
103
+ ruby_dep (~> 1.2)
104
+ locality (1.1.0)
105
+ activesupport
106
+ geocoder (= 1.2.13)
107
+ hashie
108
+ i18n
109
+ maxminddb (= 0.1.8)
110
+ operation
111
+ trouble
112
+ loofah (2.2.3)
113
+ crass (~> 1.0.2)
114
+ nokogiri (>= 1.5.9)
115
+ maxminddb (0.1.8)
116
+ meter (1.2.7)
117
+ locality (~> 1.1.0)
118
+ useragent (~> 0.16.3)
119
+ method_object (1.0.0)
120
+ dry-initializer
121
+ method_source (0.9.2)
122
+ mini_portile2 (2.4.0)
123
+ minitest (5.11.3)
124
+ msgpack (1.2.6)
125
+ nokogiri (1.10.1)
126
+ mini_portile2 (~> 2.4.0)
127
+ operation (1.4.1)
128
+ pg (1.1.4)
129
+ pry (0.12.2)
130
+ coderay (~> 1.1.0)
131
+ method_source (~> 0.9.0)
132
+ pry-rails (0.3.9)
133
+ pry (>= 0.10.4)
134
+ rack (2.0.6)
135
+ rack-protection (2.0.5)
136
+ rack
137
+ rack-test (1.1.0)
138
+ rack (>= 1.0, < 3)
139
+ rails-dom-testing (2.0.3)
140
+ activesupport (>= 4.2.0)
141
+ nokogiri (>= 1.6)
142
+ rails-html-sanitizer (1.0.4)
143
+ loofah (~> 2.2, >= 2.2.2)
144
+ railties (5.2.2)
145
+ actionpack (= 5.2.2)
146
+ activesupport (= 5.2.2)
147
+ method_source
148
+ rake (>= 0.8.7)
149
+ thor (>= 0.19.0, < 2.0)
150
+ rake (10.5.0)
151
+ rb-fsevent (0.10.3)
152
+ rb-inotify (0.10.0)
153
+ ffi (~> 1.0)
154
+ redis (4.1.0)
155
+ rspec (3.8.0)
156
+ rspec-core (~> 3.8.0)
157
+ rspec-expectations (~> 3.8.0)
158
+ rspec-mocks (~> 3.8.0)
159
+ rspec-core (3.8.0)
160
+ rspec-support (~> 3.8.0)
161
+ rspec-expectations (3.8.2)
162
+ diff-lcs (>= 1.2.0, < 2.0)
163
+ rspec-support (~> 3.8.0)
164
+ rspec-mocks (3.8.0)
165
+ diff-lcs (>= 1.2.0, < 2.0)
166
+ rspec-support (~> 3.8.0)
167
+ rspec-rails (3.8.2)
168
+ actionpack (>= 3.0)
169
+ activesupport (>= 3.0)
170
+ railties (>= 3.0)
171
+ rspec-core (~> 3.8.0)
172
+ rspec-expectations (~> 3.8.0)
173
+ rspec-mocks (~> 3.8.0)
174
+ rspec-support (~> 3.8.0)
175
+ rspec-support (3.8.0)
176
+ ruby-kafka (0.7.10)
177
+ digest-crc
178
+ ruby_dep (1.5.0)
179
+ sidekiq (5.2.5)
180
+ connection_pool (~> 2.2, >= 2.2.2)
181
+ rack (>= 1.5.0)
182
+ rack-protection (>= 1.5.0)
183
+ redis (>= 3.3.5, < 5)
184
+ simplecov (0.16.1)
185
+ docile (~> 1.1)
186
+ json (>= 1.8, < 3)
187
+ simplecov-html (~> 0.10.0)
188
+ simplecov-html (0.10.2)
189
+ thor (0.20.3)
190
+ thread_safe (0.3.6)
191
+ trouble (0.0.13)
192
+ tzinfo (1.2.5)
193
+ thread_safe (~> 0.1)
194
+ useragent (0.16.10)
195
+ virtus (1.0.5)
196
+ axiom-types (~> 0.1)
197
+ coercible (~> 1.0)
198
+ descendants_tracker (~> 0.0, >= 0.0.3)
199
+ equalizer (~> 0.0, >= 0.0.9)
200
+
201
+ PLATFORMS
202
+ ruby
203
+
204
+ DEPENDENCIES
205
+ bootsnap
206
+ bukowskis_after_transaction!
207
+ bukowskis_method_object!
208
+ bundler (~> 1.14)
209
+ listen
210
+ messaging!
211
+ pg
212
+ pry
213
+ pry-rails
214
+ railties
215
+ rake (~> 10.0)
216
+ rspec (~> 3.0)
217
+ rspec-rails
218
+ sidekiq
219
+ simplecov
220
+
221
+ BUNDLED WITH
222
+ 1.17.3
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # Messaging
2
+
3
+ Messaging is a library used to send and receive messages via Kafka.
4
+
5
+
6
+ 1. [The three main concepts](#the-three-main-concepts)
7
+ 1. [Messages](#messages)
8
+ 2. [Topics](#topics)
9
+ 3. [Handlers](#handlers)
10
+ 2. [Usage](#usage)
11
+ 1. [Creating messages](#creating-messages)
12
+ 2. [Publishing messages](#publishing-messages)
13
+ 3. [Receiving messages](#receiving-messages)
14
+
15
+ ## The three main concepts
16
+
17
+ The usage of this gem is based on three main concepts: messages, topics and handlers.
18
+
19
+ ### Messages
20
+
21
+ A message represents the actual messages we send and receive, example:
22
+
23
+ ```ruby
24
+ Module Events
25
+ class LotViewed
26
+ include ::Messaging::Message
27
+
28
+ attribute :lot_id, Integer
29
+ attribute :item_id, Integer
30
+ attribute :customer_id, Integer
31
+
32
+ end
33
+ end
34
+ ```
35
+
36
+ Messages are published to Kafka topics. By default the topic has the same name as the message class (but underscored and / are replaced with - as Kafka doesn't allow '/' in topic names).
37
+
38
+ In our example above, Events::LotViewed would be published to a topic named events-lot_viewed.
39
+
40
+ ### Topics
41
+
42
+ ### Handlers
43
+
44
+ ## Usage
45
+
46
+ ### Creating messages
47
+ ### Publishing messages
48
+ ### Receiving messages
49
+
50
+ ## Making a new version
51
+
52
+ Increase the version in version.rb
53
+ run be rake release
data/Rakefile CHANGED
@@ -1,32 +1,7 @@
1
- begin
2
- require 'bundler/setup'
3
- rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
- end
1
+ ENV['gem_push'] = 'no'
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
6
4
 
7
- require 'rdoc/task'
5
+ RSpec::Core::RakeTask.new(:spec)
8
6
 
9
- RDoc::Task.new(:rdoc) do |rdoc|
10
- rdoc.rdoc_dir = 'rdoc'
11
- rdoc.title = 'Messaging'
12
- rdoc.options << '--line-numbers'
13
- rdoc.rdoc_files.include('README.rdoc')
14
- rdoc.rdoc_files.include('lib/**/*.rb')
15
- end
16
-
17
-
18
-
19
-
20
- Bundler::GemHelper.install_tasks
21
-
22
- require 'rake/testtask'
23
-
24
- Rake::TestTask.new(:test) do |t|
25
- t.libs << 'lib'
26
- t.libs << 'test'
27
- t.pattern = 'test/**/*_test.rb'
28
- t.verbose = false
29
- end
30
-
31
-
32
- task default: :test
7
+ task :default => :spec
data/_config.yml ADDED
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-minimal
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "messaging"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require "pry"
11
+ Pry.start