mimi-messaging 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mimi/messaging/message.rb +34 -0
- data/lib/mimi/messaging/version.rb +1 -1
- data/lib/mimi/messaging.rb +8 -7
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54a536d257b3a394b605e80e1b24167e5912f785
|
4
|
+
data.tar.gz: 03374246a36903692068863563ec7a111cd18b8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0295bb31beb00e6370340e4db43bab2a145e9d463d514bcdf1eba944a171edb614133afc7384a9e1e3010b832c4ff4b547ae9a27e307efb19d4abe3acee0782d'
|
7
|
+
data.tar.gz: 5e3a7f512fc58d688551c9601c26b863872dfeafaf860554796f2493ba30234045c591520c453fa973cae529069516cc19653553cf369eca7f31bc7c5ac29395
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mimi
|
4
|
+
module Messaging
|
5
|
+
#
|
6
|
+
# A Message is a Hash and additional headers structure.
|
7
|
+
#
|
8
|
+
class Message < Hash
|
9
|
+
attr_reader :headers
|
10
|
+
|
11
|
+
# Creates a Message out of Hash or another Message.
|
12
|
+
#
|
13
|
+
# @param message_or_hash [Hash,Message]
|
14
|
+
# @param headers [Hash,nil] additional headers to attach to the message
|
15
|
+
#
|
16
|
+
def initialize(message_or_hash, headers = nil)
|
17
|
+
unless message_or_hash.is_a?(Hash) # or a Message
|
18
|
+
raise ArgumentError, "Message or Hash is expected as argument"
|
19
|
+
end
|
20
|
+
|
21
|
+
# copy attributes
|
22
|
+
message_or_hash.each { |k, v| self[k] = v.dup }
|
23
|
+
|
24
|
+
# copy headers
|
25
|
+
headers ||= {}
|
26
|
+
if message_or_hash.is_a?(Mimi::Messaging::Message)
|
27
|
+
@headers = message_or_hash.headers.merge(headers)
|
28
|
+
else
|
29
|
+
@headers = headers
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end # class Message
|
33
|
+
end # module Messaging
|
34
|
+
end # module Mimi
|
data/lib/mimi/messaging.rb
CHANGED
@@ -4,6 +4,7 @@ require "mimi/core"
|
|
4
4
|
require_relative "messaging/adapters"
|
5
5
|
require_relative "messaging/errors"
|
6
6
|
require_relative "messaging/json_serializer"
|
7
|
+
require_relative "messaging/message"
|
7
8
|
require_relative "messaging/version"
|
8
9
|
|
9
10
|
module Mimi
|
@@ -185,10 +186,10 @@ module Mimi
|
|
185
186
|
#
|
186
187
|
def self.command(target, message = {}, opts = {})
|
187
188
|
raise ArgumentError, "Invalid target argument" unless TARGET_REGEX.match(target)
|
188
|
-
raise ArgumentError, "Invalid message, Hash is expected" unless message.is_a?(Hash)
|
189
|
+
raise ArgumentError, "Invalid message, Hash or Message is expected" unless message.is_a?(Hash)
|
189
190
|
raise Error, "Failed to send command, adapter is not started" unless started?(:adapter)
|
190
191
|
|
191
|
-
adapter.command(target, message, opts)
|
192
|
+
adapter.command(target, Mimi::Messaging::Message.new(message), opts)
|
192
193
|
end
|
193
194
|
|
194
195
|
# Executes the query to the given target and returns response
|
@@ -196,17 +197,17 @@ module Mimi
|
|
196
197
|
# Raises Timeout::Error if the response from the target was not received in time.
|
197
198
|
#
|
198
199
|
# @param target [String] "<queue>/<method>"
|
199
|
-
# @param message [Hash]
|
200
|
+
# @param message [Hash,Mimi::Messaging::Message]
|
200
201
|
# @param opts [Hash] additional options, e.g. :timeout
|
201
202
|
#
|
202
203
|
# @return [Hash]
|
203
204
|
#
|
204
205
|
def self.query(target, message = {}, opts = {})
|
205
206
|
raise ArgumentError, "Invalid target argument" unless TARGET_REGEX.match(target)
|
206
|
-
raise ArgumentError, "Invalid message, Hash is expected" unless message.is_a?(Hash)
|
207
|
+
raise ArgumentError, "Invalid message, Hash or Message is expected" unless message.is_a?(Hash)
|
207
208
|
raise Error, "Failed to send query, adapter is not started" unless started?(:adapter)
|
208
209
|
|
209
|
-
adapter.query(target, message, opts)
|
210
|
+
adapter.query(target, Mimi::Messaging::Message.new(message), opts)
|
210
211
|
end
|
211
212
|
|
212
213
|
# Broadcasts the event with the given target
|
@@ -217,10 +218,10 @@ module Mimi
|
|
217
218
|
#
|
218
219
|
def self.event(target, message = {}, opts = {})
|
219
220
|
raise ArgumentError, "Invalid target argument" unless TARGET_REGEX.match(target)
|
220
|
-
raise ArgumentError, "Invalid message, Hash is expected" unless message.is_a?(Hash)
|
221
|
+
raise ArgumentError, "Invalid message, Hash or Message is expected" unless message.is_a?(Hash)
|
221
222
|
raise Error, "Failed to broadcast event, adapter is not started" unless started?(:adapter)
|
222
223
|
|
223
|
-
adapter.event(target, message, opts)
|
224
|
+
adapter.event(target, Mimi::Messaging::Message.new(message), opts)
|
224
225
|
end
|
225
226
|
|
226
227
|
# Registers the request (command/query) processor.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mimi-messaging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Kukushkin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mimi-core
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- lib/mimi/messaging/adapters/test.rb
|
123
123
|
- lib/mimi/messaging/errors.rb
|
124
124
|
- lib/mimi/messaging/json_serializer.rb
|
125
|
+
- lib/mimi/messaging/message.rb
|
125
126
|
- lib/mimi/messaging/version.rb
|
126
127
|
- mimi-messaging.gemspec
|
127
128
|
homepage: https://github.com/kukushkin/mimi-messaging
|