bunny_events 0.2.0 → 0.2.2

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: 551dc0de116a611c5fff1a08eedc6755ecf260170dc07c9a7ae101e918f429e7
4
- data.tar.gz: 533bb9acbb4ef9840092411265f62bc6f544a784dd4b33891ef2531a30aafee4
3
+ metadata.gz: 1f56ddc8106ddffb47e4a21f83c06104ab87591db3c05ca12ffc877d6997560c
4
+ data.tar.gz: daaddd4f9ae0581e40625e2ffd9146e61f9a1177cf068167974bf190f6ccd7f8
5
5
  SHA512:
6
- metadata.gz: b6cabc09d71b564763162a7ac695f31543253c1956a271c4aedc06e2c9b5796d67a5f5ad8cfd21ca275e94c8172c83c2e57f945d0a588b9757c5912933d7035a
7
- data.tar.gz: 7cc66f4ca9b42fd46b6b78de9a284e109834f72ea2f7503c079407fdaf2152a54fc1ad12168625d083af41fdd58322b58bbb7403b3b3ec2e789b327cff66586e
6
+ metadata.gz: a51e2605065ccc01876aa5b0b5d6c9aa0d8c3a44ceb1ceece1a68d62986017aed50cdf26f8798cb7ee9a9bf143f7ad8ffbb0f5d8d7e56948c7b22f1a4f9d0b11
7
+ data.tar.gz: d8b7b89407ee3c87e8af7fd1446284ec6f320467d4cadf72f1a022bc2c491f344a9c8215ac523005a47f3774e318a1160214e09210be5b13e45823051cb4954a
data/.gitignore CHANGED
@@ -6,6 +6,9 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /.idea/
9
10
 
10
11
  # rspec failure tracking
11
12
  .rspec_status
13
+
14
+ *.gem
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Bunny Events
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/message_queue_event.svg)](https://badge.fury.io/rb/message_queue_event)
3
+ [![Gem Version](https://badge.fury.io/rb/bunny_events.svg)](https://badge.fury.io/rb/bunny_events)
4
4
 
5
5
  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
6
 
@@ -93,17 +93,20 @@ BunnyEvents.init Bunny.new("amqp://rabbitmq:rabbitmq@rabbit1:5672").start
93
93
  class MyTestEvent
94
94
  include BunnyEvent
95
95
 
96
- # define the event options for queueing this event. Each event type can have different options.
97
- event_options :exchange => "test_exchange",
98
- :exchange_type => :fanout,
99
- :bindings => {
100
- :queue_1 => {
101
- :routing_key => ""
102
- },
103
- :queue_2 => {
104
- :routing_key => ""
105
- },
106
- }
96
+ # define the event options for queueing this event. Each event type can have different options.
97
+ event_options :exchange => "test_exchange",
98
+ :exchange_opts => {
99
+ :type => :fanout
100
+ },
101
+ :queues =>
102
+ {
103
+ :some_queue => {
104
+ :opts => {
105
+ :durable => true
106
+ },
107
+ :routing_key => ""
108
+ }
109
+ }
107
110
 
108
111
  # We can define what the message payload looks like here.
109
112
  def initialize(msg)
data/bin/example CHANGED
@@ -11,9 +11,6 @@ require "bunny_event"
11
11
  # require "pry"
12
12
  # Pry.start
13
13
 
14
- p "Setting up BunnyEvents..."
15
- BunnyEvents.init Bunny.new("amqp://rabbitmq:rabbitmq@localhost:5672").start
16
-
17
14
  p "Defining DummyEvent"
18
15
  class DummyEvent
19
16
  include BunnyEvent
@@ -39,4 +36,7 @@ class DummyEvent
39
36
  end
40
37
 
41
38
  p "Publishing event"
42
- BunnyEvents.publish DummyEvent.new "test"
39
+ bunny_events = BunnyEvents.new
40
+ bunny_events.init Bunny.new("amqp://rabbitmq:rabbitmq@localhost:5672").start
41
+
42
+ bunny_events.publish DummyEvent.new "test"
@@ -1,3 +1,3 @@
1
1
  module BunnyEvent
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.2"
3
3
  end
data/lib/bunny_events.rb CHANGED
@@ -2,12 +2,7 @@ require 'bunny'
2
2
 
3
3
  class BunnyEvents
4
4
 
5
- class << self
6
- # Class instance variables, for:
7
- # - keeping track of all our active channels (one for each type of event)
8
- # - our active connection to bunny (one for the whole application)
9
- attr_accessor :channels, :bunny_connection
10
- end
5
+ attr_accessor :channels, :bunny_connection
11
6
 
12
7
  @@defaults = {
13
8
  :exchange => "",
@@ -19,26 +14,29 @@ class BunnyEvents
19
14
  #
20
15
  # Example:
21
16
  #
22
- # This can also accept bunnymock for testing
23
- # BunnyEvents.init BunnyMock.new.start
17
+ # NOTE: This can also accept bunnymock for testing
18
+ # bunny_events = BunnyEvents.new
19
+ # bunny_events.init BunnyMock.new.start
24
20
  #
25
- def self.init(bunny_connection)
21
+ def init(bunny_connection)
26
22
 
27
23
  # Ensure the bunny_connection is valid
28
24
  if bunny_connection.nil? || !bunny_connection.respond_to?(:connected?)
29
25
  raise Exceptions::InvalidBunnyConnection.new
30
26
  end
31
27
 
28
+ @channels = {}
29
+
32
30
  @bunny_connection = bunny_connection
33
31
 
34
32
  end
35
33
 
36
- def self.connected?
34
+ def connected?
37
35
  @bunny_connection&.connected? || false
38
36
  end
39
37
 
40
38
  # Public message. message should be an instance of BaseMessage (or a class with BaseMessage included)
41
- def self.publish(message)
39
+ def publish(message)
42
40
 
43
41
  unless message.class.included_modules.include?(BunnyEvent)
44
42
  raise Exceptions::InvalidBunnyEvent.new
@@ -48,11 +46,6 @@ class BunnyEvents
48
46
  throw "Not connected"
49
47
  end
50
48
 
51
- # If there are no channels, or this message's key does not appear in our channel list, create a new channel
52
- if @channels.nil?
53
- @channels = {}
54
- end
55
-
56
49
  # get the options defined by the message queue event class
57
50
  opts = @@defaults.merge message.class.options
58
51
 
@@ -70,8 +63,6 @@ class BunnyEvents
70
63
  x = channel.default_exchange
71
64
  end
72
65
 
73
-
74
-
75
66
  # if the event was sent with queue definitions, ensure to create the bindings
76
67
  if !opts[:queues].nil?
77
68
  handle_queue_definitions channel, x, opts[:queues]
@@ -81,10 +72,9 @@ class BunnyEvents
81
72
 
82
73
  end
83
74
 
84
- def self.handle_queue_definitions (channel, exchange, queues)
75
+ private
76
+ def handle_queue_definitions (channel, exchange, queues)
85
77
  queues.each do |q, opts|
86
- p opts[:routing_key]
87
-
88
78
  # Create this queue and bind, if the binding options are present
89
79
  queue = channel.queue q.to_s, opts[:opts] || {}
90
80
  queue.bind exchange, :key => opts[:routing_key] || ""
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.2.0
4
+ version: 0.2.2
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-08-30 00:00:00.000000000 Z
11
+ date: 2019-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bunny