bunny_events 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 985592caa9bd8cc75584a5b75fd9867a46ed0335dbf5f40e488ceac4e1f1cf77
4
- data.tar.gz: 349a76a616f41608a04f90cc33b5d5ed470712844347ef4797e110c5d138b576
3
+ metadata.gz: ccc318c6413bcd031b944955322d4901090c15b77faf52929726e04ead11b3b3
4
+ data.tar.gz: 5a36d2c86cde7e3f1e49f2b443b9e527be434dfe32d80398b9ff5b264c54ffe7
5
5
  SHA512:
6
- metadata.gz: 0c48c7c19a3862fa90f21282db47273328e9355066dcb405bfa63c1b10ea3d3bd0595c6daee5a17cf44cfcda8d0c31b66354121348ec05c0682ec22765327416
7
- data.tar.gz: 1c2b972049aa3e951bce82a13cdffde5a501525cfeeb8b031959dbecd03f24817a09ab4069581d52a269836f3ff5105e5b42623b09257e2390b1f3f3424b4232
6
+ metadata.gz: a3d92376e744871359def061da97f575edfabfc926d8762100c3a7ff430651950251b59bf2e95df3959192bd4d7071d9b2a291d0605b72c0d3fc329d804b7aef
7
+ data.tar.gz: c6cd4c92ee2aee2e4c31cabd94c3dcfb7988c1097e49a0308d3acc0e8887f4dbeaf0dca3d491526bb555554fb41afdd658f0d17dcfb4be65204ba847cd4d8a99
data/.rubocop.yml ADDED
@@ -0,0 +1,4 @@
1
+ Style/FrozenStringLiteralComment:
2
+ Enabled: false
3
+ Metrics/LineLength:
4
+ Enabled: false
data/Gemfile CHANGED
@@ -1,9 +1,10 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  gemspec
6
6
 
7
- gem "bunny", ">= 2.14.0"
7
+ gem 'bunny', '>= 2.14.0'
8
8
  gem 'bunny-mock'
9
- gem 'coveralls', require: false
9
+ gem 'coveralls', require: false
10
+ gem 'rubocop'
data/Gemfile.lock CHANGED
@@ -8,6 +8,7 @@ GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  amq-protocol (2.3.0)
11
+ ast (2.4.0)
11
12
  bunny (2.14.2)
12
13
  amq-protocol (~> 2.3, >= 2.3.0)
13
14
  bunny-mock (1.7.0)
@@ -20,7 +21,12 @@ GEM
20
21
  tins (~> 1.6)
21
22
  diff-lcs (1.3)
22
23
  docile (1.3.2)
24
+ jaro_winkler (1.5.3)
23
25
  json (2.2.0)
26
+ parallel (1.17.0)
27
+ parser (2.6.4.0)
28
+ ast (~> 2.4.0)
29
+ rainbow (3.0.0)
24
30
  rake (10.5.0)
25
31
  rspec (3.8.0)
26
32
  rspec-core (~> 3.8.0)
@@ -35,6 +41,14 @@ GEM
35
41
  diff-lcs (>= 1.2.0, < 2.0)
36
42
  rspec-support (~> 3.8.0)
37
43
  rspec-support (3.8.2)
44
+ rubocop (0.74.0)
45
+ jaro_winkler (~> 1.5.1)
46
+ parallel (~> 1.10)
47
+ parser (>= 2.6)
48
+ rainbow (>= 2.2.2, < 4.0)
49
+ ruby-progressbar (~> 1.7)
50
+ unicode-display_width (>= 1.4.0, < 1.7)
51
+ ruby-progressbar (1.10.1)
38
52
  simplecov (0.16.1)
39
53
  docile (~> 1.1)
40
54
  json (>= 1.8, < 3)
@@ -44,6 +58,7 @@ GEM
44
58
  tins (~> 1.0)
45
59
  thor (0.20.3)
46
60
  tins (1.21.1)
61
+ unicode-display_width (1.6.0)
47
62
 
48
63
  PLATFORMS
49
64
  ruby
@@ -56,6 +71,7 @@ DEPENDENCIES
56
71
  coveralls
57
72
  rake (~> 10.0)
58
73
  rspec (~> 3.0)
74
+ rubocop
59
75
 
60
76
  BUNDLED WITH
61
77
  1.17.2
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/bunny_events.svg)](https://badge.fury.io/rb/bunny_events) [![Build Status](https://travis-ci.org/Nexus-Mods/bunny_events.svg?branch=master)](https://travis-ci.org/Nexus-Mods/bunny_events) [![Coverage Status](https://coveralls.io/repos/github/Nexus-Mods/bunny_events/badge.svg?branch=master)](https://coveralls.io/github/Nexus-Mods/bunny_events?branch=master)
4
4
 
5
+ <p><img height="200" width="200" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/3333883/bunny_events_logo.png" /></p>
6
+
5
7
  A simple wrapper gem to aid with producing events to a message queue, using Bunny, in a standardized and uniform way across multiple microservices.
6
8
 
7
9
  Rather than using Bunny directly, this gem allows an application to define "Event Definitions" which can be defined and published
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "bunny_events"
3
+ require 'bundler/setup'
4
+ require 'bunny_events'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "bunny_events"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start(__FILE__)
data/bin/example CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "bunny_events"
5
- require "bunny_event"
3
+ require 'bundler/setup'
4
+ require 'bunny_events'
5
+ require 'bunny_event'
6
6
 
7
7
  # You can add fixtures and/or initialization code here to make experimenting
8
8
  # with your gem easier. You can also use a different console, if you like.
@@ -11,50 +11,47 @@ require "bunny_event"
11
11
  # require "pry"
12
12
  # Pry.start
13
13
 
14
- p "Defining DummyEvent"
14
+ p 'Defining DummyEvent'
15
15
  class DummyEvent
16
16
  include BunnyEvent
17
17
 
18
- event_options :exchange => "test_exchange",
19
- :exchange_opts => {
20
- :type => :direct
18
+ event_options exchange: 'test_exchange',
19
+ exchange_opts: {
20
+ type: :direct
21
21
  },
22
- :queues =>
23
- {
24
- :some_queue => {
25
- :opts => {
26
- :durable => true
27
- },
28
- :routing_key => ""
29
- }
30
- }
31
-
22
+ queues: {
23
+ some_queue: {
24
+ opts: {
25
+ durable: true
26
+ },
27
+ routing_key: ''
28
+ }
29
+ }
32
30
 
33
31
  def initialize(msg)
34
32
  @message = "My test message is #{msg}"
35
33
  end
36
-
37
34
  end
38
35
 
39
- p "Publishing event"
36
+ p 'Publishing event'
40
37
 
41
38
  bunny_events = BunnyEvents.new
42
- bunny = Bunny.new("amqp://rabbitmq:rabbitmq@localhost:5672").start
39
+ bunny = Bunny.new('amqp://rabbitmq:rabbitmq@localhost:5672').start
43
40
  bunny_events.init bunny
44
41
 
45
- bunny_events.publish DummyEvent.new "test"
42
+ bunny_events.publish DummyEvent.new 'test'
46
43
 
47
- p "deleting exchane"
48
- p bunny.exchange_exists? "test_exchange"
44
+ p 'deleting exchane'
45
+ p bunny.exchange_exists? 'test_exchange'
49
46
 
50
- x = bunny_events.channels["DummyEvent"].exchange "test_exchange"
47
+ x = bunny_events.channels['DummyEvent'].exchange 'test_exchange'
51
48
  x.delete
52
49
 
53
- p "Does exchange exist?"
54
- p bunny.exchange_exists? "test_exchange"
50
+ p 'Does exchange exist?'
51
+ p bunny.exchange_exists? 'test_exchange'
55
52
 
56
- bunny_events.publish DummyEvent.new "test"
53
+ bunny_events.publish DummyEvent.new 'test'
57
54
 
58
- p bunny.exchange_exists? "test_exchange"
55
+ p bunny.exchange_exists? 'test_exchange'
59
56
 
60
- p "end"
57
+ p 'end'
data/bunny_events.gemspec CHANGED
@@ -1,44 +1,43 @@
1
-
2
- lib = File.expand_path("../lib", __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "bunny_events/version"
3
+ require 'bunny_events/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "bunny_events"
6
+ spec.name = 'bunny_events'
8
7
  spec.version = BunnyEvent::VERSION
9
- spec.authors = ["Dean Lovett"]
10
- spec.email = ["dean.lovett@nexusmods.com"]
8
+ spec.authors = ['Dean Lovett']
9
+ spec.email = ['dean.lovett@nexusmods.com']
11
10
 
12
- spec.summary = %q{A simple gem to define events for messages queues }
13
- spec.description = %q{This gem allows the use of "Messages" to be defined and published very easily, without your models/controllers having to worry about how messages are produced. Supports AMQP}
14
- spec.homepage = "https://www.nexusmods.com"
15
- spec.license = "MIT"
11
+ spec.summary = 'A simple gem to define events for messages queues '
12
+ spec.description = 'This gem allows the use of "Messages" to be defined and published very easily, without your models/controllers having to worry about how messages are produced. Supports AMQP'
13
+ spec.homepage = 'https://www.nexusmods.com'
14
+ spec.license = 'MIT'
16
15
 
17
16
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
17
  # to allow pushing to a single host or delete this section to allow pushing to any host.
19
18
  if spec.respond_to?(:metadata)
20
19
 
21
- spec.metadata["homepage_uri"] = spec.homepage
22
- spec.metadata["source_code_uri"] = "https://github.com/Nexus-Mods"
23
- spec.metadata["changelog_uri"] = "https://github.com/Nexus-Mods"
20
+ spec.metadata['homepage_uri'] = spec.homepage
21
+ spec.metadata['source_code_uri'] = 'https://github.com/Nexus-Mods'
22
+ spec.metadata['changelog_uri'] = 'https://github.com/Nexus-Mods'
24
23
  else
25
- raise "RubyGems 2.0 or newer is required to protect against " \
26
- "public gem pushes."
24
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
25
+ 'public gem pushes.'
27
26
  end
28
27
 
29
28
  # Specify which files should be added to the gem when it is released.
30
29
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
30
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
32
31
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
32
  end
34
- spec.bindir = "exe"
33
+ spec.bindir = 'exe'
35
34
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
- spec.require_paths = ["lib"]
35
+ spec.require_paths = ['lib']
37
36
 
38
- spec.add_dependency "bunny", ">= 2.14.0"
37
+ spec.add_dependency 'bunny', '>= 2.14.0'
39
38
 
40
- spec.add_development_dependency "bundler", "~> 1.17"
41
- spec.add_development_dependency "rake", "~> 10.0"
42
- spec.add_development_dependency "rspec", "~> 3.0"
43
- spec.add_development_dependency "bunny-mock"
39
+ spec.add_development_dependency 'bundler', '~> 1.17'
40
+ spec.add_development_dependency 'bunny-mock'
41
+ spec.add_development_dependency 'rake', '~> 10.0'
42
+ spec.add_development_dependency 'rspec', '~> 3.0'
44
43
  end
data/lib/bunny_event.rb CHANGED
@@ -3,11 +3,9 @@ require 'bunny_events'
3
3
  # Module that can be included into a ruby class to create a definition of a BunnyEvent. These events can then be published
4
4
  # via the BunnyEvents system.
5
5
  module BunnyEvent
6
-
7
6
  attr_accessor :message
8
7
 
9
8
  module ClassMethods
10
-
11
9
  # Class method to allow the setting of event options in the message definitions
12
10
  def event_options(options)
13
11
  @options = options
@@ -30,4 +28,4 @@ module Exceptions
30
28
  class InvalidBunnyConnection < StandardError; end
31
29
  class InvalidBunnyEvent < StandardError; end
32
30
  class InvalidExchange < StandardError; end
33
- end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module BunnyEvent
2
- VERSION = "0.3.0"
2
+ VERSION = '0.3.1'.freeze
3
3
  end
data/lib/bunny_events.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require 'bunny'
2
2
 
3
3
  class BunnyEvents
4
-
5
4
  attr_accessor :channels, :bunny_connection
6
5
 
7
6
  # Keeps track of which events have been intiailized by this BunnyEvents worker. Used to ensure that the queue and
@@ -9,9 +8,9 @@ class BunnyEvents
9
8
  attr_accessor :initialized_events
10
9
 
11
10
  @@defaults = {
12
- :exchange => "",
13
- :exchange_type => :direct,
14
- :routing_key => "message_queue_event"
11
+ exchange: '',
12
+ exchange_type: :direct,
13
+ routing_key: 'message_queue_event'
15
14
  }
16
15
 
17
16
  # Initialise the BunnyEvents system by accepting a bunny connection.
@@ -23,10 +22,9 @@ class BunnyEvents
23
22
  # bunny_events.init BunnyMock.new.start
24
23
  #
25
24
  def init(bunny_connection)
26
-
27
25
  # Ensure the bunny_connection is valid
28
26
  if bunny_connection.nil? || !bunny_connection.respond_to?(:connected?)
29
- raise Exceptions::InvalidBunnyConnection.new
27
+ raise Exceptions::InvalidBunnyConnection
30
28
  end
31
29
 
32
30
  @channels = {}
@@ -34,7 +32,6 @@ class BunnyEvents
34
32
  @initialized_exchanges = {}
35
33
 
36
34
  @bunny_connection = bunny_connection
37
-
38
35
  end
39
36
 
40
37
  def connected?
@@ -43,14 +40,11 @@ class BunnyEvents
43
40
 
44
41
  # Public message. message should be an instance of BaseMessage (or a class with BaseMessage included)
45
42
  def publish(message, routing_key = nil)
46
-
47
43
  unless message.class.included_modules.include?(BunnyEvent)
48
- raise Exceptions::InvalidBunnyEvent.new
44
+ raise Exceptions::InvalidBunnyEvent
49
45
  end
50
46
 
51
- unless connected?
52
- raise Exceptions::InvalidBunnyConnection.new
53
- end
47
+ raise Exceptions::InvalidBunnyConnection unless connected?
54
48
 
55
49
  # get the options defined by the message queue event class
56
50
  opts = @@defaults.merge message.class.options
@@ -63,17 +57,15 @@ class BunnyEvents
63
57
  channel = @channels[message.class.name]
64
58
 
65
59
  # Ensure that the exchange, queue and binding creation is only performed once
66
- if (!@initialized_exchanges.key?(message.class.name)) || opts[:always_create_when_publishing]
60
+ if !@initialized_exchanges.key?(message.class.name) || opts[:always_create_when_publishing]
67
61
  # If the event was sent with an exchange name, create and submit this to the exchange, otherwise, just use the default exchange
68
- if !opts[:exchange].nil? && !opts[:exchange].empty?
69
- x = channel.exchange(opts[:exchange], opts[:exchange_opts] || {})
70
- else
71
- x = channel.default_exchange
72
- end
62
+ x = if !opts[:exchange].nil? && !opts[:exchange].empty?
63
+ channel.exchange(opts[:exchange], opts[:exchange_opts] || {})
64
+ else
65
+ channel.default_exchange
66
+ end
73
67
  # if the event was sent with queue definitions, ensure to create the bindings
74
- if !opts[:queues].nil?
75
- handle_queue_definitions channel, x, opts[:queues]
76
- end
68
+ handle_queue_definitions channel, x, opts[:queues] unless opts[:queues].nil?
77
69
 
78
70
  # ensure this event's creation params are not processed again
79
71
  @initialized_exchanges[message.class.name] ||= x
@@ -83,27 +75,28 @@ class BunnyEvents
83
75
 
84
76
  # ensure exchange is not null
85
77
  if x.nil? || !@bunny_connection.exchange_exists?(opts[:exchange])
86
- raise Exceptions::InvalidExchange.new
78
+ raise Exceptions::InvalidExchange
87
79
  end
88
80
 
89
81
  # publish message along with the optional routing key
90
- x.publish message.message, :routing_key => routing_key || opts[:routing_key]
82
+ x.publish message.message, routing_key: routing_key || opts[:routing_key]
91
83
  end
92
84
 
93
85
  private
94
- def handle_queue_definitions (channel, exchange, queues)
95
- queues.each do |q, opts|
96
- # Create this queue and bind, if the binding options are present
97
- queue = channel.queue q.to_s, opts[:opts] || {}
98
-
99
- # if ignore bind isn't set, set to nil
100
- ignore_bind = opts[:ignore_bind] || false
101
-
102
- # if we aren't ignoring the binding for this queue, check if it's already bound. We also shouldn't bind directly
103
- # to the default queue
104
- if !ignore_bind && !queue.bound_to?(exchange) && exchange.name != ""
105
- queue.bind exchange, :key => opts[:routing_key] || ""
106
- end
86
+
87
+ def handle_queue_definitions(channel, exchange, queues)
88
+ queues.each do |q, opts|
89
+ # Create this queue and bind, if the binding options are present
90
+ queue = channel.queue q.to_s, opts[:opts] || {}
91
+
92
+ # if ignore bind isn't set, set to nil
93
+ ignore_bind = opts[:ignore_bind] || false
94
+
95
+ # if we aren't ignoring the binding for this queue, check if it's already bound. We also shouldn't bind directly
96
+ # to the default queue
97
+ if !ignore_bind && !queue.bound_to?(exchange) && exchange.name != ''
98
+ queue.bind exchange, key: opts[:routing_key] || ''
107
99
  end
108
100
  end
109
- end
101
+ end
102
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bunny_events
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dean Lovett
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-05 00:00:00.000000000 Z
11
+ date: 2019-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny
@@ -39,47 +39,47 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.17'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: bunny-mock
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rspec
56
+ name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '3.0'
61
+ version: '10.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '3.0'
68
+ version: '10.0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: bunny-mock
70
+ name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '3.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '3.0'
83
83
  description: This gem allows the use of "Messages" to be defined and published very
84
84
  easily, without your models/controllers having to worry about how messages are produced.
85
85
  Supports AMQP
@@ -91,6 +91,7 @@ extra_rdoc_files: []
91
91
  files:
92
92
  - ".gitignore"
93
93
  - ".rspec"
94
+ - ".rubocop.yml"
94
95
  - ".travis.yml"
95
96
  - Gemfile
96
97
  - Gemfile.lock