fleck 1.0.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +11 -10
- data/CHANGELOG.md +89 -72
- data/Gemfile +6 -4
- data/examples/actions.rb +60 -53
- data/examples/blocking_consumer.rb +42 -42
- data/examples/consumer_initialization.rb +44 -42
- data/examples/deprecation.rb +50 -57
- data/examples/example.rb +76 -74
- data/examples/expired.rb +72 -76
- data/examples/fanout.rb +62 -64
- data/fleck.gemspec +37 -36
- data/lib/fleck/client.rb +124 -124
- data/lib/fleck/configuration.rb +149 -144
- data/lib/fleck/consumer.rb +7 -287
- data/lib/fleck/core/consumer/action_param.rb +106 -0
- data/lib/fleck/core/consumer/actions.rb +79 -0
- data/lib/fleck/core/consumer/base.rb +111 -0
- data/lib/fleck/core/consumer/configuration.rb +69 -0
- data/lib/fleck/core/consumer/decorators.rb +77 -0
- data/lib/fleck/core/consumer/helpers_definers.rb +56 -0
- data/lib/fleck/core/consumer/logger.rb +88 -0
- data/lib/fleck/core/consumer/request.rb +100 -0
- data/lib/fleck/core/consumer/response.rb +77 -0
- data/lib/fleck/core/consumer/response_helpers.rb +81 -0
- data/lib/fleck/core/consumer/validation.rb +163 -0
- data/lib/fleck/core/consumer.rb +166 -0
- data/lib/fleck/core.rb +9 -0
- data/lib/fleck/loggable.rb +15 -10
- data/lib/fleck/{hash_with_indifferent_access.rb → utilities/hash_with_indifferent_access.rb} +80 -85
- data/lib/fleck/utilities/host_rating.rb +104 -0
- data/lib/fleck/version.rb +6 -3
- data/lib/fleck.rb +81 -72
- metadata +36 -25
- data/lib/fleck/consumer/request.rb +0 -52
- data/lib/fleck/consumer/response.rb +0 -80
- data/lib/fleck/host_rating.rb +0 -74
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3877289696f65588095dc677e305c54af7a55e8145b7608a4c41a2ee9d12555d
|
4
|
+
data.tar.gz: 1ec2de10405c6b42e72a50e9a20d466dec9da666a9047451d421084c9fa51baf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96433348361bb72b516fb5c0c102ed71bc83b97c3db3bcd60535801c32435c42a37ab47f39b6a105e14ab424b6a7869009d7bb018d169e58e3bf81a3a7aa61e4
|
7
|
+
data.tar.gz: a33cf55738d71a88386da96867304783bf0ff0839e750d47033854322a72442f3563019f134b119287fc01a2ded13ba773a8d8bac87122dcf141ec461261a68e
|
data/.gitignore
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
/.bundle/
|
2
|
-
/.yardoc
|
3
|
-
/Gemfile.lock
|
4
|
-
/_yardoc/
|
5
|
-
/coverage/
|
6
|
-
/doc/
|
7
|
-
/pkg/
|
8
|
-
/spec/reports/
|
9
|
-
/tmp/
|
10
|
-
/*.gem
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
|
+
/*.gem
|
11
|
+
/.rubocop.yml
|
data/CHANGELOG.md
CHANGED
@@ -1,72 +1,89 @@
|
|
1
|
-
# CHANGELOG #
|
2
|
-
|
3
|
-
## develop ##
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
## v0.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
1
|
+
# CHANGELOG #
|
2
|
+
|
3
|
+
## develop ##
|
4
|
+
|
5
|
+
- **BREAKING CHANGE** Updated minimum required Ruby version to >= 2.5.
|
6
|
+
- **NEW** Refactore `Fleck::Consumer` in order to have a better code structure.
|
7
|
+
- **NEW** Implemented response helpers, which allow to terminate the request with desired status code and message.
|
8
|
+
- **NEW** Implemented action decorators, which allow to define an action and it's parameters directly before the method.
|
9
|
+
- **NEW** Implemented action params automatic validation, which can be set by using action decorators.
|
10
|
+
|
11
|
+
## v1.0.1 (2 April 2020) ##
|
12
|
+
|
13
|
+
- **BREAKING CHANGE** Updateg gemset, in order to be able to use new versions of Ruby.
|
14
|
+
|
15
|
+
## v0.7.0 (21 June 2016) ##
|
16
|
+
|
17
|
+
- **NEW** Added multihost support to Fleck configuration, that allows to manage network failure situations and to choose the best options from the list of available hosts.
|
18
|
+
This feature uses `Fleck::HostRating` to collect TCP latency data about each provided host, so that when a new connection is required, the host with lowest latency
|
19
|
+
will be choosed. If a host becomes unreachable, it gets the lowest rating and will be used as the last option, allowing you to automatically manage network failures.
|
20
|
+
- **NEW** Implemented a basic log filter for headers and params in requests and responses.
|
21
|
+
- **NEW** Log each processed request in `Fleck::Consumer::Response`.
|
22
|
+
- **NEW** Implemented `:deprecated?` method for `Fleck::Consumer::Response`.
|
23
|
+
- **NEW** Store client IP address to requests headers, in order to be able to trace requests origin when multiple clients making requests to the same consumer type.
|
24
|
+
|
25
|
+
## v0.6.0 (16 June 2016)##
|
26
|
+
|
27
|
+
- **NEW** __(BREAKING CHANGE)__ Use `"fleck"` exchange for RPC simulation, so that reply queues could be used in a RabbitMQ Federation configuration.
|
28
|
+
Be careful when upgrading `Fleck::Consumer` from version `v0.5.x` or below, because now `Fleck::Consumer` will send responses to a `:direct` exchange
|
29
|
+
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
|
30
|
+
newer version.
|
31
|
+
- **NEW** Added a filter that prevents from using reserved `Fleck::Consumer` methods as actions.
|
32
|
+
- **NEW** Implemented the feature that allows to start consumer in a blocking way.
|
33
|
+
- **NEW** Added `:prefetch` and `:mandatory` options to `Fleck::Consumer` configuration options.
|
34
|
+
|
35
|
+
## v0.5.1 (20 April 2016) ##
|
36
|
+
|
37
|
+
- **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
|
38
|
+
until the request expiration.
|
39
|
+
|
40
|
+
## v0.5.0 (20 April 2016) ##
|
41
|
+
|
42
|
+
- **NEW** Added `:autostart` option to `Fleck::Consumer` configuration, so that the developer could decide to start the consumer manually or automatically. By default
|
43
|
+
the consumer will start automatically.
|
44
|
+
- **NEW** Implemented the feature that allows to define an initialization block for `Fleck::Consumer`. This feature should be used to initialize consumer instance
|
45
|
+
variables so that it is not necessary to overwrite `Fleck::Consumer#initialize` method.
|
46
|
+
- **NEW** Implemented the feature that allows to define a map of actions to consumer methods, so that requests actions are automatically mapped to
|
47
|
+
consumer methods.
|
48
|
+
- **NEW** Implemented `#expired?` method for `Fleck::Client::Request`, that tells if the request is expired or not. It makes possible to
|
49
|
+
distinguish service unavailable responses from expired requests.
|
50
|
+
- **NEW** Added `:concurrency` option to `Fleck::Client`, that allows to specify the concurrency level for responses parsing.
|
51
|
+
- **NEW** Add `:version` option to `Fleck::Client#request` and implement `#version` method for `Fleck::Consumer::Request`.
|
52
|
+
- **NEW** Implemented `#request` and `#response` methods for `Fleck::Consumer`, so that you don't have to pass them as argument every time you
|
53
|
+
delegate the logic to a different method.
|
54
|
+
- **NEW** Implemented the feature that allows to deprecate actions within a consumer. Now you can call `deprecated!` inside a consumer to
|
55
|
+
reply with a response that is marked as **deprecated**.
|
56
|
+
- **NEW** Add `app_name` configuration, that allows to configure the default `app_id` to set for RabbitMQ messages.
|
57
|
+
- **NEW** Add process ID to logs, so that if you have multiple instances of the same application writting to the same log file, you'll be able to filter logs by process ID. Also changed logs format.
|
58
|
+
|
59
|
+
## v0.4.1 (18 April 2016) ##
|
60
|
+
|
61
|
+
- **FIX** Fixed a bug of `Fleck::Consumer::Request` class, that was causing errors when RabbitMQ message header wasn't set.
|
62
|
+
|
63
|
+
## v0.4.0 (15 April 2016) ##
|
64
|
+
|
65
|
+
- **NEW** Support different types of exchanges in both `Fleck::Client` and `Fleck::Consumer`.
|
66
|
+
- **FIX** Use `auto_delete` queue for `Fleck::Client`, so that it is deleted when the client is terminated.
|
67
|
+
- **NEW** Add `:rmq_options` option to `Fleck::Client::Request`, which can be used to pass options like `:persistent`, `mandatory`, etc.
|
68
|
+
to RabbitMQ message on publish.
|
69
|
+
- **NEW** Store `:headers` attribute of `Fleck::Client::Request` into RabbitMQ message `:headers`, so that in the future only
|
70
|
+
`:params` option will be converted to JSON.
|
71
|
+
- **NEW** Add `:action` option to `Fleck::Client::Request`, which will replace the action passed within `:headers` hash.
|
72
|
+
|
73
|
+
## v0.3.0 (1 April 2016) ##
|
74
|
+
|
75
|
+
- **FIX** Use `:compat` mode when using `Oj` gem to dump/load JSON content.
|
76
|
+
- **FIX** Prevent unnecessary `Fleck::Request` lock for response reception if the response already received.
|
77
|
+
- **NEW** Implemented a timeout functionality for asynchronous request, so that if the request isn't completed within that timeout, it will be canceled and removed from
|
78
|
+
requests list.
|
79
|
+
- **NEW** Set `mandatory: true` when publishing the request to RabbitMQ for both `Fleck::Client` and `Fleck::Consumer`, in order to ensure that requests and responses
|
80
|
+
are enqueued for sure to RabbitMQ.
|
81
|
+
- **NEW** Implemented `#pause` and `#resume` methods for `Fleck::Consumer`, that allows to pause the consumer from consuming messages.
|
82
|
+
- **NEW** `Fleck::Consumer::Response#reject!` support, that allows to reject the processed message. By default `requeue` parameter is set to `false`, so that
|
83
|
+
failed requests aren't requeued. You should call `response.reject(requeue: true)` within the `on_message` method, if you want to requeue the processing
|
84
|
+
message.
|
85
|
+
|
86
|
+
## v0.2.0 (18 February 2016) ##
|
87
|
+
|
88
|
+
- **NEW** `timeout` (synchronous requests only) and `queue` support for `Fleck::Client#request`
|
89
|
+
- **NEW** Keywords arguments for `Fleck::Client#request` method (ex. `client.request(headers: {h1: v1, ...}, params: {p1: v2, ...}`)
|
data/Gemfile
CHANGED
data/examples/actions.rb
CHANGED
@@ -1,53 +1,60 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#
|
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
|
-
|
13
|
-
|
14
|
-
config.
|
15
|
-
config.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
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
|
+
QUEUE = 'actions.example.queue'
|
12
|
+
|
13
|
+
Fleck.configure do |config|
|
14
|
+
config.default_user = user
|
15
|
+
config.default_pass = pass
|
16
|
+
config.loglevel = Logger::DEBUG
|
17
|
+
end
|
18
|
+
|
19
|
+
connection = Fleck.connection(host: '127.0.0.1', port: 5672, user: user, pass: pass, vhost: '/')
|
20
|
+
client = Fleck::Client.new(connection, QUEUE, concurrency: CONCURRENCY.to_i)
|
21
|
+
|
22
|
+
class MyConsumer < Fleck::Consumer
|
23
|
+
configure queue: QUEUE, concurrency: CONCURRENCY.to_i
|
24
|
+
|
25
|
+
action 'hello', "An action which returns 'Hello'"
|
26
|
+
def hello
|
27
|
+
ok! result: 'Hello', message: 'Ciao'
|
28
|
+
end
|
29
|
+
|
30
|
+
action 'ciao', "An action which returns 'Ciao'"
|
31
|
+
param :world, type: 'boolean', required: true, default: false
|
32
|
+
def my_custom_method
|
33
|
+
ok! params[:world] ? 'Ciao, Mondo!' : 'Ciao!'
|
34
|
+
end
|
35
|
+
|
36
|
+
action :aloha
|
37
|
+
param :number, type: 'integer', clamp: [1, 10], required: true
|
38
|
+
param :name, type: 'string', default: 'John Doe', required: true
|
39
|
+
def my_aloha
|
40
|
+
ok! "#{params[:number]}. Aloha, #{params[:name]}!"
|
41
|
+
end
|
42
|
+
|
43
|
+
def not_an_action
|
44
|
+
logger.warn("I'm not an action, so you should not be able to call me!")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
actions = %i[hello ciao aloha not_an_action]
|
49
|
+
|
50
|
+
SAMPLES.to_i.times do |num|
|
51
|
+
action = actions.sample
|
52
|
+
name = ['John Doe', 'Willie Wonka', 'Billie Smith'].sample
|
53
|
+
client.request(action: action, params: { num: num, name: name, number: rand * 100, world: %w[yes no].sample }, timeout: 5) do |_, response|
|
54
|
+
if response.status == 200
|
55
|
+
Fleck.logger.info "ACTION: (#{action.inspect}) #{response.body.inspect}"
|
56
|
+
else
|
57
|
+
Fleck.logger.error "ACTION: (#{action.inspect}) #{response.errors.join(', ')} --- #{response.body.inspect}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -1,42 +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 :) #{
|
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
|
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 :) #{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
|
+
Ztimer.async { self.class.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
|
@@ -1,42 +1,44 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#
|
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
|
-
|
13
|
-
|
14
|
-
config.
|
15
|
-
config.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
Fleck.logger.
|
40
|
-
|
41
|
-
|
42
|
-
end
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
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
|
+
QUEUE = 'consumer.initialization.example.queue'
|
12
|
+
|
13
|
+
Fleck.configure do |config|
|
14
|
+
config.default_user = user
|
15
|
+
config.default_pass = pass
|
16
|
+
config.loglevel = Logger::DEBUG
|
17
|
+
end
|
18
|
+
|
19
|
+
connection = Fleck.connection(host: '127.0.0.1', port: 5672, user: user, pass: pass, vhost: '/')
|
20
|
+
client = Fleck::Client.new(connection, QUEUE, concurrency: CONCURRENCY.to_i)
|
21
|
+
|
22
|
+
class MyConsumer < Fleck::Consumer
|
23
|
+
configure queue: QUEUE, concurrency: CONCURRENCY.to_i
|
24
|
+
actions :hello
|
25
|
+
|
26
|
+
initialize do
|
27
|
+
@value = "MY CONSUMER :) #{object_id}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def hello
|
31
|
+
logger.info '---------------- HELLO ----------------'
|
32
|
+
ok! "#{@value} Hello!"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
SAMPLES.to_i.times do |num|
|
37
|
+
client.request(action: 'hello', params: {num: num}, timeout: 5) do |_, response|
|
38
|
+
if response.status == 200
|
39
|
+
Fleck.logger.info response.body
|
40
|
+
else
|
41
|
+
Fleck.logger.error response.errors.join(', ')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/examples/deprecation.rb
CHANGED
@@ -1,57 +1,50 @@
|
|
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, "deprecation.example.queue", concurrency: CONCURRENCY.to_i)
|
20
|
-
|
21
|
-
class MyConsumer < Fleck::Consumer
|
22
|
-
configure queue: 'deprecation.example.queue', concurrency: CONCURRENCY.to_i
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
SAMPLES.to_i.times do |num|
|
55
|
-
response = client.request(action: 'hello', version: (rand >= 0.5 ? 'v2' : 'v1'), params: {num: num}, timeout: 5)
|
56
|
-
puts (response.deprecated? ? "DEPRECATED: #{response.body}" : response.body)
|
57
|
-
end
|
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, "deprecation.example.queue", concurrency: CONCURRENCY.to_i)
|
20
|
+
|
21
|
+
class MyConsumer < Fleck::Consumer
|
22
|
+
configure queue: 'deprecation.example.queue', concurrency: CONCURRENCY.to_i
|
23
|
+
|
24
|
+
action :hello
|
25
|
+
def hello
|
26
|
+
version = request.version || 'v1'
|
27
|
+
case version.to_s
|
28
|
+
when 'v1' then hello_v1
|
29
|
+
when 'v2' then hello_v2
|
30
|
+
else
|
31
|
+
not_found!
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def hello_v1
|
38
|
+
deprecated!
|
39
|
+
ok! "#{request.params[:num]}. Hello V1!"
|
40
|
+
end
|
41
|
+
|
42
|
+
def hello_v2
|
43
|
+
ok! "#{request.params[:num] + 1}. Hello V2!"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
SAMPLES.to_i.times do |num|
|
48
|
+
response = client.request(action: 'hello', version: (rand >= 0.5 ? 'v2' : 'v1'), params: {num: num}, timeout: 5)
|
49
|
+
puts (response.deprecated? ? "DEPRECATED: #{response.body}" : response.body)
|
50
|
+
end
|