message_bus 2.1.0 → 2.1.1

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.

Potentially problematic release.


This version of message_bus might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6609e7158e64715d6113ffb1c2d61d99c919d16b
4
- data.tar.gz: d561cb2c1342bc50cca592676f7f45c6eb50326e
3
+ metadata.gz: 6aa05eed76182bd5fe219675994c62e4bbab64a4
4
+ data.tar.gz: cbc5bb1dee813ae31140818862684fb000640e0d
5
5
  SHA512:
6
- metadata.gz: 9f42d527e19b5a9e15edabb29198a860447fb2e57697b2d946aa1bac26e5d2c8eec860a8839ff6fede461e61a050c806ae9fbfba39ff6e2ae0a945238d3921e6
7
- data.tar.gz: 271dc3f565aa0dde4f2e513f5fb9cddaf4e59680bbe5b87136708c042020de47c9469cdf56d8f9d5025ce1272138e9ac7b4adfde5713ed896b7a9002bf8cbc42
6
+ metadata.gz: 74a3cf289846f5d2f69562655ca2da052e62f9c069be0e4ecc6621031511da9595f35992130266e622ea707fa808b2e80ba2a7af3919067de9fec4c165c4e026
7
+ data.tar.gz: 67f93e82846a5ca0ead95bd1cc3aa04de4ef284ba9142d2b6127c8631bdcfb422be74a665129f150fe0c70615d52ea1341737e0b0f2ce87db6c7daae2f587161
data/CHANGELOG CHANGED
@@ -1,5 +1,11 @@
1
1
  18-12-2017
2
2
 
3
+ - Version 2.1.1
4
+
5
+ - FEATURE: allow setting of max_backlog_size and max_backlog_age on publish for redis provider
6
+
7
+ 18-12-2017
8
+
3
9
  - Version 2.1.0
4
10
 
5
11
  - FEATURE: you can now lookup last N messages on channel on subscribe from JavaScript
@@ -164,7 +164,7 @@ class MessageBus::Memory::ReliablePubSub
164
164
  client.reset!
165
165
  end
166
166
 
167
- def publish(channel, data, queue_in_memory = true)
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 (channel, value)
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, queue_in_memory = true)
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, queue_in_memory = true)
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
- publish(*@in_memory_backlog[0], false)
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
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module MessageBus
3
- VERSION = "2.1.0"
3
+ VERSION = "2.1.1"
4
4
  end
data/lib/message_bus.rb CHANGED
@@ -236,7 +236,16 @@ module MessageBus::Implementation
236
236
  client_ids: client_ids
237
237
  )
238
238
 
239
- reliable_pub_sub.publish(encode_channel_name(channel), encoded_data)
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"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: message_bus
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron