bunny_events 0.1.1 → 0.2.0

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: a636e6dfacc607d7b8c4c85de42c882b3e6486c38901ef0cf94c645ac7c47e87
4
- data.tar.gz: b49ffde771cb39c7e2404603d4eb913154d1fcfdedae36b14fd400f71e2778af
3
+ metadata.gz: 551dc0de116a611c5fff1a08eedc6755ecf260170dc07c9a7ae101e918f429e7
4
+ data.tar.gz: 533bb9acbb4ef9840092411265f62bc6f544a784dd4b33891ef2531a30aafee4
5
5
  SHA512:
6
- metadata.gz: a96296e85bd6c27d9ebbd6d19c9f81a8da8b1307a97d0c0d0c03f8be939a6f34f7fdf40dcdf82f6871682916ba681e97bcf4bed20c32046c982f1825bec87a82
7
- data.tar.gz: edbf92c0720199995875b668dbafec22f8a0b55782457625ff834ba8751eac45151a92a73e5b299d0df79a3e60827480eea3327ed07b011ff05bdc1a921eff8c
6
+ metadata.gz: b6cabc09d71b564763162a7ac695f31543253c1956a271c4aedc06e2c9b5796d67a5f5ad8cfd21ca275e94c8172c83c2e57f945d0a588b9757c5912933d7035a
7
+ data.tar.gz: 7cc66f4ca9b42fd46b6b78de9a284e109834f72ea2f7503c079407fdaf2152a54fc1ad12168625d083af41fdd58322b58bbb7403b3b3ec2e789b327cff66586e
data/bin/example ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bunny_events"
5
+ require "bunny_event"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ p "Setting up BunnyEvents..."
15
+ BunnyEvents.init Bunny.new("amqp://rabbitmq:rabbitmq@localhost:5672").start
16
+
17
+ p "Defining DummyEvent"
18
+ class DummyEvent
19
+ include BunnyEvent
20
+
21
+ event_options :exchange => "test_exchange",
22
+ :exchange_opts => {
23
+ :type => :fanout
24
+ },
25
+ :queues =>
26
+ {
27
+ :some_queue => {
28
+ :opts => {
29
+ :durable => true
30
+ },
31
+ :routing_key => ""
32
+ }
33
+ }
34
+
35
+ def initialize(msg)
36
+ @message = "My test message is #{msg}"
37
+ end
38
+
39
+ end
40
+
41
+ p "Publishing event"
42
+ BunnyEvents.publish DummyEvent.new "test"
data/lib/bunny_events.rb CHANGED
@@ -63,22 +63,31 @@ class BunnyEvents
63
63
 
64
64
  channel = @channels[message.class.name]
65
65
 
66
- # If our message was sent with an exchange name, create and submit this to the exchange, otherwise, just use the default exchange
66
+ # If the event was sent with an exchange name, create and submit this to the exchange, otherwise, just use the default exchange
67
67
  if !opts[:exchange].nil? && !opts[:exchange].empty?
68
- x = channel.exchange(opts[:exchange], {:type => opts[:exchange_type] || :direct})
68
+ x = channel.exchange(opts[:exchange], opts[:exchange_opts] || {})
69
69
  else
70
70
  x = channel.default_exchange
71
71
  end
72
72
 
73
- # if your event was sent with queue bindings, ensure to create the queue and bindings
74
- if !opts[:bindings].nil?
75
- opts[:bindings].each do |q, binding|
76
- queue = channel.queue q.to_s
77
- queue.bind x, routing_key: binding[:routing_key]
78
- end
73
+
74
+
75
+ # if the event was sent with queue definitions, ensure to create the bindings
76
+ if !opts[:queues].nil?
77
+ handle_queue_definitions channel, x, opts[:queues]
79
78
  end
80
79
 
81
80
  x.publish message.message, :routing_key => opts[:routing_key]
82
81
 
83
- end
82
+ end
83
+
84
+ def self.handle_queue_definitions (channel, exchange, queues)
85
+ queues.each do |q, opts|
86
+ p opts[:routing_key]
87
+
88
+ # Create this queue and bind, if the binding options are present
89
+ queue = channel.queue q.to_s, opts[:opts] || {}
90
+ queue.bind exchange, :key => opts[:routing_key] || ""
91
+ end
92
+ end
84
93
  end
@@ -1,3 +1,3 @@
1
1
  module BunnyEvent
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bunny_events
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dean Lovett
@@ -84,6 +84,7 @@ files:
84
84
  - README.md
85
85
  - Rakefile
86
86
  - bin/console
87
+ - bin/example
87
88
  - bin/setup
88
89
  - lib/bunny_event.rb
89
90
  - lib/bunny_events.rb