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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2b1c640aa3d499463f10de79d7453798a65666a
4
- data.tar.gz: 110882ce6e58ed69d1a660140501e4539f54f9ba
3
+ metadata.gz: 02bb3bd003a801e1bccbf63499e12bedf681e37e
4
+ data.tar.gz: 884528721db8a307dfdc46e66b2b3b51b6929614
5
5
  SHA512:
6
- metadata.gz: 2debf5267b8c786d17b3d5d2316e0e6e6bbffc10576ad7a528c86c16aa687b6b7691b8b356810e517964044fd2005d11dafe3b237fb5fb4c840d7d0f50d21a23
7
- data.tar.gz: 9a69238001e217b496e7141290e0753adeabab7aaf9d2a110c3053a8b16b3235d0d3b1f18b9adbc235a8034a7d3dcd8a5105c0b8c562298415226fdfd3e4576a
6
+ metadata.gz: 3b6088b307501f85b5fbf92ed5c07795990467638c9a5fd948df2658259c57476176386ee2fb266c01b80b1fbb375f3ab2c3dacaca3a230fb6d66e7f898fceb1
7
+ data.tar.gz: cd0cad6abdb9dbf2d12800b4c0964f0381faa20d92ec5099a0b6e6243fba7706bd8782158dff3b4a5479b20637eb1bdd74f5adf4e9237abba179a0ba402e0138
data/.semver CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 0
4
- :patch: 19
4
+ :patch: 26
5
5
  :special: ''
@@ -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 }
@@ -3,7 +3,7 @@ require 'pp'
3
3
  require 'thread'
4
4
 
5
5
  include ZeroMQ
6
- EP = 'ipc://pushpull.ipc'
6
+ EP = 'tcp://127.0.0.1:2600'
7
7
  thr = []
8
8
 
9
9
  # push
@@ -0,0 +1,14 @@
1
+ # coding: utf-8
2
+ require 'rzmq-enhancement'
3
+ require 'pp'
4
+
5
+ include ZeroMQ
6
+
7
+ # request
8
+
9
+ (0..10).each do |i|
10
+ zeromq_request( :hello, payload: [i, i*i] ) do |result|
11
+ print "result: "
12
+ pp result
13
+ end
14
+ end
File without changes
@@ -0,0 +1,13 @@
1
+ require 'rzmq-enhancement'
2
+ require 'pp'
3
+
4
+ include ZeroMQ
5
+
6
+ # response
7
+
8
+ zeromq_response_server :hello do |payload|
9
+ print "respond to this: "
10
+ pp payload
11
+ i, j = payload
12
+ i + j
13
+ end
File without changes
@@ -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, endpoint = "ipc://#{name}.ipc", &block
13
- grand_pusher ZMQ::PUSH, name, endpoint, {}, &block
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, endpoint = "ipc://#{name}.ipc", &block
18
- grand_server ZMQ::PULL, name, endpoint, &block
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, endpoint = "ipc://#{name}.ipc", **opts, &block
23
- h = grand_pusher ZMQ::REQ, name, endpoint, **opts, &block
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, endpoint = "ipc://#{name}.ipc", &block
27
- grand_server ZMQ::REP, name, endpoint, bind: true, respond: true, &block
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
- h = if @ctxh[name].nil?
35
- h = (@ctxh[name] ||= OpenStruct.new)
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[name]
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
- h = (@ctxh[name] ||= OpenStruct.new)
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)
@@ -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.19 ruby lib
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.19"
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-07"
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/rr-request.rb",
34
- "examples/rr-response.rb",
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.19
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-07 00:00:00.000000000 Z
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/rr-request.rb
248
- - examples/rr-response.rb
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