rzmq-enhancement 0.0.4 → 0.0.14

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8aa4451bc61e19437a3beca41f893075926a3f06
4
- data.tar.gz: f146bec0bbf0210e42623389bc9f195bbca7b313
3
+ metadata.gz: f6360f3b091688410725c27c5505f753e1e3e688
4
+ data.tar.gz: 18dd429996fac085eb8e1bd8ad868ed319be08d1
5
5
  SHA512:
6
- metadata.gz: e0f08bcf7afa5015bd320737cfd983b88cbbb7f5f11a5197480775c866ba20c593ab181a22625aaccdb12caaceade36a653a333dd56c339fb7f6f2395683d8ec
7
- data.tar.gz: deaf85707d0e88ea0c5366842a71810494790ea1f837c3a49790d94d15f701731af9d648c5cd035035a962a93acc1f35ba3ccbee8ccb9fc3e8ebddec9aa5f46b
6
+ metadata.gz: c6254b1dea7b4aed670415f08175b89b09ab6214ec8acbb0dcc794a95e238f989f6d45d27e6e4fb5576903934077c0765709b6d9e625f7fa6d3d216e9c679f14
7
+ data.tar.gz: d66e70b7b9e27ee39f79eb65155208f837658aee3a5f9b85109fc5a43e71d6bf091c5a1c20887ccbb4db29b0ecec0122fa4755a7db0b40bdc105e48afce1f582
data/.semver CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 0
4
- :patch: 4
4
+ :patch: 14
5
5
  :special: ''
data/Gemfile.lock CHANGED
@@ -32,7 +32,7 @@ GEM
32
32
  highline (1.7.8)
33
33
  interception (0.5)
34
34
  json (1.8.6)
35
- juwelier (2.4.5)
35
+ juwelier (2.4.6)
36
36
  builder
37
37
  bundler (>= 1.13)
38
38
  git (>= 1.2.5)
@@ -49,12 +49,12 @@ GEM
49
49
  semver2 (~> 3)
50
50
  method_source (0.8.2)
51
51
  mime-types (2.99.3)
52
- mini_portile2 (2.1.0)
52
+ mini_portile2 (2.2.0)
53
53
  multi_json (1.12.1)
54
54
  multi_xml (0.6.0)
55
55
  multipart-post (2.0.0)
56
- nokogiri (1.7.2)
57
- mini_portile2 (~> 2.1.0)
56
+ nokogiri (1.8.0)
57
+ mini_portile2 (~> 2.2.0)
58
58
  oauth2 (1.3.1)
59
59
  faraday (>= 0.8, < 0.12)
60
60
  jwt (~> 1.0)
data/README.org CHANGED
@@ -4,6 +4,7 @@
4
4
  - [[#preliminaries][Preliminaries]]
5
5
  - [[#install][Install]]
6
6
  - [[#usage][Usage]]
7
+ - [[#tips][Tips]]
7
8
  - [[#contributing-to-rzmq-enhancement][Contributing to rzmq-enhancement]]
8
9
  - [[#copyright][Copyright]]
9
10
 
@@ -54,6 +55,9 @@
54
55
  #+end_src
55
56
 
56
57
  ** Usage
58
+ Please see the [[./examples][Examples.]]
59
+
60
+ *** Tips
57
61
  Do not use "localhost". Use, instead, 127.0.0.1, example:
58
62
 
59
63
  #+begin_src ruby
@@ -67,7 +71,6 @@
67
71
  'ipc://anynameyoulike.ipc'
68
72
  #+end_src
69
73
 
70
-
71
74
  ** Contributing to rzmq-enhancement
72
75
 
73
76
  - Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
@@ -27,4 +27,4 @@ thr << Thread.new {
27
27
  end
28
28
  }
29
29
 
30
- thr.each {|t| t.join }
30
+ thr.each { |t| t.join }
@@ -0,0 +1,17 @@
1
+ require 'rzmq-enhancement'
2
+ require 'pp'
3
+ require 'thread'
4
+
5
+ include ZeroMQ
6
+ EP = 'ipc://reqresp.ipc'
7
+
8
+ # request
9
+
10
+ (0..10).each do |i|
11
+ zeromq_request( :request_example,
12
+ EP,
13
+ payload: [i, i*i] ) do |result|
14
+ print "result: "
15
+ pp result
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ require 'rzmq-enhancement'
2
+ require 'pp'
3
+ require 'thread'
4
+
5
+ include ZeroMQ
6
+ EP = 'ipc://reqresp.ipc'
7
+
8
+ # response
9
+
10
+ zeromq_response_server :response_example, EP do |payload|
11
+ print "respond to this: "
12
+ pp payload
13
+ i, j = payload
14
+ i + j
15
+ end
@@ -8,14 +8,33 @@ require 'json'
8
8
  Thread.abort_on_exception = true
9
9
 
10
10
  module ZeroMQ
11
-
12
11
 
13
12
  def zeromq_push name, endpoint = "ipc://#{name}.ipc", &block
13
+ grand_pusher ZMQ::PUSH, name, endpoint, {}, &block
14
+ end
15
+
16
+ # this does an endless loop as a "server"
17
+ def zeromq_pull_server name, endpoint = "ipc://#{name}.ipc", &block
18
+ grand_server ZMQ::PULL, name, endpoint, &block
19
+ end
20
+
21
+ # we make the request and return the response
22
+ def zeromq_request name, endpoint = "ipc://#{name}.ipc", **opts, &block
23
+ h = grand_pusher ZMQ::REQ, name, endpoint, **opts, &block
24
+ end
25
+
26
+ def zeromq_response_server name, endpoint = "ipc://#{name}.ipc", &block
27
+ grand_server ZMQ::REP, name, endpoint, bind: true, respond: true, &block
28
+ end
29
+
30
+ private
31
+ # TODO: We don't handle the non-block req case at all. Do we want to?
32
+ def grand_pusher type, name, endpoint, **opts, &block
14
33
  init_sys
15
34
  h = if @ctxh[name].nil?
16
35
  h = (@ctxh[name] ||= OpenStruct.new)
17
36
  h.ctx = ZMQ::Context.create(1)
18
- h.push_sock = h.ctx.socket(ZMQ::PUSH)
37
+ h.push_sock = h.ctx.socket(type)
19
38
  error_check(h.push_sock.setsockopt(ZMQ::LINGER, 0))
20
39
  rc = h.push_sock.bind(endpoint)
21
40
  error_check(rc)
@@ -25,34 +44,49 @@ module ZeroMQ
25
44
  end
26
45
 
27
46
  if block_given?
28
- payload = block.(h.ctx)
29
- rc = h.push_sock.send_string(JSON.generate(payload))
30
- error_check(rc)
47
+ unless opts[:payload]
48
+ # here, we get the payload from the block
49
+ payload = block.(h.ctx)
50
+ rc = h.push_sock.send_string(JSON.generate(payload))
51
+ error_check(rc)
52
+ else
53
+ # here, we call the block with the results
54
+ rc = h.push_sock.send_string(JSON.generate(opts[:payload]))
55
+ error_check(rc)
56
+ rc = h.push_sock.recv_string(result = '')
57
+ error_check(rc)
58
+ block.(JSON.parse(result))
59
+ end
31
60
  end
32
61
  h
33
- end
62
+ end
34
63
 
35
- # this does an endless loop as a "server"
36
- def zeromq_pull_server name, endpoint = "ipc://#{name}.ipc", &block
64
+ def grand_server type, name, endpoint, **opts, &block
37
65
  init_sys
38
66
  h = (@ctxh[name] ||= OpenStruct.new)
39
67
  h.ctx = ZMQ::Context.create(1)
40
68
 
41
- h.pull_sock = h.ctx.socket(ZMQ::PULL)
69
+ h.pull_sock = h.ctx.socket(type)
42
70
  error_check(h.pull_sock.setsockopt(ZMQ::LINGER, 0))
43
-
44
- rc = h.pull_sock.connect(endpoint)
71
+ rc = if opts[:bind]
72
+ h.pull_sock.connect(endpoint)
73
+ else
74
+ h.pull_sock.connect(endpoint)
75
+ end
45
76
  error_check(rc)
46
77
 
47
78
  loop do
48
79
  rc = h.pull_sock.recv_string payload = ''
49
-
50
- block.(JSON.parse(payload))
80
+ error_check(rc)
81
+
82
+ result = block.(JSON.parse(payload))
83
+ if opts[:respond]
84
+ rc = h.pull_sock.send_string JSON.generate(result)
85
+ end
51
86
  end if block_given?
52
87
  h
53
88
  end
54
89
 
55
- private
56
90
  def init_sys
57
91
  @ctxh ||= {}
58
92
  end
@@ -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.4 ruby lib
5
+ # stub: rzmq-enhancement 0.0.14 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "rzmq-enhancement".freeze
9
- s.version = "0.0.4"
9
+ s.version = "0.0.14"
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-06"
14
+ s.date = "2017-06-07"
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]
@@ -30,6 +30,8 @@ Gem::Specification.new do |s|
30
30
  "Rakefile",
31
31
  "bin/rzmq",
32
32
  "examples/push-pull.rb",
33
+ "examples/rr-request.rb",
34
+ "examples/rr-response.rb",
33
35
  "lib/rzmq-enhancement.rb",
34
36
  "rzmq-enhancement.gemspec",
35
37
  "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
4
+ version: 0.0.14
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-06 00:00:00.000000000 Z
12
+ date: 2017-06-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: semver2
@@ -244,6 +244,8 @@ files:
244
244
  - Rakefile
245
245
  - bin/rzmq
246
246
  - examples/push-pull.rb
247
+ - examples/rr-request.rb
248
+ - examples/rr-response.rb
247
249
  - lib/rzmq-enhancement.rb
248
250
  - rzmq-enhancement.gemspec
249
251
  - spec/rzmq-enhancement_spec.rb