tiny_bus 3.1.0 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tiny_bus.rb +16 -9
- 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: 27b59f1cbc599aa563486a8fb29274e2369b1099dc01523f96b14bc9f3f0d06f
|
4
|
+
data.tar.gz: e8f3511275ca57d791808e343e9f70e4855cbaea72a1eb119935b09b4acbbb4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adfd193f7b1c3f55c66f86d5a096d21b0d1d8e5fb04c2c978cf9885cdb8663ca3d2850dfda25c4debb4b93e5407dd601428f76a184a72f7a1210b0abf7a2ce03
|
7
|
+
data.tar.gz: 34c31596855df2ac266fd839de02b84c1827cc64ec4ecf2d295cf98748364604be1285c9b0efb9278392fadadd23553d5d342cb76f9b67a037c12c51443361c0
|
data/lib/tiny_bus.rb
CHANGED
@@ -6,7 +6,7 @@ require 'tiny_pipe'
|
|
6
6
|
|
7
7
|
# NOTE: This library depends on the TinyLog library.
|
8
8
|
#
|
9
|
-
# This class implements a very
|
9
|
+
# This class implements a very simple PubSub system where:
|
10
10
|
# - subscribers can subscribe via the #sub method
|
11
11
|
# - subscribers can unsubscribe via the #unsub method
|
12
12
|
# - msgs can enter the TinyBus via the #msg method
|
@@ -56,10 +56,17 @@ class TinyBus
|
|
56
56
|
annotation_prefix: ANNOTATION_PREFIX_DEFAULT)
|
57
57
|
@subs = {}
|
58
58
|
@translator = translator
|
59
|
+
|
60
|
+
@dead_key = "#{annotation_prefix}dead"
|
61
|
+
@topic_key = "#{annotation_prefix}topic"
|
62
|
+
@time_key = "#{annotation_prefix}time"
|
63
|
+
@msg_uuid_key = "#{annotation_prefix}msg_uuid"
|
64
|
+
@trace_key = "#{annotation_prefix}trace"
|
65
|
+
|
59
66
|
@annotator = TinyPipe.new([
|
60
|
-
->(m){ m[
|
61
|
-
->(m){ m[
|
62
|
-
->(m){ m[
|
67
|
+
->(m){ m[@time_key] = (Time.now.to_f * 1000).to_i; m },
|
68
|
+
->(m){ m[@msg_uuid_key] = SecureRandom.uuid; m },
|
69
|
+
->(m){ m[@trace_key] ||= SecureRandom.uuid; m }
|
63
70
|
])
|
64
71
|
|
65
72
|
@stats = { '.dead' => 0 }
|
@@ -76,14 +83,14 @@ class TinyBus
|
|
76
83
|
@subs[topic] << subber
|
77
84
|
@stats[topic] ||= 0
|
78
85
|
|
79
|
-
msg({
|
86
|
+
msg({ @topic_key => 'sub', 'to_topic' => topic, 'subber' => subber.to_s })
|
80
87
|
end
|
81
88
|
|
82
89
|
# removes a subscriber from a topic
|
83
90
|
def unsub(topic, subber)
|
84
91
|
@subs[topic]&.delete(subber)
|
85
92
|
|
86
|
-
msg({
|
93
|
+
msg({ @topic_key => 'unsub', 'from_topic' => topic, 'subber' => subber.to_s })
|
87
94
|
end
|
88
95
|
|
89
96
|
# takes an incoming message and distributes it to subscribers
|
@@ -101,11 +108,11 @@ class TinyBus
|
|
101
108
|
msg = @annotator.pipe(msg)
|
102
109
|
msg = @translator&.pipe(msg) || msg
|
103
110
|
|
104
|
-
topic = msg[
|
111
|
+
topic = msg[@topic_key]
|
105
112
|
|
106
113
|
subbers = @subs[topic]
|
107
114
|
|
108
|
-
if subbers
|
115
|
+
if (subbers&.length || 0) > 0
|
109
116
|
@stats[topic] += 1
|
110
117
|
subbers.each{|s| s.msg(msg) }
|
111
118
|
@log.sent msg
|
@@ -113,7 +120,7 @@ class TinyBus
|
|
113
120
|
if @raise_on_dead
|
114
121
|
raise TinyBus::DeadMsgError.new("Could not deliver message to topic `#{topic}'")
|
115
122
|
else
|
116
|
-
@stats[
|
123
|
+
@stats[@dead_key] += 1
|
117
124
|
@dead.dead msg
|
118
125
|
end
|
119
126
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tiny_bus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Lunt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-12-
|
11
|
+
date: 2022-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tiny_log
|