rzmq-enhancement 0.0.19 → 0.0.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.semver +1 -1
- data/examples/push-pull-ipc.rb +30 -0
- data/examples/{push-pull.rb → push-pull-tcp.rb} +1 -1
- data/examples/rr-request-ipc.rb +14 -0
- data/examples/{rr-request.rb → rr-request-tcp.rb} +0 -0
- data/examples/rr-response-ipc.rb +13 -0
- data/examples/{rr-response.rb → rr-response-tcp.rb} +0 -0
- data/lib/rzmq-enhancement.rb +32 -12
- data/rzmq-enhancement.gemspec +9 -6
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02bb3bd003a801e1bccbf63499e12bedf681e37e
|
4
|
+
data.tar.gz: 884528721db8a307dfdc46e66b2b3b51b6929614
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b6088b307501f85b5fbf92ed5c07795990467638c9a5fd948df2658259c57476176386ee2fb266c01b80b1fbb375f3ab2c3dacaca3a230fb6d66e7f898fceb1
|
7
|
+
data.tar.gz: cd0cad6abdb9dbf2d12800b4c0964f0381faa20d92ec5099a0b6e6243fba7706bd8782158dff3b4a5479b20637eb1bdd74f5adf4e9237abba179a0ba402e0138
|
data/.semver
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rzmq-enhancement'
|
2
|
+
require 'pp'
|
3
|
+
require 'thread'
|
4
|
+
|
5
|
+
include ZeroMQ
|
6
|
+
|
7
|
+
thr = []
|
8
|
+
|
9
|
+
# push
|
10
|
+
thr << Thread.new {
|
11
|
+
(0..10).each do |i|
|
12
|
+
zeromq_push(:pushpull_example, ctx: :push) do |ctx|
|
13
|
+
unless i == 10
|
14
|
+
[i, 'mississippi']
|
15
|
+
else
|
16
|
+
:end_of_stream
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
}
|
21
|
+
|
22
|
+
# pull
|
23
|
+
thr << Thread.new {
|
24
|
+
zeromq_pull_server(:pushpull_example, ctx: :pull) do |payload|
|
25
|
+
pp payload
|
26
|
+
exit if payload == 'end_of_stream'
|
27
|
+
end
|
28
|
+
}
|
29
|
+
|
30
|
+
thr.each { |t| t.join }
|
File without changes
|
File without changes
|
data/lib/rzmq-enhancement.rb
CHANGED
@@ -5,34 +5,53 @@ require 'awesome_print'
|
|
5
5
|
require 'ostruct'
|
6
6
|
require 'json'
|
7
7
|
|
8
|
+
IPCDIR = '/tmp'
|
9
|
+
|
8
10
|
Thread.abort_on_exception = true
|
9
11
|
|
10
12
|
module ZeroMQ
|
11
13
|
|
12
|
-
def zeromq_push name,
|
13
|
-
|
14
|
+
def zeromq_push name,
|
15
|
+
endpoint = "ipc://#{IPCDIR}/#{name}.ipc",
|
16
|
+
ctx: :default,
|
17
|
+
&block
|
18
|
+
grand_pusher ZMQ::PUSH, name, endpoint, ctx: ctx, &block
|
14
19
|
end
|
15
20
|
|
16
21
|
# this does an endless loop as a "server"
|
17
|
-
def zeromq_pull_server name,
|
18
|
-
|
22
|
+
def zeromq_pull_server name,
|
23
|
+
endpoint = "ipc://#{IPCDIR}/#{name}.ipc",
|
24
|
+
ctx: :default,
|
25
|
+
&block
|
26
|
+
grand_server ZMQ::PULL, name, endpoint, ctx: ctx, bind: true, &block
|
19
27
|
end
|
20
28
|
|
21
29
|
# we make the request and return the response
|
22
|
-
def zeromq_request name,
|
23
|
-
|
30
|
+
def zeromq_request name,
|
31
|
+
endpoint = "ipc://#{IPCDIR}/#{name}.ipc",
|
32
|
+
**opts,
|
33
|
+
&block
|
34
|
+
h = grand_pusher ZMQ::REQ, name, endpoint, **opts, &block
|
24
35
|
end
|
25
36
|
|
26
|
-
def zeromq_response_server name,
|
27
|
-
|
37
|
+
def zeromq_response_server name,
|
38
|
+
endpoint = "ipc://#{IPCDIR}/#{name}.ipc",
|
39
|
+
ctx: :default,
|
40
|
+
&block
|
41
|
+
grand_server ZMQ::REP, name, endpoint, bind: true, respond: true, ctx: ctx, &block
|
28
42
|
end
|
29
43
|
|
30
44
|
private
|
45
|
+
def ctx_name name, opts
|
46
|
+
:"#{name}.#{opts[:ctx] || :default}"
|
47
|
+
end
|
48
|
+
|
31
49
|
# TODO: We don't handle the non-block req case at all. Do we want to?
|
32
50
|
def grand_pusher type, name, endpoint, **opts, &block
|
33
51
|
init_sys
|
34
|
-
|
35
|
-
|
52
|
+
ctxname = ctx_name(name,opts)
|
53
|
+
h = if @ctxh[ctxname].nil?
|
54
|
+
h = (@ctxh[ctxname] ||= OpenStruct.new)
|
36
55
|
h.ctx = ZMQ::Context.create(1)
|
37
56
|
h.push_sock = h.ctx.socket(type)
|
38
57
|
error_check(h.push_sock.setsockopt(ZMQ::LINGER, 0))
|
@@ -40,7 +59,7 @@ module ZeroMQ
|
|
40
59
|
error_check(rc)
|
41
60
|
h
|
42
61
|
else
|
43
|
-
@ctxh[
|
62
|
+
@ctxh[ctxname]
|
44
63
|
end
|
45
64
|
|
46
65
|
if block_given?
|
@@ -63,7 +82,8 @@ module ZeroMQ
|
|
63
82
|
|
64
83
|
def grand_server type, name, endpoint, **opts, &block
|
65
84
|
init_sys
|
66
|
-
|
85
|
+
ctxname = ctx_name(name,opts)
|
86
|
+
h = (@ctxh[ctxname] ||= OpenStruct.new)
|
67
87
|
h.ctx = ZMQ::Context.create(1)
|
68
88
|
|
69
89
|
h.server_sock = h.ctx.socket(type)
|
data/rzmq-enhancement.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: rzmq-enhancement 0.0.
|
5
|
+
# stub: rzmq-enhancement 0.0.26 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "rzmq-enhancement".freeze
|
9
|
-
s.version = "0.0.
|
9
|
+
s.version = "0.0.26"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["Fred Mitchell".freeze, "Sensorberg GmbH".freeze]
|
14
|
-
s.date = "2017-06-
|
14
|
+
s.date = "2017-06-09"
|
15
15
|
s.description = "\n The ffi-rzmq wraps ZeroMQ nicely, but not in a Ruby-friendly manner.\n here, we take that one step further to present a mor Ruby-Friendy\n interface.".freeze
|
16
16
|
s.email = "frederick.mitchell@sensorberg.com".freeze
|
17
17
|
s.executables = ["rzmq".freeze]
|
@@ -29,9 +29,12 @@ Gem::Specification.new do |s|
|
|
29
29
|
"README.org",
|
30
30
|
"Rakefile",
|
31
31
|
"bin/rzmq",
|
32
|
-
"examples/push-pull.rb",
|
33
|
-
"examples/
|
34
|
-
"examples/rr-
|
32
|
+
"examples/push-pull-ipc.rb",
|
33
|
+
"examples/push-pull-tcp.rb",
|
34
|
+
"examples/rr-request-ipc.rb",
|
35
|
+
"examples/rr-request-tcp.rb",
|
36
|
+
"examples/rr-response-ipc.rb",
|
37
|
+
"examples/rr-response-tcp.rb",
|
35
38
|
"lib/rzmq-enhancement.rb",
|
36
39
|
"rzmq-enhancement.gemspec",
|
37
40
|
"spec/rzmq-enhancement_spec.rb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rzmq-enhancement
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.26
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fred Mitchell
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-06-
|
12
|
+
date: 2017-06-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: semver2
|
@@ -243,9 +243,12 @@ files:
|
|
243
243
|
- README.org
|
244
244
|
- Rakefile
|
245
245
|
- bin/rzmq
|
246
|
-
- examples/push-pull.rb
|
247
|
-
- examples/
|
248
|
-
- examples/rr-
|
246
|
+
- examples/push-pull-ipc.rb
|
247
|
+
- examples/push-pull-tcp.rb
|
248
|
+
- examples/rr-request-ipc.rb
|
249
|
+
- examples/rr-request-tcp.rb
|
250
|
+
- examples/rr-response-ipc.rb
|
251
|
+
- examples/rr-response-tcp.rb
|
249
252
|
- lib/rzmq-enhancement.rb
|
250
253
|
- rzmq-enhancement.gemspec
|
251
254
|
- spec/rzmq-enhancement_spec.rb
|