message_bus 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of message_bus might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG +6 -0
- data/lib/message_bus/backends/memory.rb +1 -1
- data/lib/message_bus/backends/postgres.rb +5 -2
- data/lib/message_bus/backends/redis.rb +8 -2
- data/lib/message_bus/version.rb +1 -1
- data/lib/message_bus.rb +10 -1
- data/spec/lib/message_bus/backends/redis_spec.rb +18 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6aa05eed76182bd5fe219675994c62e4bbab64a4
|
4
|
+
data.tar.gz: cbc5bb1dee813ae31140818862684fb000640e0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74a3cf289846f5d2f69562655ca2da052e62f9c069be0e4ecc6621031511da9595f35992130266e622ea707fa808b2e80ba2a7af3919067de9fec4c165c4e026
|
7
|
+
data.tar.gz: 67f93e82846a5ca0ead95bd1cc3aa04de4ef284ba9142d2b6127c8631bdcfb422be74a665129f150fe0c70615d52ea1341737e0b0f2ce87db6c7daae2f587161
|
data/CHANGELOG
CHANGED
@@ -164,7 +164,7 @@ class MessageBus::Memory::ReliablePubSub
|
|
164
164
|
client.reset!
|
165
165
|
end
|
166
166
|
|
167
|
-
def publish(channel, data,
|
167
|
+
def publish(channel, data, opts = nil)
|
168
168
|
client = self.client
|
169
169
|
backlog_id = client.add(channel, data)
|
170
170
|
if backlog_id % clear_every == 0
|
@@ -31,7 +31,7 @@ class MessageBus::Postgres::Client
|
|
31
31
|
@pid = Process.pid
|
32
32
|
end
|
33
33
|
|
34
|
-
def add
|
34
|
+
def add(channel, value)
|
35
35
|
hold { |conn| exec_prepared(conn, 'insert_message', [channel, value]) { |r| r.getvalue(0, 0).to_i } }
|
36
36
|
end
|
37
37
|
|
@@ -256,7 +256,10 @@ class MessageBus::Postgres::ReliablePubSub
|
|
256
256
|
client.reset!
|
257
257
|
end
|
258
258
|
|
259
|
-
def publish(channel, data,
|
259
|
+
def publish(channel, data, opts = nil)
|
260
|
+
|
261
|
+
# TODO in memory queue?
|
262
|
+
|
260
263
|
client = self.client
|
261
264
|
backlog_id = client.add(channel, data)
|
262
265
|
msg = MessageBus::Message.new backlog_id, backlog_id, channel, data
|
@@ -125,7 +125,12 @@ LUA
|
|
125
125
|
|
126
126
|
LUA_PUBLISH_SHA1 = Digest::SHA1.hexdigest(LUA_PUBLISH)
|
127
127
|
|
128
|
-
def publish(channel, data,
|
128
|
+
def publish(channel, data, opts = nil)
|
129
|
+
queue_in_memory = (opts && opts[:queue_in_memory]) != false
|
130
|
+
|
131
|
+
max_backlog_age = (opts && opts[:max_backlog_age]) || self.max_backlog_age
|
132
|
+
max_backlog_size = (opts && opts[:max_backlog_size]) || self.max_backlog_size
|
133
|
+
|
129
134
|
redis = pub_redis
|
130
135
|
backlog_id_key = backlog_id_key(channel)
|
131
136
|
backlog_key = backlog_key(channel)
|
@@ -190,7 +195,8 @@ LUA
|
|
190
195
|
end
|
191
196
|
|
192
197
|
begin
|
193
|
-
|
198
|
+
# TODO recover special options
|
199
|
+
publish(*@in_memory_backlog[0], queue_in_memory: false)
|
194
200
|
rescue Redis::CommandError => e
|
195
201
|
if e.message =~ /^READONLY/
|
196
202
|
try_again = true
|
data/lib/message_bus/version.rb
CHANGED
data/lib/message_bus.rb
CHANGED
@@ -236,7 +236,16 @@ module MessageBus::Implementation
|
|
236
236
|
client_ids: client_ids
|
237
237
|
)
|
238
238
|
|
239
|
-
|
239
|
+
channel_opts = nil
|
240
|
+
|
241
|
+
if opts && ((age = opts[:max_backlog_age]) || (size = opts[:max_backlog_size]))
|
242
|
+
channel_opts = {
|
243
|
+
max_backlog_size: size,
|
244
|
+
max_backlog_age: age
|
245
|
+
}
|
246
|
+
end
|
247
|
+
|
248
|
+
reliable_pub_sub.publish(encode_channel_name(channel), encoded_data, channel_opts)
|
240
249
|
end
|
241
250
|
|
242
251
|
def blocking_subscribe(channel = nil, &blk)
|
@@ -52,6 +52,24 @@ if MESSAGE_BUS_CONFIG[:backend] == :redis
|
|
52
52
|
@bus.pub_redis.ttl(@bus.backlog_key("/foo")).must_be :>, 0
|
53
53
|
end
|
54
54
|
|
55
|
+
it "can set backlog age on publish" do
|
56
|
+
@bus.max_backlog_age = 100
|
57
|
+
|
58
|
+
@bus.publish "/foo", "bar", max_backlog_age: 50
|
59
|
+
@bus.pub_redis.ttl(@bus.backlog_key("/foo")).must_be :<=, 50
|
60
|
+
@bus.pub_redis.ttl(@bus.backlog_key("/foo")).must_be :>, 0
|
61
|
+
end
|
62
|
+
|
63
|
+
it "can set backlog size on publish" do
|
64
|
+
@bus.max_backlog_size = 100
|
65
|
+
|
66
|
+
@bus.publish "/foo", "bar", max_backlog_size: 2
|
67
|
+
@bus.publish "/foo", "bar", max_backlog_size: 2
|
68
|
+
@bus.publish "/foo", "bar", max_backlog_size: 2
|
69
|
+
|
70
|
+
@bus.backlog("/foo").length.must_equal 2
|
71
|
+
end
|
72
|
+
|
55
73
|
it "should be able to access the backlog" do
|
56
74
|
@bus.publish "/foo", "bar"
|
57
75
|
@bus.publish "/foo", "baz"
|