fleck 2.2.1 → 2.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db2ce9b82ecb8b531a9bddabc20b2eee9619358bcc7d2914954936a1de838d04
4
- data.tar.gz: f74fff714edfca1e30c106031909a7d0bcef90535858c7e5abc04019b6f3c2f2
3
+ metadata.gz: 0d362b6a20a242296ef0697d57c31503067df64d05b3cee439f58449a7dbe732
4
+ data.tar.gz: 76f4a6b22cdfdff8a9826702073eae8866751e4c5446c1d7fdd1aaecd6341655
5
5
  SHA512:
6
- metadata.gz: 79c6e83ca6f93e1377df5aaa318c22a650ccbd970120d490f60bd39316a19682a1638691794bd05acdc4a3cd95396e4f5553110c5df8f654ce727233e912c252
7
- data.tar.gz: 7052ed477e244d917977e1872f089bc3d5e9f5b2e612e6e4bb5e77cb5e6883530e0fdf1c0f75e0502bb0756ef1669c53341198fc67e21f81134ce61026207984
6
+ metadata.gz: 794a481e65666fa6ac3be6bd7014d0a20a54819849f2be83402950778de70d24728d3bd283a1fb71332504acb501fe7323e315dbcf9f20f4fe8c229e74120611
7
+ data.tar.gz: 42c5b8f0dd478e595d47bde2250a5d01d4b81414ad9670288a1098bb6f7168b71949a8401e848b3f6d2e4d163d23babb70259695ccaa7314fad962b9084a0b1f
data/.gitignore CHANGED
@@ -1,11 +1,11 @@
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
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/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- # Specify your gem's dependencies in fleck.gemspec
6
- gemspec
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in fleck.gemspec
6
+ gemspec
data/examples/actions.rb CHANGED
@@ -1,60 +1,60 @@
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
+ #!/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 :) #{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
+ #!/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,44 +1,44 @@
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
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
@@ -1,50 +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
- 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
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
data/examples/example.rb CHANGED
@@ -1,76 +1,76 @@
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'] || 10).to_i
10
- SAMPLES = (ENV['SAMPLES'] || 10_000).to_i
11
- QUEUE = '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
- client = Fleck::Client.new(Fleck.connection, QUEUE, concurrency: CONCURRENCY.to_i)
20
-
21
- count = 0
22
- success = 0
23
- failure = 0
24
-
25
- mutex = Mutex.new
26
- lock = Mutex.new
27
- condition = ConditionVariable.new
28
-
29
- class First < Fleck::Consumer
30
- configure queue: QUEUE, concurrency: CONCURRENCY.to_i
31
-
32
- action :incr, 'Returns a message with incremented number'
33
- param :num, type: 'number', required: true
34
- def incr
35
- if rand > 0.1
36
- not_found! if request.action != 'incr'
37
-
38
- ok! "#{params[:num].to_i + 1}. Hello, World!"
39
- else
40
- logger.warn "REJECTING REQUEST {headers: #{headers}, params: #{params}"
41
- request.reject!(requeue: true)
42
- end
43
- end
44
- end
45
-
46
- Thread.new do
47
- SAMPLES.times do |i|
48
- client.request(
49
- action: 'incr',
50
- params: { num: i, secret: 'supersecret' },
51
- async: true,
52
- timeout: 1,
53
- rmq_options: { priority: (rand * 9).round(0), mandatory: false }
54
- ) do |request, response|
55
- if response.status == 200
56
- request.logger.debug response.body
57
- else
58
- request.logger.error "#{response.status} #{response.errors.join(', ')}"
59
- end
60
- mutex.synchronize do
61
- count += 1
62
- if response.status == 200
63
- success += 1
64
- else
65
- failure += 1
66
- end
67
-
68
- lock.synchronize { condition.signal } if count >= SAMPLES
69
- end
70
- end
71
- end
72
- end
73
-
74
- lock.synchronize { condition.wait(lock) }
75
-
76
- puts "Total: #{count}, Success: #{success}, Failure: #{failure}"
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'] || 10).to_i
10
+ SAMPLES = (ENV['SAMPLES'] || 10_000).to_i
11
+ QUEUE = '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
+ client = Fleck::Client.new(Fleck.connection, QUEUE, concurrency: CONCURRENCY.to_i)
20
+
21
+ count = 0
22
+ success = 0
23
+ failure = 0
24
+
25
+ mutex = Mutex.new
26
+ lock = Mutex.new
27
+ condition = ConditionVariable.new
28
+
29
+ class First < Fleck::Consumer
30
+ configure queue: QUEUE, concurrency: CONCURRENCY.to_i
31
+
32
+ action :incr, 'Returns a message with incremented number'
33
+ param :num, type: 'number', required: true
34
+ def incr
35
+ if rand > 0.1
36
+ not_found! if request.action != 'incr'
37
+
38
+ ok! "#{params[:num].to_i + 1}. Hello, World!"
39
+ else
40
+ logger.warn "REJECTING REQUEST {headers: #{headers}, params: #{params}"
41
+ request.reject!(requeue: true)
42
+ end
43
+ end
44
+ end
45
+
46
+ Thread.new do
47
+ SAMPLES.times do |i|
48
+ client.request(
49
+ action: 'incr',
50
+ params: { num: i, secret: 'supersecret' },
51
+ async: true,
52
+ timeout: 1,
53
+ rmq_options: { priority: (rand * 9).round(0), mandatory: false }
54
+ ) do |request, response|
55
+ if response.status == 200
56
+ request.logger.debug response.body
57
+ else
58
+ request.logger.error "#{response.status} #{response.errors.join(', ')}"
59
+ end
60
+ mutex.synchronize do
61
+ count += 1
62
+ if response.status == 200
63
+ success += 1
64
+ else
65
+ failure += 1
66
+ end
67
+
68
+ lock.synchronize { condition.signal } if count >= SAMPLES
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ lock.synchronize { condition.wait(lock) }
75
+
76
+ puts "Total: #{count}, Success: #{success}, Failure: #{failure}"