philotic 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +28 -1
- data/examples/creating_named_queues/manually.rb +6 -8
- data/examples/publishing/publish.rb +2 -3
- data/examples/{simple_combined_example.rb → simple_instance.rb} +0 -0
- data/examples/simple_singleton.rb +27 -0
- data/examples/subscribing/acks.rb +7 -10
- data/examples/subscribing/anonymous_queue.rb +3 -6
- data/examples/subscribing/multiple_named_queues.rb +4 -6
- data/examples/subscribing/named_queue.rb +2 -4
- data/lib/philotic.rb +4 -21
- data/lib/philotic/connection.rb +2 -1
- data/lib/philotic/dummy_event.rb +3 -1
- data/lib/philotic/event.rb +1 -2
- data/lib/philotic/publisher.rb +1 -1
- data/lib/philotic/singleton.rb +13 -0
- data/lib/philotic/subscriber.rb +2 -0
- data/lib/philotic/tasks/init_queues.rb +2 -5
- data/lib/philotic/version.rb +1 -1
- data/spec/spec_helper.rb +0 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b72b8c6dc5ab1be2da45998cf70ebe908ad3099d
|
4
|
+
data.tar.gz: 8b6473eb588bdbe69d4b401b4b149cdcecb416b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a95fc1ea9e1729aff8752d68b50168e41d8ed621271c2a00809ec3e714ef68813defcb137febb57b4978df085a22da3b1a39e67b38e878f2de99d41b72e52eb
|
7
|
+
data.tar.gz: 96fb09160928634ec14693512aadd19c99237993d7e608bcf850ced33006a75ca8216ed60da6e6571e2c29b2a6e3c9363b649979578f8584e082b4a2c1358596
|
data/README.md
CHANGED
@@ -8,8 +8,35 @@ Lightweight, opinionated wrapper for using RabbitMQ headers exchanges
|
|
8
8
|
[](https://codeclimate.com/github/nkeyes/philotic)
|
9
9
|
|
10
10
|
Check out the [examples](https://github.com/nkeyes/philotic/tree/master/examples).
|
11
|
+
## Examples
|
12
|
+
### Using `Philotic` as a singleton
|
13
|
+
```Ruby
|
14
|
+
require 'philotic'
|
15
|
+
require 'awesome_print'
|
16
|
+
|
17
|
+
# override the message return handler
|
18
|
+
Philotic.config.message_return_handler = lambda do |basic_return, metadata, message|
|
19
|
+
Philotic.logger.warn "Message returned. reply_text: #{basic_return.reply_text}"
|
20
|
+
end
|
21
|
+
|
22
|
+
Philotic.subscriber.subscribe(header_key: 'header_1') do |metadata, message|
|
23
|
+
ap message[:attributes]
|
24
|
+
end
|
25
|
+
|
26
|
+
# normally we'd do:
|
27
|
+
#
|
28
|
+
# Philotic.subscriber.endure
|
29
|
+
#
|
30
|
+
# to keep the parent thread alive while the subscribers do their thing
|
31
|
+
# but this infinite publish loop takes care of that
|
32
|
+
loop do
|
33
|
+
Philotic::Event.publish({header_key: "header_#{[1, 2].sample}"}, {payload_key: 'payload_value'})
|
34
|
+
# only send a message every two seconds so we can see whats going on
|
35
|
+
sleep 2
|
36
|
+
end
|
37
|
+
```
|
11
38
|
|
12
|
-
|
39
|
+
### Using an instance of `Philotic::Connection`
|
13
40
|
```Ruby
|
14
41
|
require 'philotic'
|
15
42
|
require 'awesome_print'
|
@@ -4,13 +4,11 @@ $stdout.sync = true
|
|
4
4
|
|
5
5
|
require 'philotic'
|
6
6
|
|
7
|
-
philotic = Philotic::Connection.new
|
8
|
-
|
9
7
|
# explicitly create named queues for this example
|
10
|
-
#
|
11
|
-
|
8
|
+
# Philotic.config.initialize_named_queues must be truthy to run Philotic.initialize_named_queue!
|
9
|
+
Philotic.config.initialize_named_queues = true
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
Philotic.initialize_named_queue!('male_queue', bindings: [{:'x-match' => 'all', gender: :M, available: true}])
|
12
|
+
Philotic.initialize_named_queue!('female_queue', bindings: [{:'x-match' => 'all', gender: :F, available: true}])
|
13
|
+
Philotic.initialize_named_queue!('test_queue', bindings: [{ :'x-match' => 'any', gender: :M, available: true }])
|
14
|
+
Philotic.initialize_named_queue!('flaky_queue', bindings: [{ :'x-match' => 'any', gender: :M, available: true }])
|
@@ -5,9 +5,8 @@ $stdout.sync = true
|
|
5
5
|
require 'philotic'
|
6
6
|
require 'philotic/dummy_event'
|
7
7
|
|
8
|
-
@philotic = Philotic::Connection.new
|
9
8
|
|
10
|
-
|
9
|
+
Philotic.logger.level = Logger::WARN
|
11
10
|
|
12
11
|
@event = Philotic::DummyEvent.new
|
13
12
|
|
@@ -26,7 +25,7 @@ def send_message number
|
|
26
25
|
@event.gender = [:F, :M].sample
|
27
26
|
@event.message = "Message #{number}: Hey #{@event.gender == :M ? 'dude' : 'dudette'}"
|
28
27
|
|
29
|
-
|
28
|
+
Philotic.publish @event
|
30
29
|
|
31
30
|
end
|
32
31
|
|
File without changes
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
$stdout.sync = true
|
4
|
+
|
5
|
+
require 'philotic'
|
6
|
+
require 'awesome_print'
|
7
|
+
|
8
|
+
# override the message return handler
|
9
|
+
Philotic.config.message_return_handler = lambda do |basic_return, metadata, message|
|
10
|
+
Philotic.logger.warn "Message returned. reply_text: #{basic_return.reply_text}"
|
11
|
+
end
|
12
|
+
|
13
|
+
Philotic.subscriber.subscribe(header_key: 'header_1') do |metadata, message|
|
14
|
+
ap message[:attributes]
|
15
|
+
end
|
16
|
+
|
17
|
+
# normally we'd do:
|
18
|
+
#
|
19
|
+
# Philotic.subscriber.endure
|
20
|
+
#
|
21
|
+
# to keep the parent thread alive while the subscribers do their thing
|
22
|
+
# but this infinite publish loop takes care of that
|
23
|
+
loop do
|
24
|
+
Philotic::Event.publish({header_key: "header_#{[1, 2].sample}"}, {payload_key: 'payload_value'})
|
25
|
+
# only send a message every two seconds so we can see whats going on
|
26
|
+
sleep 2
|
27
|
+
end
|
@@ -5,24 +5,21 @@ $stdout.sync = true
|
|
5
5
|
require 'philotic'
|
6
6
|
require 'awesome_print'
|
7
7
|
|
8
|
-
philotic = Philotic::Connection.new
|
9
|
-
|
10
|
-
|
11
8
|
# sometimes ack
|
12
|
-
|
9
|
+
Philotic.subscriber.subscribe('flaky_queue', ack: true) do |metadata, message|
|
13
10
|
ap message[:attributes]
|
14
|
-
[true, false].sample ?
|
11
|
+
[true, false].sample ? Philotic.subscriber.acknowledge(message) : Philotic.subscriber.reject(message)
|
15
12
|
end
|
16
13
|
|
17
14
|
# always ack
|
18
|
-
|
15
|
+
Philotic.subscriber.subscribe('flaky_queue', ack: true) do |metadata, message|
|
19
16
|
ap message[:attributes]
|
20
|
-
|
17
|
+
Philotic.subscriber.acknowledge(message, true)
|
21
18
|
end
|
22
19
|
|
23
20
|
# always reject
|
24
|
-
|
21
|
+
Philotic.subscriber.subscribe('flaky_queue', ack: true) do |metadata, message|
|
25
22
|
ap message[:attributes]
|
26
|
-
|
23
|
+
Philotic.subscriber.reject message
|
27
24
|
end
|
28
|
-
|
25
|
+
Philotic.subscriber.endure
|
@@ -5,13 +5,10 @@ $stdout.sync = true
|
|
5
5
|
require 'philotic'
|
6
6
|
require 'awesome_print'
|
7
7
|
|
8
|
-
|
8
|
+
Philotic.config.load_file(File.join(File.dirname(__FILE__), '../../', 'Philotic.yml.example'))
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
philotic.subscriber.subscribe(philotic_firehose: true) do |metadata, message|
|
10
|
+
Philotic.subscriber.subscribe(philotic_firehose: true) do |metadata, message|
|
14
11
|
ap message[:attributes]
|
15
12
|
end
|
16
13
|
|
17
|
-
|
14
|
+
Philotic.subscriber.endure
|
@@ -4,17 +4,15 @@ $stdout.sync = true
|
|
4
4
|
|
5
5
|
require 'philotic'
|
6
6
|
require 'awesome_print'
|
7
|
-
philotic = Philotic::Connection.new
|
8
7
|
|
8
|
+
Philotic.config.load_file(File.join(File.dirname(__FILE__), '../../', 'Philotic.yml.example'))
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
philotic.subscriber.subscribe('female_queue') do |metadata, message|
|
10
|
+
Philotic.subscriber.subscribe('female_queue') do |metadata, message|
|
13
11
|
ap message[:attributes]
|
14
12
|
end
|
15
13
|
|
16
|
-
|
14
|
+
Philotic.subscriber.subscribe('male_queue') do |metadata, message|
|
17
15
|
ap message[:attributes]
|
18
16
|
end
|
19
17
|
|
20
|
-
|
18
|
+
Philotic.subscriber.endure
|
@@ -5,10 +5,8 @@ $stdout.sync = true
|
|
5
5
|
require 'philotic'
|
6
6
|
require 'awesome_print'
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
philotic.subscriber.subscribe('test_queue') do |metadata, message|
|
8
|
+
Philotic.subscriber.subscribe('test_queue') do |metadata, message|
|
11
9
|
ap message[:attributes]
|
12
10
|
end
|
13
11
|
|
14
|
-
|
12
|
+
Philotic.subscriber.endure
|
data/lib/philotic.rb
CHANGED
@@ -1,36 +1,19 @@
|
|
1
1
|
require 'active_support/all'
|
2
2
|
require 'pathname'
|
3
3
|
|
4
|
-
require 'philotic/constants'
|
5
|
-
require 'philotic/connection'
|
6
|
-
|
7
|
-
|
8
4
|
module Philotic
|
9
5
|
class << self
|
10
|
-
extend Forwardable
|
11
|
-
|
12
6
|
def root
|
13
7
|
::Pathname.new File.expand_path('../../', __FILE__)
|
14
8
|
end
|
15
|
-
|
16
|
-
def env
|
17
|
-
ENV['SERVICE_ENV'] || 'development'
|
18
|
-
end
|
19
|
-
|
20
|
-
def connection
|
21
|
-
@connection ||= Philotic::Connection.new
|
22
|
-
end
|
23
|
-
|
24
|
-
def method_missing(method, *args, &block)
|
25
|
-
connection.send(method, *args, &block)
|
26
|
-
end
|
27
|
-
|
28
|
-
def_delegators :connection, *(Philotic::Connection.public_instance_methods(false) - [:connection])
|
29
|
-
|
30
9
|
end
|
31
10
|
|
32
11
|
end
|
33
12
|
|
13
|
+
require 'philotic/constants'
|
14
|
+
require 'philotic/singleton'
|
15
|
+
|
16
|
+
require 'philotic/connection'
|
34
17
|
require 'philotic/version'
|
35
18
|
require 'philotic/config'
|
36
19
|
require 'philotic/routable'
|
data/lib/philotic/connection.rb
CHANGED
@@ -2,6 +2,7 @@ require 'json'
|
|
2
2
|
require 'bunny'
|
3
3
|
require 'logger'
|
4
4
|
|
5
|
+
require 'philotic/constants'
|
5
6
|
require 'philotic/config'
|
6
7
|
require 'philotic/publisher'
|
7
8
|
require 'philotic/subscriber'
|
@@ -119,7 +120,7 @@ module Philotic
|
|
119
120
|
end
|
120
121
|
|
121
122
|
def queue_from_config(queue_name, config)
|
122
|
-
queue_options = DEFAULT_NAMED_QUEUE_OPTIONS.dup
|
123
|
+
queue_options = Philotic::DEFAULT_NAMED_QUEUE_OPTIONS.dup
|
123
124
|
queue_options.merge!(config[:options] || {})
|
124
125
|
|
125
126
|
channel.queue(queue_name, queue_options).tap do
|
data/lib/philotic/dummy_event.rb
CHANGED
data/lib/philotic/event.rb
CHANGED
data/lib/philotic/publisher.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'philotic/connection'
|
2
|
+
|
3
|
+
module Philotic
|
4
|
+
class << self
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
def connection
|
8
|
+
@connection ||= Philotic::Connection.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def_delegators :connection, *(Philotic::Connection.public_instance_methods(false) - [:connection])
|
12
|
+
end
|
13
|
+
end
|
data/lib/philotic/subscriber.rb
CHANGED
@@ -5,17 +5,14 @@ namespace :philotic do
|
|
5
5
|
|
6
6
|
require 'philotic'
|
7
7
|
|
8
|
-
philotic = Philotic::Connection.new
|
9
|
-
|
10
8
|
# philotic.config.initialize_named_queues must be truthy to run Philotic.initialize_named_queue!
|
11
|
-
|
9
|
+
Philotic.config.initialize_named_queues = true
|
12
10
|
|
13
11
|
|
14
12
|
@filename = args[:filename]
|
15
13
|
queues = YAML.load_file(@filename)
|
16
|
-
philotic.connect!
|
17
14
|
queues.each_pair do |queue_name, queue_options|
|
18
|
-
|
15
|
+
Philotic.initialize_named_queue!(queue_name, queue_options)
|
19
16
|
end
|
20
17
|
end
|
21
18
|
end
|
data/lib/philotic/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: philotic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Keyes
|
@@ -169,7 +169,8 @@ files:
|
|
169
169
|
- examples/creating_named_queues/manually.rb
|
170
170
|
- examples/creating_named_queues/with_rake.rb
|
171
171
|
- examples/publishing/publish.rb
|
172
|
-
- examples/
|
172
|
+
- examples/simple_instance.rb
|
173
|
+
- examples/simple_singleton.rb
|
173
174
|
- examples/subscribing/acks.rb
|
174
175
|
- examples/subscribing/anonymous_queue.rb
|
175
176
|
- examples/subscribing/multiple_named_queues.rb
|
@@ -185,6 +186,7 @@ files:
|
|
185
186
|
- lib/philotic/logging/logger.rb
|
186
187
|
- lib/philotic/publisher.rb
|
187
188
|
- lib/philotic/routable.rb
|
189
|
+
- lib/philotic/singleton.rb
|
188
190
|
- lib/philotic/subscriber.rb
|
189
191
|
- lib/philotic/tasks.rb
|
190
192
|
- lib/philotic/tasks/init_queues.rb
|