tiny_bus 3.3.0 → 3.4.0
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/lib/tiny_bus.rb +6 -18
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3331fb500d2860aabc8902f7c9ca22afe2c9edf32225577ac22b41fe496e440
|
4
|
+
data.tar.gz: 637184ebeb5d80a614379af73b96b998d3e655844a4ac77f2427d407cc552c09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c49fe21fd0793a80914bc70d9c32c3fcc8e59fad61deae99f65a46ac122e6372e8eea2c2e0bea01afbb1e9cecb35929e6c3fee7b2d7beb8a7e1a0fbf12dfb1b
|
7
|
+
data.tar.gz: 732f63a9a8927a30a339a0214aede09ab23e532a7a1f379fd547f0f33cfcc637448433d785ad2c197572370f269fd71de65104bae84f6570b21dd380f4441492
|
data/lib/tiny_bus.rb
CHANGED
@@ -28,10 +28,6 @@ require 'tiny_pipe'
|
|
28
28
|
# TinyBus.new(raise_on_dead: true) # strict mode for undeliverable messages, defaults to false
|
29
29
|
class TinyBus
|
30
30
|
ANNOTATION_PREFIX_DEFAULT = '.'
|
31
|
-
LOGGING_LEVELS = {
|
32
|
-
'sent' => 'SENT',
|
33
|
-
'dead' => 'DEAD'
|
34
|
-
}.freeze
|
35
31
|
|
36
32
|
# log:
|
37
33
|
# if specified, it should be a TinyLog instance
|
@@ -56,15 +52,8 @@ class TinyBus
|
|
56
52
|
# default: '.'
|
57
53
|
# if specified, the annotated message attributes ('.time', '.msg_uuid', and
|
58
54
|
# '.trace') will have the dot ('.') replaced with the specified prefix text
|
59
|
-
# logging_overrides:
|
60
|
-
# default: LOGGING_LEVELS
|
61
|
-
# allows you to specify a Hash of overrides of the logging levels for
|
62
|
-
# 'SENT' and 'DEAD' message delivery; useful if the consuming application
|
63
|
-
# wants to use its own logging levels, or you just want the labels changed
|
64
|
-
# for some reason
|
65
55
|
def initialize(log: nil, dead: nil, translator: nil, raise_on_dead: false,
|
66
|
-
annotation_prefix: ANNOTATION_PREFIX_DEFAULT
|
67
|
-
logging_overrides: LOGGING_LEVELS)
|
56
|
+
annotation_prefix: ANNOTATION_PREFIX_DEFAULT)
|
68
57
|
@subs = {}
|
69
58
|
@translator = translator
|
70
59
|
|
@@ -84,8 +73,6 @@ class TinyBus
|
|
84
73
|
@log = log || TinyLog.new($stdout)
|
85
74
|
@dead = dead || TinyLog.new($stderr)
|
86
75
|
@raise_on_dead = raise_on_dead
|
87
|
-
@sent_level = logging_overrides['sent'] || LOGGING_LEVELS['sent']
|
88
|
-
@dead_level = logging_overrides['dead'] || LOGGING_LEVELS['dead']
|
89
76
|
end
|
90
77
|
|
91
78
|
# adds a subscriber to a topic
|
@@ -110,9 +97,10 @@ class TinyBus
|
|
110
97
|
#
|
111
98
|
# msg: the incoming message to be distributed
|
112
99
|
# lvl (optional): the logging level
|
100
|
+
# default: 'info'
|
113
101
|
#
|
114
|
-
# NOTE:
|
115
|
-
# unnecessary object allocations
|
102
|
+
# NOTE: this method modifies the incoming msg object in place in order to
|
103
|
+
# avoid unnecessary object allocations
|
116
104
|
#
|
117
105
|
# NOTE: keys that begin with dot (.), such as '.time' are reserved for
|
118
106
|
# TinyBus and show not be altered by outside code, otherwise undefined
|
@@ -128,13 +116,13 @@ class TinyBus
|
|
128
116
|
if (subbers&.length || 0) > 0
|
129
117
|
@stats[topic] += 1
|
130
118
|
subbers.each{|s| s.msg(msg) }
|
131
|
-
@log.send(
|
119
|
+
@log.send(lvl, "S #{msg}")
|
132
120
|
else
|
133
121
|
if @raise_on_dead
|
134
122
|
raise TinyBus::DeadMsgError.new("Could not deliver message to topic `#{topic}'")
|
135
123
|
else
|
136
124
|
@stats[@dead_key] += 1
|
137
|
-
@dead.send(
|
125
|
+
@dead.send(lvl, "D #{msg}")
|
138
126
|
end
|
139
127
|
end
|
140
128
|
end
|