rmessage 0.1.0 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rmessage/message.rb +4 -3
- data/lib/rmessage/publisher.rb +3 -2
- data/lib/rmessage/subscriber.rb +9 -10
- 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: a49ac884778c35479a6f9bd22cdf223aac6d02ef586d61c41cd16b1278c4be97
|
4
|
+
data.tar.gz: d2d69bc681472e741c9eaec10dab3903c2014488030c8fae76d05908c14b4eb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c35501badb73bf98833fb58703167cae86ce0ceccee81e3e416b7f9a76e63f4173f19307e12bacd8c1e4e3eb173f39ce2b6965ab433c8cf97ec44b632d87c5a
|
7
|
+
data.tar.gz: 8dc719f163a85322f28b0cb10674113ab0993e1983429999c71d0f3057a017d47979719a781a9c4962bbe0faddd732376c107cdf42f1bd2e024cd6ba694a800c
|
data/lib/rmessage/message.rb
CHANGED
@@ -19,15 +19,15 @@ module RMessage
|
|
19
19
|
# * label [Symbol, String] the Message label
|
20
20
|
# * signature [Integer, String] the Message signature
|
21
21
|
# * payload [Hash, String] the Message data
|
22
|
-
|
23
|
-
def initialize(opts = {}, data = nil)
|
22
|
+
def initialize(opts = {})
|
24
23
|
@label = opts[:label] || :UNTITLED
|
25
24
|
@signature = opts[:signature] || Druuid.gen
|
26
|
-
@payload =
|
25
|
+
@payload = opts[:payload] || {}
|
27
26
|
end
|
28
27
|
|
29
28
|
# Read and parse data. Defaults to the Message#payload.
|
30
29
|
# @param data [Hash, String] the data.
|
30
|
+
# @return [RMessage::Message]
|
31
31
|
def read(data = @payload)
|
32
32
|
case data
|
33
33
|
when Hash
|
@@ -41,6 +41,7 @@ module RMessage
|
|
41
41
|
@payload ||= parsed['payload']
|
42
42
|
else raise TypeError, 'Invalid type for Message#payload'
|
43
43
|
end
|
44
|
+
self
|
44
45
|
end
|
45
46
|
|
46
47
|
# Build a JSON string using data in this message
|
data/lib/rmessage/publisher.rb
CHANGED
@@ -10,7 +10,8 @@ module RMessage::Publisher
|
|
10
10
|
# @param message [RMessage::Message] the message
|
11
11
|
# @param channel [String, Integer, Symbol] the channel
|
12
12
|
# @param connection_index [Integer] the index of the connection to Redis within the {RMessage::CONNECTION_POOL}
|
13
|
-
def publish(message, channel: @channel, connection_index: 0)
|
14
|
-
RMessage::CONNECTION_POOL[connection_index]
|
13
|
+
def publish(message, channel: @channel, connection: nil, connection_index: 0)
|
14
|
+
redis_connection = connection || RMessage::CONNECTION_POOL[connection_index]
|
15
|
+
redis_connection.publish(channel, message.build)
|
15
16
|
end
|
16
17
|
end
|
data/lib/rmessage/subscriber.rb
CHANGED
@@ -13,17 +13,18 @@ module RMessage::Subscriber
|
|
13
13
|
# Setup a subscription to a specific Redis channel
|
14
14
|
# @param channel [Symbol, String, Integer] the channel
|
15
15
|
# @param auto_parse [Boolean] should messages be parsed automatically?
|
16
|
+
# @param connection [Redis] optional argument to provide the redis connection.
|
16
17
|
# @param connection_index [Integer] the index of the redis connection in {RMessage::CONNECTION_POOL}
|
17
|
-
def setup_subscription(channel: @channel, auto_parse: false, connection_index: 0, &_)
|
18
|
-
RMessage::CONNECTION_POOL[connection_index]
|
18
|
+
def setup_subscription(channel: @channel, auto_parse: false, logger: nil, connection: nil, connection_index: 0, &_)
|
19
|
+
redis_connection = connection || RMessage::CONNECTION_POOL[connection_index]
|
20
|
+
redis_connection.subscribe(channel) do |event|
|
19
21
|
event.subscribe do
|
20
|
-
|
22
|
+
logger&.info("Subscribed to channel [channel: #{channel}]")
|
21
23
|
end
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
event.message { |_, message| yield(message) }
|
25
|
+
event.message do |_, message|
|
26
|
+
auto_parse ? yield(parse_message(message)) : yield(message)
|
27
|
+
logger&.info("Received Message: #{message}")
|
27
28
|
end
|
28
29
|
end
|
29
30
|
end
|
@@ -31,9 +32,7 @@ module RMessage::Subscriber
|
|
31
32
|
private
|
32
33
|
|
33
34
|
def parse_message(message_data)
|
34
|
-
|
35
|
-
msg.read
|
36
|
-
@events[msg.label].new(msg)
|
35
|
+
RMessage::Message.new(message_data).read
|
37
36
|
end
|
38
37
|
end
|
39
38
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rmessage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick W.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|