mimi-messaging 1.1.1 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/lib/mimi/messaging.rb +15 -6
- data/lib/mimi/messaging/adapters/base.rb +1 -1
- data/lib/mimi/messaging/adapters/memory.rb +1 -1
- data/lib/mimi/messaging/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26a8638d1cd6dc83e1dae3096d1e069dacf09b11
|
4
|
+
data.tar.gz: bd878a461feb3246b95030322e6a00f403131ae3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adc464f5691764a4ce6584aba1680629ce5cedeb0335d340f484bc32655bc422397e4e9d46ac7a02e932f5e03cccd57960f1a261cc3ad751542941496c51fb3b
|
7
|
+
data.tar.gz: 5218ebeac04c69fbdfe26c5a567090a44b0cc4dcaafc2dee44e9db90cb367a0aeec46071028a732324500ae4598eb4fecca8464f0854355b8fe7e3c51bd24311
|
data/README.md
CHANGED
@@ -57,7 +57,7 @@ there are several available adapters:
|
|
57
57
|
* [Kafka](https://github.com/kukushkin/mimi-messaging-kafka)
|
58
58
|
* RabbitMQ (TBD)
|
59
59
|
* NATS (TBD)
|
60
|
-
* Amazon SQS/SNS
|
60
|
+
* [Amazon SQS/SNS](https://github.com/kukushkin/mimi-messaging-sqs_sns)
|
61
61
|
* in-memory (single process)
|
62
62
|
|
63
63
|
## Designing apps
|
@@ -65,10 +65,11 @@ there are several available adapters:
|
|
65
65
|
|
66
66
|
There are only two hard problems in distributed systems:
|
67
67
|
|
68
|
+
```
|
68
69
|
2. Exactly-once delivery
|
69
70
|
1. Guaranteed order of messages
|
70
71
|
2. Exactly-once delivery
|
71
|
-
|
72
|
+
```
|
72
73
|
|
73
74
|
## License
|
74
75
|
|
data/lib/mimi/messaging.rb
CHANGED
@@ -14,14 +14,23 @@ module Mimi
|
|
14
14
|
# Usage: [TBD]
|
15
15
|
#
|
16
16
|
module Messaging
|
17
|
-
#
|
17
|
+
# Request target validation pattern:
|
18
18
|
# "[<name>.][...]<name>/<name>"
|
19
19
|
# Where <name> consists of valid identifier characters: A-Za-z0-9_
|
20
20
|
#
|
21
21
|
# Example:
|
22
22
|
# "shop.orders/list"
|
23
23
|
#
|
24
|
-
|
24
|
+
REQUEST_TARGET_REGEX = %r{^((\w+)\.)*(\w+)\/(\w+)$}.freeze
|
25
|
+
|
26
|
+
# Event target validation pattern:
|
27
|
+
# "[<name>.][...]<name>#<name>"
|
28
|
+
# Where <name> consists of valid identifier characters: A-Za-z0-9_
|
29
|
+
#
|
30
|
+
# Example:
|
31
|
+
# "shop.orders#created"
|
32
|
+
#
|
33
|
+
EVENT_TARGET_REGEX = %r{^((\w+)\.)*(\w+)\#(\w+)$}.freeze
|
25
34
|
|
26
35
|
# By default Mimi::Messaging logs at given level
|
27
36
|
DEFAULT_LOG_AT_LEVEL = :info
|
@@ -185,7 +194,7 @@ module Mimi
|
|
185
194
|
# @return nil
|
186
195
|
#
|
187
196
|
def self.command(target, message = {}, opts = {})
|
188
|
-
raise ArgumentError, "Invalid target argument" unless
|
197
|
+
raise ArgumentError, "Invalid target argument" unless REQUEST_TARGET_REGEX.match(target)
|
189
198
|
raise ArgumentError, "Invalid message, Hash or Message is expected" unless message.is_a?(Hash)
|
190
199
|
raise Error, "Failed to send command, adapter is not started" unless started?(:adapter)
|
191
200
|
|
@@ -206,7 +215,7 @@ module Mimi
|
|
206
215
|
# @return [Hash]
|
207
216
|
#
|
208
217
|
def self.query(target, message = {}, opts = {})
|
209
|
-
raise ArgumentError, "Invalid target argument" unless
|
218
|
+
raise ArgumentError, "Invalid target argument" unless REQUEST_TARGET_REGEX.match(target)
|
210
219
|
raise ArgumentError, "Invalid message, Hash or Message is expected" unless message.is_a?(Hash)
|
211
220
|
raise Error, "Failed to send query, adapter is not started" unless started?(:adapter)
|
212
221
|
|
@@ -215,12 +224,12 @@ module Mimi
|
|
215
224
|
|
216
225
|
# Broadcasts the event with the given target
|
217
226
|
#
|
218
|
-
# @param target [String] "<topic
|
227
|
+
# @param target [String] "<topic>#<event_type>", e.g. "customers#created"
|
219
228
|
# @param message [Hash,Mimi::Messaging::Message]
|
220
229
|
# @param opts [Hash] additional options
|
221
230
|
#
|
222
231
|
def self.event(target, message = {}, opts = {})
|
223
|
-
raise ArgumentError, "Invalid target argument" unless
|
232
|
+
raise ArgumentError, "Invalid target argument" unless EVENT_TARGET_REGEX.match(target)
|
224
233
|
raise ArgumentError, "Invalid message, Hash or Message is expected" unless message.is_a?(Hash)
|
225
234
|
raise Error, "Failed to broadcast event, adapter is not started" unless started?(:adapter)
|
226
235
|
|
@@ -88,7 +88,7 @@ module Mimi
|
|
88
88
|
|
89
89
|
# Broadcasts the event with the given target
|
90
90
|
#
|
91
|
-
# @param target [String] "<topic
|
91
|
+
# @param target [String] "<topic>#<event_type>", e.g. "customers#created"
|
92
92
|
# @param message [Mimi::Messaging::Message]
|
93
93
|
# @param opts [Hash] additional options
|
94
94
|
#
|
@@ -89,7 +89,7 @@ module Mimi
|
|
89
89
|
end
|
90
90
|
|
91
91
|
def dispatch_event(target, message_serialized, _opts = {})
|
92
|
-
topic_name, event_type = target.split("
|
92
|
+
topic_name, event_type = target.split("#")
|
93
93
|
processors = event_processors[topic_name] || []
|
94
94
|
processor_queues = event_processors_with_queue[topic_name] || {}
|
95
95
|
processor_queues.values.each do |same_queue_processors|
|