beetle 3.3.8 → 3.3.9
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/RELEASE_NOTES.rdoc +6 -0
- data/lib/beetle/configuration.rb +4 -0
- data/lib/beetle/queue_properties.rb +21 -5
- data/lib/beetle/version.rb +1 -1
- data/test/beetle/queue_properties_test.rb +30 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95e3ab98a559390c7f20bb68ae99e8636c82df9a66fff22413c73459d9ff6332
|
4
|
+
data.tar.gz: dd0e5868943f6b2cdb9d73037851da75b380171487a0f5cb29328a8e44aaec40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbec6f5dcf9bdd429442cea86190bed2960038d31241781b5a748586a76038e060654bd91c0f559b3f17ee57e41b97017859549c3c11523df76ccfddde3d022b
|
7
|
+
data.tar.gz: '091e597c4b84ec2bf72d14ae1875ee6e44d39770b82968c803cc4029c26d252aa24eb53f88c4893ef0f98acb496ea2c691a5bcb4f829ac1ae174228e705da852'
|
data/RELEASE_NOTES.rdoc
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
= Release Notes
|
2
2
|
|
3
|
+
== Version 3.3.9
|
4
|
+
* Reduce the number of queue policies created on the servers by allowing
|
5
|
+
the spefication of a default broker policy. You need to install the
|
6
|
+
default policy with a priority of zero to match all queues ever
|
7
|
+
created. This feature is optional.
|
8
|
+
|
3
9
|
== Version 3.3.8
|
4
10
|
* Avoid needless put call when updating queue policies.
|
5
11
|
It seems the additional call to get the current definition of a policy
|
data/lib/beetle/configuration.rb
CHANGED
@@ -14,6 +14,9 @@ module Beetle
|
|
14
14
|
# Name of the policy update routing key
|
15
15
|
attr_accessor :beetle_policy_updates_routing_key
|
16
16
|
# default logger (defaults to <tt>Logger.new(log_file)</tt>)
|
17
|
+
attr_accessor :broker_default_policy
|
18
|
+
# set this to whatever your brokers have installed as default policy. For example, if you have installed
|
19
|
+
# a policy that makes every queue lazy, it should be set to <tt>{"queue-moode" => "lazy"}</tt>.
|
17
20
|
attr_accessor :logger
|
18
21
|
# defaults to <tt>STDOUT</tt>
|
19
22
|
attr_accessor :redis_logger
|
@@ -146,6 +149,7 @@ module Beetle
|
|
146
149
|
self.beetle_policy_exchange_name = "beetle-policies"
|
147
150
|
self.beetle_policy_updates_queue_name = "beetle-policy-updates"
|
148
151
|
self.beetle_policy_updates_routing_key = "beetle.policy.update"
|
152
|
+
self.broker_default_policy = {}
|
149
153
|
|
150
154
|
self.gc_threshold = 1.hour.to_i
|
151
155
|
self.redis_server = "localhost:6379"
|
@@ -45,9 +45,11 @@ module Beetle
|
|
45
45
|
return unless options[:dead_lettering] || options[:lazy]
|
46
46
|
|
47
47
|
# no need to worry that the server has the port 5672. Net:HTTP will take care of this. See below.
|
48
|
-
|
48
|
+
policy_name = "#{queue_name}_policy"
|
49
|
+
request_url = URI("http://#{server}/api/policies/#{vhost}/#{policy_name}")
|
49
50
|
get_request = Net::HTTP::Get.new(request_url)
|
50
51
|
put_request = Net::HTTP::Put.new(request_url)
|
52
|
+
delete_request = Net::HTTP::Delete.new(request_url)
|
51
53
|
|
52
54
|
# set up queue policy
|
53
55
|
definition = {}
|
@@ -66,13 +68,26 @@ module Beetle
|
|
66
68
|
"definition" => definition,
|
67
69
|
}
|
68
70
|
|
71
|
+
is_default_policy = definition == config.broker_default_policy
|
72
|
+
|
69
73
|
get_response = run_rabbit_http_request(request_url, get_request) do |http|
|
70
74
|
http.request(get_request, nil)
|
71
75
|
end
|
72
76
|
|
73
|
-
|
77
|
+
case get_response.code
|
78
|
+
when "200"
|
74
79
|
response_body = JSON.parse(get_response.body) rescue {}
|
75
|
-
|
80
|
+
same_policy = put_request_body.all? { |k,v| response_body[k] == v }
|
81
|
+
if same_policy
|
82
|
+
if is_default_policy
|
83
|
+
run_rabbit_http_request(request_url, delete_request) do |http|
|
84
|
+
http.request(get_request, nil)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
return :ok
|
88
|
+
end
|
89
|
+
when "404"
|
90
|
+
return :ok if is_default_policy
|
76
91
|
end
|
77
92
|
|
78
93
|
put_response = run_rabbit_http_request(request_url, put_request) do |http|
|
@@ -141,9 +156,10 @@ module Beetle
|
|
141
156
|
|
142
157
|
def run_rabbit_http_request(uri, request, &block)
|
143
158
|
request.basic_auth(config.user, config.password)
|
144
|
-
|
159
|
+
case request.class::METHOD
|
160
|
+
when 'GET'
|
145
161
|
request["Accept"] = "application/json"
|
146
|
-
|
162
|
+
when 'PUT'
|
147
163
|
request["Content-Type"] = "application/json"
|
148
164
|
end
|
149
165
|
http = Net::HTTP.new(uri.hostname, config.api_port)
|
data/lib/beetle/version.rb
CHANGED
@@ -78,6 +78,36 @@ module Beetle
|
|
78
78
|
@queue_properties.set_queue_policy!(@server, @queue_name, :lazy => false, :dead_lettering => true, :routing_key => "QUEUE_NAME_dead_letter")
|
79
79
|
end
|
80
80
|
|
81
|
+
test "deletes policy if its definition corresponds to the broker default policy" do
|
82
|
+
@config.broker_default_policy = { "queue-mode" => "lazy" }
|
83
|
+
stub_request(:get, "http://localhost:15672/api/policies/%2F/QUEUE_NAME_policy")
|
84
|
+
.with(basic_auth: ['guest', 'guest'])
|
85
|
+
.to_return(:status => 200,
|
86
|
+
:body => {
|
87
|
+
"vhost" => "/",
|
88
|
+
"name" => "QUEUE_NAME_policy",
|
89
|
+
"pattern" => "^QUEUE_NAME$",
|
90
|
+
"priority" => 1,
|
91
|
+
"apply-to" => "queues",
|
92
|
+
"definition" => {
|
93
|
+
"queue-mode" => "lazy",
|
94
|
+
}}.to_json)
|
95
|
+
stub_request(:delete, "http://localhost:15672/api/policies/%2F/QUEUE_NAME_policy")
|
96
|
+
.with(basic_auth: ['guest', 'guest'])
|
97
|
+
.to_return(:status => 204)
|
98
|
+
|
99
|
+
@queue_properties.set_queue_policy!(@server, @queue_name, :lazy => true, :dead_lettering => false, :routing_key => "QUEUE_NAME_dead_letter")
|
100
|
+
end
|
101
|
+
|
102
|
+
test "does nothing if its definition corresponds to the broker default policy and the policy does not exist on the server" do
|
103
|
+
@config.broker_default_policy = { "queue-mode" => "lazy" }
|
104
|
+
stub_request(:get, "http://localhost:15672/api/policies/%2F/QUEUE_NAME_policy")
|
105
|
+
.with(basic_auth: ['guest', 'guest'])
|
106
|
+
.to_return(:status => 404)
|
107
|
+
|
108
|
+
@queue_properties.set_queue_policy!(@server, @queue_name, :lazy => true, :dead_lettering => false, :routing_key => "QUEUE_NAME_dead_letter")
|
109
|
+
end
|
110
|
+
|
81
111
|
test "creates a policy by posting to the rabbitmq if lazy queues are enabled" do
|
82
112
|
stub_request(:get, "http://localhost:15672/api/policies/%2F/QUEUE_NAME_policy")
|
83
113
|
.with(basic_auth: ['guest', 'guest'])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beetle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.3.
|
4
|
+
version: 3.3.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Kaes
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2020-05-
|
15
|
+
date: 2020-05-21 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: bunny
|