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 +4 -4
- data/bin/example +42 -0
- data/lib/bunny_events.rb +18 -9
- data/lib/bunny_events/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 551dc0de116a611c5fff1a08eedc6755ecf260170dc07c9a7ae101e918f429e7
|
4
|
+
data.tar.gz: 533bb9acbb4ef9840092411265f62bc6f544a784dd4b33891ef2531a30aafee4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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],
|
68
|
+
x = channel.exchange(opts[:exchange], opts[:exchange_opts] || {})
|
69
69
|
else
|
70
70
|
x = channel.default_exchange
|
71
71
|
end
|
72
72
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
-
|
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
|
data/lib/bunny_events/version.rb
CHANGED
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.
|
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
|