tiny_bus 3.1.1 → 3.2.0
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 -3
- 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: e0b4ee66f65bb60557ba29b72f0ade0e840f0db352ac2f1bca0cab5385b97b19
|
4
|
+
data.tar.gz: '089bfc105f34f3538844e5756e3623f8db4f835c58501140cc6d6a02521c17dc'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58a576c5b7bc7445b263e93b23ba1ba65e6536dfdd38dfe150251401dfc9490776ca6b751ef27c9ed71ce2bea0901d5292b009bed217c7c0a50c3c852f88e748
|
7
|
+
data.tar.gz: 45a52d67eecda3efa9d8e72267413fd0d5adaab5b5f3168278e7938e0edd88f9f29b6e18fb5a98d7058c0a456c3898b83a92549cf7df7a012313bc27b1f8b736
|
data/lib/tiny_bus.rb
CHANGED
@@ -28,6 +28,10 @@ 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
|
31
35
|
|
32
36
|
# log:
|
33
37
|
# if specified, it should be a TinyLog instance
|
@@ -52,8 +56,15 @@ class TinyBus
|
|
52
56
|
# default: '.'
|
53
57
|
# if specified, the annotated message attributes ('.time', '.msg_uuid', and
|
54
58
|
# '.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
|
55
65
|
def initialize(log: nil, dead: nil, translator: nil, raise_on_dead: false,
|
56
|
-
annotation_prefix: ANNOTATION_PREFIX_DEFAULT
|
66
|
+
annotation_prefix: ANNOTATION_PREFIX_DEFAULT,
|
67
|
+
logging_overrides: LOGGING_LEVELS)
|
57
68
|
@subs = {}
|
58
69
|
@translator = translator
|
59
70
|
|
@@ -73,6 +84,8 @@ class TinyBus
|
|
73
84
|
@log = log || TinyLog.new($stdout)
|
74
85
|
@dead = dead || TinyLog.new($stderr)
|
75
86
|
@raise_on_dead = raise_on_dead
|
87
|
+
@sent_level = logging_overrides['sent'] || LOGGING_LEVELS['sent']
|
88
|
+
@dead_level = logging_overrides['dead'] || LOGGING_LEVELS['dead']
|
76
89
|
end
|
77
90
|
|
78
91
|
# adds a subscriber to a topic
|
@@ -115,13 +128,13 @@ class TinyBus
|
|
115
128
|
if (subbers&.length || 0) > 0
|
116
129
|
@stats[topic] += 1
|
117
130
|
subbers.each{|s| s.msg(msg) }
|
118
|
-
@log.
|
131
|
+
@log.send(@sent_level, msg)
|
119
132
|
else
|
120
133
|
if @raise_on_dead
|
121
134
|
raise TinyBus::DeadMsgError.new("Could not deliver message to topic `#{topic}'")
|
122
135
|
else
|
123
136
|
@stats[@dead_key] += 1
|
124
|
-
@dead.
|
137
|
+
@dead.send(@dead_level, msg)
|
125
138
|
end
|
126
139
|
end
|
127
140
|
end
|