fleck 0.5.1 → 0.6.0.rc1
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/CHANGELOG.md +9 -0
- data/examples/blocking_consumer.rb +42 -0
- data/lib/fleck/client.rb +3 -2
- data/lib/fleck/consumer.rb +13 -6
- data/lib/fleck/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ed2d8327cd0b426a6b0cc46ea6cb419c9d13e7b
|
4
|
+
data.tar.gz: 35a37db895a6747cdd10b81727f71c6bbafe7ef1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d29b40d7fc239bd4270953332af99b4274dbb164467c2ce02047bf3495bba035d8cf86f26c5e00fa253160d3378d9b27127c35fbc291005f41adb419580cb99
|
7
|
+
data.tar.gz: c70db6dbf8db14d47a937a87092b476e5acc54f812a587698841f38b0e1c7f92162107de715fc8a409377ffd7ad8105df82660371c4899fa2334c6d80801f783
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,15 @@
|
|
2
2
|
|
3
3
|
## develop ##
|
4
4
|
|
5
|
+
## v0.6.0 (16 June 2016)
|
6
|
+
- **NEW** __(BREAKING CHANGE)__ Use `"fleck"` exchange for RPC simulation, so that reply queues could be used in a RabbitMQ Federation configuration.
|
7
|
+
Be careful when upgrading `Fleck::Consumer` from version `v0.5.x` or below, because now `Fleck::Consumer` will send responses to a `:direct` exchange
|
8
|
+
named `"fleck"`. If there're `Fleck::Clients` that are at version `v0.5.x` or below, they will not be able to receive the response from consumers of a
|
9
|
+
newer version.
|
10
|
+
- **NEW** Added a filter that prevents from using reserved `Fleck::Consumer` methods as actions.
|
11
|
+
- **NEW** Implemented the feature that allows to start consumer in a blocking way.
|
12
|
+
- **NEW** Added `:prefetch` and `:mandatory` options to `Fleck::Consumer` configuration options.
|
13
|
+
|
5
14
|
## v0.5.1 (20 April 2016)
|
6
15
|
- **FIX** Don't expire requests with multiple responses if any response is received. Treat that kind of request as expired if no response has been received
|
7
16
|
until the request expiration.
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'fleck'
|
5
|
+
|
6
|
+
user = ENV['USER'] || 'guest'
|
7
|
+
pass = ENV['PASS'] || 'guest'
|
8
|
+
|
9
|
+
CONCURRENCY = (ENV['CONCURRENCY'] || 2).to_i
|
10
|
+
SAMPLES = (ENV['SAMPLES'] || 10).to_i
|
11
|
+
|
12
|
+
Fleck.configure do |config|
|
13
|
+
config.default_user = user
|
14
|
+
config.default_pass = pass
|
15
|
+
config.loglevel = Logger::DEBUG
|
16
|
+
end
|
17
|
+
|
18
|
+
connection = Fleck.connection(host: "127.0.0.1", port: 5672, user: user, pass: pass, vhost: "/")
|
19
|
+
client = Fleck::Client.new(connection, "blocking.consumer.example.queue")
|
20
|
+
|
21
|
+
class MyConsumer < Fleck::Consumer
|
22
|
+
configure queue: 'blocking.consumer.example.queue', autostart: false
|
23
|
+
actions :quit
|
24
|
+
|
25
|
+
initialize do
|
26
|
+
@value = "MY CONSUMER :) #{self.object_id}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def quit
|
30
|
+
logger.debug "Quit message received, but I'm goint to sleep for 2 seconds ..."
|
31
|
+
sleep 2
|
32
|
+
logger.debug "Let's terminate this example!"
|
33
|
+
terminate
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
client.request(action: 'quit', timeout: 5, async: true)
|
38
|
+
|
39
|
+
MyConsumer.start(block: true)
|
40
|
+
|
41
|
+
puts "We did it :)"
|
42
|
+
sleep 0.01 # Give some time to Bunny to cancel subscribtions and to close channels and connections
|
data/lib/fleck/client.rb
CHANGED
@@ -15,9 +15,10 @@ module Fleck
|
|
15
15
|
@mutex = Mutex.new
|
16
16
|
|
17
17
|
@channel = @connection.create_channel
|
18
|
-
@exchange = @channel
|
19
|
-
@publisher = Bunny::Exchange.new(@
|
18
|
+
@exchange = Bunny::Exchange.new(@channel, :direct, 'fleck')
|
19
|
+
@publisher = Bunny::Exchange.new(@connection.create_channel, exchange_type, exchange_name)
|
20
20
|
@reply_queue = @channel.queue("", exclusive: true, auto_delete: true)
|
21
|
+
@reply_queue.bind(@exchange, routing_key: @reply_queue.name)
|
21
22
|
|
22
23
|
handle_returned_messages!
|
23
24
|
@concurrency.times { handle_responses! }
|
data/lib/fleck/consumer.rb
CHANGED
@@ -31,6 +31,7 @@ module Fleck
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def self.register_action(action, method_name)
|
34
|
+
raise ArgumentError.new("Cannot use `:#{method_name}` method as an action, because it is reserved for Fleck::Consumer internal stuff!") if Fleck::Consumer.instance_methods.include?(method_name.to_s.to_sym)
|
34
35
|
self.actions_map[action.to_s] = method_name.to_s
|
35
36
|
end
|
36
37
|
|
@@ -38,9 +39,9 @@ module Fleck
|
|
38
39
|
self.initialize_block = block
|
39
40
|
end
|
40
41
|
|
41
|
-
def self.start
|
42
|
+
def self.start(block: false)
|
42
43
|
self.consumers.each do |consumer|
|
43
|
-
consumer.start
|
44
|
+
consumer.start(block: block)
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
@@ -77,6 +78,8 @@ module Fleck
|
|
77
78
|
@__consumer_tag = nil
|
78
79
|
@__request = nil
|
79
80
|
@__response = nil
|
81
|
+
@__lock = Mutex.new
|
82
|
+
@__lounger = ConditionVariable.new
|
80
83
|
|
81
84
|
@__host = configs[:host]
|
82
85
|
@__port = configs[:port]
|
@@ -87,6 +90,8 @@ module Fleck
|
|
87
90
|
@__exchange_name = configs[:exchange_name] || ""
|
88
91
|
@__queue_name = configs[:queue]
|
89
92
|
@__autostart = configs[:autostart]
|
93
|
+
@__prefetch = (configs[:prefetch] || 100).to_i
|
94
|
+
@__mandatory = !!configs[:mandatory]
|
90
95
|
|
91
96
|
if self.class.initialize_block
|
92
97
|
self.instance_eval(&self.class.initialize_block)
|
@@ -101,10 +106,11 @@ module Fleck
|
|
101
106
|
end
|
102
107
|
end
|
103
108
|
|
104
|
-
def start
|
109
|
+
def start(block: false)
|
105
110
|
connect!
|
106
111
|
create_channel!
|
107
112
|
subscribe!
|
113
|
+
@__lock.synchronize{ @__lounger.wait(@__lock) } if block
|
108
114
|
end
|
109
115
|
|
110
116
|
def on_message(request, response)
|
@@ -117,6 +123,7 @@ module Fleck
|
|
117
123
|
end
|
118
124
|
|
119
125
|
def terminate
|
126
|
+
@__lock.synchronize { @__lounger.signal }
|
120
127
|
pause
|
121
128
|
unless channel.nil? || channel.closed?
|
122
129
|
channel.close
|
@@ -202,8 +209,8 @@ module Fleck
|
|
202
209
|
|
203
210
|
logger.debug "Creating a new channel for #{self.class.to_s.color(:yellow)} consumer"
|
204
211
|
@__channel = @__connection.create_channel
|
205
|
-
@__channel.prefetch(
|
206
|
-
@__publisher = @
|
212
|
+
@__channel.prefetch(@__prefetch) # consume messages in batches
|
213
|
+
@__publisher = Bunny::Exchange.new(@__connection.create_channel, :direct, 'fleck')
|
207
214
|
if @__exchange_type == :direct && @__exchange_name == ""
|
208
215
|
@__queue = @__channel.queue(@__queue_name, auto_delete: false)
|
209
216
|
else
|
@@ -243,7 +250,7 @@ module Fleck
|
|
243
250
|
if @__channel.closed?
|
244
251
|
logger.warn "Channel already closed! The response #{metadata.correlation_id} is going to be dropped."
|
245
252
|
else
|
246
|
-
@__publisher.publish(@__response.to_json, routing_key: metadata.reply_to, correlation_id: metadata.correlation_id, mandatory:
|
253
|
+
@__publisher.publish(@__response.to_json, routing_key: metadata.reply_to, correlation_id: metadata.correlation_id, mandatory: @__mandatory)
|
247
254
|
@__channel.ack(delivery_info.delivery_tag)
|
248
255
|
end
|
249
256
|
end
|
data/lib/fleck/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fleck
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Groza Sergiu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -143,6 +143,7 @@ files:
|
|
143
143
|
- bin/console
|
144
144
|
- bin/setup
|
145
145
|
- examples/actions.rb
|
146
|
+
- examples/blocking_consumer.rb
|
146
147
|
- examples/consumer_initialization.rb
|
147
148
|
- examples/deprecation.rb
|
148
149
|
- examples/example.rb
|
@@ -176,12 +177,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
176
177
|
version: '2.0'
|
177
178
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
178
179
|
requirements:
|
179
|
-
- - "
|
180
|
+
- - ">"
|
180
181
|
- !ruby/object:Gem::Version
|
181
|
-
version:
|
182
|
+
version: 1.3.1
|
182
183
|
requirements: []
|
183
184
|
rubyforge_project:
|
184
|
-
rubygems_version: 2.4.
|
185
|
+
rubygems_version: 2.4.8
|
185
186
|
signing_key:
|
186
187
|
specification_version: 4
|
187
188
|
summary: A Ruby gem for syncronous and asyncronous communication via Message Queue
|