tiny_bus 3.1.1 → 3.3.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 +18 -5
- 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: b6166f18cf5222d5886b6276f55e5e6eba9f74050f69665a93b1f641a0ae9177
|
4
|
+
data.tar.gz: 96b2ebda14a8820f268d19c1f7e517937fae4c424faf8cb31bcf20a6b87110e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b95b706827023d4cbd94030a3f5a382d46543422e6ad47f9bfe2196972c0c106b22082a5654b096de708ccdba8d7d48be949c11b59a1a8ec89162eeec2d6e471
|
7
|
+
data.tar.gz: b7be435794e5fc4aca6f4baa0ab3b7d35ceaebdd573fe1e60bb7ff5757370917a96c3b4b0ea476796ba2f3e46326e2b524e06d64705f890f4f533c761253c5f4
|
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
|
|
@@ -64,8 +75,8 @@ class TinyBus
|
|
64
75
|
@trace_key = "#{annotation_prefix}trace"
|
65
76
|
|
66
77
|
@annotator = TinyPipe.new([
|
67
|
-
->(m){ m[@time_key]
|
68
|
-
->(m){ m[@msg_uuid_key]
|
78
|
+
->(m){ m[@time_key] ||= (Time.now.to_f * 1000).to_i; m },
|
79
|
+
->(m){ m[@msg_uuid_key] ||= SecureRandom.uuid; m },
|
69
80
|
->(m){ m[@trace_key] ||= SecureRandom.uuid; m }
|
70
81
|
])
|
71
82
|
|
@@ -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
|