message_channel 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +73 -0
- data/README.adoc +11 -0
- data/README.ja.adoc +12 -2
- data/Rakefile +1 -1
- data/lib/message_channel/base.rb +0 -2
- data/lib/message_channel/druby.rb +6 -6
- data/lib/message_channel/mongodb.rb +12 -10
- data/lib/message_channel/mqtt.rb +6 -5
- data/lib/message_channel/observer.rb +3 -3
- data/lib/message_channel/redis.rb +8 -9
- data/lib/message_channel/version.rb +1 -1
- data/message_channel.gemspec +4 -4
- metadata +19 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e76774a75506f2c670888b319bf69ee3abf09fa5ed509e56549d8bccda8ea26
|
4
|
+
data.tar.gz: b1bbe6889b83970a86a7405d7ce3ee6a1e95438445fa1bad7539c0bcb15162ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f793f863eccdde06bed75405f2268159aeaa286bd4d612fc82e656dfacb4b23917030978ce153613499dcc0f17760246b7a6d916b50b749243f8b274213dee03
|
7
|
+
data.tar.gz: fadae6f9289d7307cf939f0818db11008f1aa4270dff733d7639aa12e5703fe0be7f41030c988faa561bb9c10f824cbd923a91bc27a84b5e1edb65d8c3b83aec
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
|
2
|
+
AllCops:
|
3
|
+
Exclude:
|
4
|
+
- '.*'
|
5
|
+
- '*'
|
6
|
+
- '*.gemspec'
|
7
|
+
- 'Gemfile*'
|
8
|
+
- 'bin/**'
|
9
|
+
- 'exe/**'
|
10
|
+
- 'config/**/*'
|
11
|
+
- 'spec/**/*'
|
12
|
+
- 'tmp/**/*'
|
13
|
+
- 'vendor/**/*'
|
14
|
+
TargetRubyVersion: 2.7
|
15
|
+
|
16
|
+
Layout/ExtraSpacing:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Layout/SpaceAroundOperators:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Layout/SpaceBeforeFirstArg:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Layout/SpaceInsideParens:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Layout/SpaceInsideArrayLiteralBrackets:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Layout/SpaceInsideRangeLiteral:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Layout/SpaceInsideReferenceBrackets:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Layout/SpaceInsideStringInterpolation:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Lint/AmbiguousBlockAssociation:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
Lint/EmptyWhen:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
Lint/ReturnInVoidContext:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
Lint/UselessAssignment:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
Metrics/BlockLength:
|
53
|
+
Enabled: false
|
54
|
+
|
55
|
+
Metrics/LineLength:
|
56
|
+
Enabled: false
|
57
|
+
Max: 120
|
58
|
+
|
59
|
+
Metrics/MethodLength:
|
60
|
+
Enabled: false
|
61
|
+
|
62
|
+
Style/Documentation:
|
63
|
+
Enabled: true
|
64
|
+
|
65
|
+
Style/FrozenStringLiteralComment:
|
66
|
+
Enabled: false
|
67
|
+
|
68
|
+
Style/NumericPredicate:
|
69
|
+
Enabled: false
|
70
|
+
|
71
|
+
Style/StringLiterals:
|
72
|
+
Enabled: false
|
73
|
+
|
data/README.adoc
CHANGED
@@ -2,6 +2,15 @@
|
|
2
2
|
|
3
3
|
Yet another observer pattern library via Observable, DRb, MQTT, Redis and Mongo.
|
4
4
|
|
5
|
+
== Features
|
6
|
+
|
7
|
+
* Thread based observer pattern library.
|
8
|
+
* Implemented as a wrapper for Obserbable, DRb, MQTT, Redis and Mongo.
|
9
|
+
* Observer can communicate without using sockets.
|
10
|
+
* DRb can communicate between processes without using an external server.
|
11
|
+
* MQTT, Redis, and Mongo can create apps that can communicate in other languages.
|
12
|
+
* Distribute topic as a character string and data as a JSON-encoded character string.
|
13
|
+
|
5
14
|
== Installation
|
6
15
|
|
7
16
|
Add this line to your application's Gemfile:
|
@@ -172,3 +181,5 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/arimay
|
|
172
181
|
== License
|
173
182
|
|
174
183
|
The gem is available as open source under the terms of the http://opensource.org/licenses/MIT[MIT License].
|
184
|
+
|
185
|
+
Copyright (c) ARIMA Yasuhiro <arima.yasuhiro@gmail.com>
|
data/README.ja.adoc
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
= MessageChannel
|
2
2
|
|
3
|
-
オブザーバパターンライブラリのひとつ.
|
4
|
-
|
3
|
+
オブザーバパターンライブラリのひとつ. Observable, DRb, MQTT, Redis, Mongo を用いる.
|
4
|
+
|
5
|
+
== 特徴
|
6
|
+
|
7
|
+
* スレッドベースのオブザーバパターンライブラリ.
|
8
|
+
* Obserbable, DRb, MQTT, Redis および Mongo のラッパーとして実装.
|
9
|
+
* Observer はソケットを使わずに通信できる.
|
10
|
+
* DRb は外部サーバを使わずにプロセス間通信できる.
|
11
|
+
* MQTT, Redis, Mongo は通信できるアプリを他言語でも作成できる.
|
12
|
+
* トピックは文字列として、データは JSON 化した文字列として配信する.
|
5
13
|
|
6
14
|
== 導入
|
7
15
|
|
@@ -173,3 +181,5 @@ MessageChannel::Mongodb#unlisten( *patterns )
|
|
173
181
|
== ライセンス
|
174
182
|
|
175
183
|
この Gem は、 http://opensource.org/licenses/MIT[MITライセンス] の条件に基づいてオープンソースとして入手できる.
|
184
|
+
|
185
|
+
Copyright (c) ARIMA Yasuhiro <arima.yasuhiro@gmail.com>
|
data/Rakefile
CHANGED
@@ -8,7 +8,7 @@ task :default => :spec
|
|
8
8
|
|
9
9
|
class Bundler::GemHelper
|
10
10
|
|
11
|
-
def git_archive( dir = "
|
11
|
+
def git_archive( dir = "../zip" )
|
12
12
|
FileUtils.mkdir_p dir
|
13
13
|
dest_path = File.join(dir, "#{name}-#{version}.zip")
|
14
14
|
cmnd = "git archive --format zip --prefix=#{name}/ HEAD > #{dest_path}"
|
data/lib/message_channel/base.rb
CHANGED
@@ -49,7 +49,7 @@ module MessageChannel
|
|
49
49
|
|
50
50
|
def publish( topic, message )
|
51
51
|
@mutex.synchronize do
|
52
|
-
@patterns.each do |
|
52
|
+
@patterns.each do |_queue_id, items|
|
53
53
|
pattern, queue = *items
|
54
54
|
if File.fnmatch( pattern, topic, File::FNM_PATHNAME )
|
55
55
|
queue.push( [topic, message] )
|
@@ -94,7 +94,7 @@ module MessageChannel
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def unlisten( pattern )
|
97
|
-
if
|
97
|
+
if ( queue_id = @queue_ids[pattern] )
|
98
98
|
@drb.unsubscribe( queue_id )
|
99
99
|
@queue_ids.delete( pattern ) rescue nil
|
100
100
|
end
|
@@ -118,10 +118,10 @@ module MessageChannel
|
|
118
118
|
queue = Queue.new
|
119
119
|
threads = {}
|
120
120
|
patterns.each do |pattern|
|
121
|
-
threads[pattern] = Thread.start(pattern) do |
|
121
|
+
threads[pattern] = Thread.start( pattern ) do |pttrn|
|
122
122
|
agent = Agent.new
|
123
123
|
begin
|
124
|
-
topic, message = * agent.listen_once(
|
124
|
+
topic, message = * agent.listen_once( pttrn )
|
125
125
|
items = JSON.parse( message, symbolize_names: true )
|
126
126
|
queue.push( [topic, items] )
|
127
127
|
rescue => error
|
@@ -142,9 +142,9 @@ module MessageChannel
|
|
142
142
|
|
143
143
|
def listen_each( *patterns, &block )
|
144
144
|
patterns.each do |pattern|
|
145
|
-
@threads[pattern] = Thread.start(pattern) do |
|
145
|
+
@threads[pattern] = Thread.start( pattern ) do |pttrn|
|
146
146
|
begin
|
147
|
-
@agent.listen_each(
|
147
|
+
@agent.listen_each( pttrn ) do |topic, message|
|
148
148
|
items = JSON.parse( message, symbolize_names: true )
|
149
149
|
block.call( topic, items )
|
150
150
|
end
|
@@ -44,8 +44,8 @@ module MessageChannel
|
|
44
44
|
|
45
45
|
def get_event_tail( event_queue )
|
46
46
|
filter = {}
|
47
|
-
if
|
48
|
-
if
|
47
|
+
if ( enum = event_queue.find( {}, { sort: { "$natural" => -1 } } ).to_enum )
|
48
|
+
if ( doc = enum.next rescue nil )
|
49
49
|
filter = { "_id"=>{ "$gt"=>doc["_id"] } }
|
50
50
|
end
|
51
51
|
end
|
@@ -56,20 +56,21 @@ module MessageChannel
|
|
56
56
|
queue = Queue.new
|
57
57
|
threads = {}
|
58
58
|
patterns.each do |pattern|
|
59
|
-
threads[pattern] = ::Thread.start(pattern) do |
|
59
|
+
threads[pattern] = ::Thread.start( pattern ) do |pttrn|
|
60
60
|
event_queue = get_event_queue
|
61
61
|
event_tail = get_event_tail( event_queue )
|
62
62
|
begin
|
63
|
-
while
|
63
|
+
while ( doc = event_tail.next )
|
64
64
|
items = JSON.parse( doc.to_json, symbolize_names: true )
|
65
65
|
topic = items[:topic]
|
66
|
-
if File.fnmatch(
|
66
|
+
if File.fnmatch( pttrn, topic, File::FNM_PATHNAME )
|
67
67
|
items.delete( :_id )
|
68
68
|
items.delete( :topic )
|
69
69
|
queue.push [topic, items]
|
70
70
|
end
|
71
71
|
end
|
72
|
-
|
72
|
+
rescue => e
|
73
|
+
nil
|
73
74
|
end
|
74
75
|
end
|
75
76
|
end
|
@@ -84,20 +85,21 @@ module MessageChannel
|
|
84
85
|
|
85
86
|
def listen_each( *patterns, &block )
|
86
87
|
patterns.each do |pattern|
|
87
|
-
@threads[pattern] = ::Thread.start(pattern) do |
|
88
|
+
@threads[pattern] = ::Thread.start( pattern ) do |pttrn|
|
88
89
|
begin
|
89
90
|
event_queue = get_event_queue
|
90
91
|
event_tail = get_event_tail( event_queue )
|
91
|
-
while
|
92
|
+
while ( doc = event_tail.next )
|
92
93
|
items = JSON.parse( doc.to_json, symbolize_names: true )
|
93
94
|
topic = items[:topic]
|
94
|
-
if File.fnmatch(
|
95
|
+
if File.fnmatch( pttrn, topic, File::FNM_PATHNAME )
|
95
96
|
items.delete( :_id )
|
96
97
|
items.delete( :topic )
|
97
98
|
block.call( topic, items )
|
98
99
|
end
|
99
100
|
end
|
100
|
-
|
101
|
+
rescue => e
|
102
|
+
nil
|
101
103
|
end
|
102
104
|
end
|
103
105
|
end
|
data/lib/message_channel/mqtt.rb
CHANGED
@@ -15,15 +15,16 @@ module MessageChannel
|
|
15
15
|
queue = Queue.new
|
16
16
|
threads = {}
|
17
17
|
patterns.each do |pattern|
|
18
|
-
threads[pattern] = ::Thread.start(pattern) do |
|
18
|
+
threads[pattern] = ::Thread.start( pattern ) do |pttrn|
|
19
19
|
mqtt = MQTT::Client.connect( @host, @port )
|
20
20
|
begin
|
21
|
-
mqtt.get(
|
21
|
+
mqtt.get( pttrn ) do |topic, message|
|
22
22
|
items = JSON.parse( message, symbolize_names: true )
|
23
23
|
mqtt.disconnect rescue nil
|
24
24
|
queue.push [topic, items]
|
25
25
|
end
|
26
|
-
|
26
|
+
rescue => e
|
27
|
+
nil
|
27
28
|
end
|
28
29
|
end
|
29
30
|
end
|
@@ -38,10 +39,10 @@ module MessageChannel
|
|
38
39
|
|
39
40
|
def listen_each( *patterns, &block )
|
40
41
|
patterns.each do |pattern|
|
41
|
-
@threads[pattern] = ::Thread.start(pattern) do |
|
42
|
+
@threads[pattern] = ::Thread.start( pattern ) do |pttrn|
|
42
43
|
mqtt = MQTT::Client.connect( @host, @port )
|
43
44
|
begin
|
44
|
-
mqtt.get(
|
45
|
+
mqtt.get( pttrn ) do |topic, message|
|
45
46
|
items = JSON.parse( message, symbolize_names: true )
|
46
47
|
block.call( topic, items )
|
47
48
|
end
|
@@ -14,7 +14,7 @@ module MessageChannel
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def initialize( **
|
17
|
+
def initialize( **_options )
|
18
18
|
@asyncs = {}
|
19
19
|
@awaits = {}
|
20
20
|
@queues = {}
|
@@ -26,7 +26,7 @@ module MessageChannel
|
|
26
26
|
items = JSON.parse( message, symbolize_names: true )
|
27
27
|
@asyncs.keys.each do |pattern|
|
28
28
|
if File.fnmatch( pattern, topic, File::FNM_PATHNAME )
|
29
|
-
if
|
29
|
+
if ( action = @asyncs[pattern] )
|
30
30
|
action.call( topic, items )
|
31
31
|
end
|
32
32
|
end
|
@@ -66,7 +66,7 @@ module MessageChannel
|
|
66
66
|
|
67
67
|
def unlisten( **patterns )
|
68
68
|
patterns.each do |pattern|
|
69
|
-
if
|
69
|
+
if ( action = @asyncs[pattern] )
|
70
70
|
@asyncs.delete( pattern )
|
71
71
|
end
|
72
72
|
end
|
@@ -16,20 +16,19 @@ module MessageChannel
|
|
16
16
|
queue = Queue.new
|
17
17
|
threads = {}
|
18
18
|
patterns.each do |pattern|
|
19
|
-
threads[pattern] = ::Thread.start(pattern) do |
|
19
|
+
threads[pattern] = ::Thread.start( pattern ) do |pttrn|
|
20
20
|
redis = ::Redis.new( host: @host, port: @port, db: @db )
|
21
21
|
begin
|
22
|
-
redis.psubscribe(
|
23
|
-
on.pmessage do |
|
22
|
+
redis.psubscribe( pttrn ) do |on|
|
23
|
+
on.pmessage do |ptn, channel, message|
|
24
24
|
items = JSON.parse( message, symbolize_names: true )
|
25
|
-
redis.punsubscribe(
|
25
|
+
redis.punsubscribe( ptn ) rescue nil
|
26
26
|
queue.push [channel, items]
|
27
27
|
end
|
28
28
|
end
|
29
29
|
rescue ::Redis::BaseConnectionError => error
|
30
30
|
sleep 1
|
31
31
|
retry
|
32
|
-
ensure
|
33
32
|
end
|
34
33
|
end
|
35
34
|
end
|
@@ -44,11 +43,11 @@ module MessageChannel
|
|
44
43
|
|
45
44
|
def listen_each( *patterns, &block )
|
46
45
|
patterns.each do |pattern|
|
47
|
-
@threads[pattern] = ::Thread.start(pattern) do |
|
46
|
+
@threads[pattern] = ::Thread.start( pattern ) do |pttrn|
|
48
47
|
redis = ::Redis.new( host: @host, port: @port, db: @db )
|
49
48
|
begin
|
50
|
-
redis.psubscribe(
|
51
|
-
on.pmessage do |
|
49
|
+
redis.psubscribe( pttrn ) do |on|
|
50
|
+
on.pmessage do |_ptn, channel, message|
|
52
51
|
items = JSON.parse( message, symbolize_names: true )
|
53
52
|
block.call( channel, items )
|
54
53
|
end
|
@@ -57,7 +56,7 @@ module MessageChannel
|
|
57
56
|
sleep 1
|
58
57
|
retry
|
59
58
|
ensure
|
60
|
-
redis.punsubscribe(
|
59
|
+
redis.punsubscribe( pttrn ) rescue nil
|
61
60
|
end
|
62
61
|
end
|
63
62
|
end
|
data/message_channel.gemspec
CHANGED
@@ -7,9 +7,9 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.email = ["arima.yasuhiro@gmail.com"]
|
8
8
|
|
9
9
|
spec.summary = %q{ Wrapper library for publish/subscribe pattern. }
|
10
|
-
spec.description = %q{ Yet another observer pattern wrapper library via Observable, DRb, MQTT, Redis
|
10
|
+
spec.description = %q{ Yet another observer pattern wrapper library via Observable, DRb, MQTT, Redis or Mongo. }
|
11
11
|
spec.homepage = "https://github.com/arimay/message_channel"
|
12
|
-
spec.
|
12
|
+
spec.license = "MIT"
|
13
13
|
|
14
14
|
# Specify which files should be added to the gem when it is released.
|
15
15
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -25,6 +25,6 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency "msgpack"
|
26
26
|
spec.add_development_dependency "mongo"
|
27
27
|
|
28
|
-
spec.add_development_dependency "rake"
|
29
|
-
spec.add_development_dependency "rspec"
|
28
|
+
spec.add_development_dependency "rake"
|
29
|
+
spec.add_development_dependency "rspec"
|
30
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: message_channel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- arimay
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mqtt
|
@@ -70,32 +70,32 @@ dependencies:
|
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '0'
|
97
97
|
description: " Yet another observer pattern wrapper library via Observable, DRb, MQTT,
|
98
|
-
Redis
|
98
|
+
Redis or Mongo. "
|
99
99
|
email:
|
100
100
|
- arima.yasuhiro@gmail.com
|
101
101
|
executables: []
|
@@ -104,6 +104,7 @@ extra_rdoc_files: []
|
|
104
104
|
files:
|
105
105
|
- ".gitignore"
|
106
106
|
- ".rspec"
|
107
|
+
- ".rubocop.yml"
|
107
108
|
- ".travis.yml"
|
108
109
|
- Gemfile
|
109
110
|
- README.adoc
|
@@ -126,9 +127,10 @@ files:
|
|
126
127
|
- sample/sample_2.rb
|
127
128
|
- sample/sample_3.rb
|
128
129
|
homepage: https://github.com/arimay/message_channel
|
129
|
-
licenses:
|
130
|
+
licenses:
|
131
|
+
- MIT
|
130
132
|
metadata: {}
|
131
|
-
post_install_message:
|
133
|
+
post_install_message:
|
132
134
|
rdoc_options: []
|
133
135
|
require_paths:
|
134
136
|
- lib
|
@@ -136,15 +138,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
136
138
|
requirements:
|
137
139
|
- - ">="
|
138
140
|
- !ruby/object:Gem::Version
|
139
|
-
version:
|
141
|
+
version: '0'
|
140
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
143
|
requirements:
|
142
144
|
- - ">="
|
143
145
|
- !ruby/object:Gem::Version
|
144
146
|
version: '0'
|
145
147
|
requirements: []
|
146
|
-
rubygems_version: 3.
|
147
|
-
signing_key:
|
148
|
+
rubygems_version: 3.2.3
|
149
|
+
signing_key:
|
148
150
|
specification_version: 4
|
149
151
|
summary: Wrapper library for publish/subscribe pattern.
|
150
152
|
test_files: []
|