em-zmq-tp10 0.1.17 → 0.1.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: be62a1ea0af2e99a3b6a974a2a3e2da94d4a548b
4
+ data.tar.gz: e11e1a7b60f8736e5686dc16a3b735e7c5292bc4
5
+ SHA512:
6
+ metadata.gz: 8fbde09f3e2ae2d9fc1912365c7fcbdc66abc7ea72a9113d8e3a0aa834fe7a1bd9314ee92759cf11c15faa79103a99262610e4950137cd0cbc9ceaa032105094
7
+ data.tar.gz: 67e2778866ed15fac8c1ce186a4b0d0f7b47be93958319c5d8377743fe73cc1992ab97ccfb69dd280640fdf59fad71c93263a5b4338653a522f613ab98257916
data/README.md CHANGED
@@ -48,95 +48,99 @@ And you could do any crazy thing using base `EM::Protocols::Zmq2::Socket` class
48
48
 
49
49
  ### Dealer
50
50
 
51
- class MyPreDealer < EM::Protocols::Zmq2::PreDealer
52
- def receive_message(message)
53
- puts "Message received: #{message.inspect}"
54
- end
55
- end
56
- dealer = MyPreDealer.new
57
- dealer.connect('tcp://127.0.0.1:8000')
58
- dealer.bind('unix://dealer.sock')
59
- EM.schedule {
60
- if !dealer.send_message(['asdf','fdas'])
61
- puts "Could not send message (no free peers)"
62
- end
63
- }
64
-
65
- class MyDealer < EM::Protocols::Zmq2::Dealer
66
- def receive_message(message)
67
- puts "Message received: #{message.inspect}"
68
- end
69
- end
70
- dealer = MyDealer.new(hwm: 1000, hwm_strategy: :drop_last)
71
- dealer.connect('tcp://127.0.0.1:8000')
72
- EM.schedule {
73
- if !dealer.send_message(['asdf','fdas'])
74
- puts "No free peers and outgoing queue is full"
75
- end
76
- }
77
-
78
- dealer = EM::Protocols::Zmq2::DealerCb.new do |message|
79
- puts "Receive message #{message.inspect}"
80
- end
81
- dealer.connect('ipc://rep')
82
- EM.schedule {
83
- dealer.send_message(['hello','world'])
84
- }
51
+ ```ruby
52
+ class MyPreDealer < EM::Protocols::Zmq2::PreDealer
53
+ def receive_message(message)
54
+ puts "Message received: #{message.inspect}"
55
+ end
56
+ end
57
+ dealer = MyPreDealer.new
58
+ dealer.connect('tcp://127.0.0.1:8000')
59
+ dealer.bind('unix://dealer.sock')
60
+ EM.schedule {
61
+ if !dealer.send_message(['asdf','fdas'])
62
+ puts "Could not send message (no free peers)"
63
+ end
64
+ }
65
+
66
+ class MyDealer < EM::Protocols::Zmq2::Dealer
67
+ def receive_message(message)
68
+ puts "Message received: #{message.inspect}"
69
+ end
70
+ end
71
+ dealer = MyDealer.new(hwm: 1000, hwm_strategy: :drop_last)
72
+ dealer.connect('tcp://127.0.0.1:8000')
73
+ EM.schedule {
74
+ if !dealer.send_message(['asdf','fdas'])
75
+ puts "No free peers and outgoing queue is full"
76
+ end
77
+ }
78
+
79
+ dealer = EM::Protocols::Zmq2::DealerCb.new do |message|
80
+ puts "Receive message #{message.inspect}"
81
+ end
82
+ dealer.connect('ipc://rep')
83
+ EM.schedule {
84
+ dealer.send_message(['hello','world'])
85
+ }
86
+ ```
85
87
 
86
88
  ### Req
87
89
 
88
- class MyPreReq < EM::Protocols::Zmq2::PreReq
89
- def receive_reply(message, data, request_id)
90
- puts "Received message #{message} and stored data #{data}
91
- end
92
- end
93
- req = MyPreReq.new
94
- req.bind(...)
95
- req.connect(...)
96
- if request_id = req.send_request(['this is', 'message'], 'saved_data')
97
- puts "Message sent"
98
- else
99
- puts "there is no free peer"
100
- end
101
-
102
- class MyReq < EM::Protocols::Zmq2::PreReq
103
- def receive_reply(message, data, request_id)
104
- puts "Received message #{message} and stored data #{data}
105
- end
106
- end
107
- req = MyReq.new
108
- req.bind(...)
109
- req.connect(...)
110
- if request_id = req.send_request(['hi'], 'ho')
111
- puts "Message sent"
112
- end
113
-
114
- req = EM::Protocols::Zmq2::ReqCb.new
115
- req.bind('ipc://req')
116
- timer = nil
117
- request_id = req.send_request(['hello', 'world']) do |message|
118
- EM.cancel_timer(timer)
119
- puts "Message #{message}"
120
- end
121
- if request_id
122
- timer = EM.add_timer(1) {
123
- req.cancel_request(request_id)
124
- }
125
- end
126
-
127
- req = EM::Protocols::Zmq2::ReqDefer.new
128
- req.bind('ipc://req')
129
- data = {hi: 'ho'}
130
- deferable = req.send_request(['hello', 'world'], data) do |reply, data|
131
- puts "Reply received #{reply} #{data}"
132
- end
133
- deferable.timeout 1
134
- deferable.errback do
135
- puts "Message canceled"
136
- end
137
- deferable.callback do |reply, data|
138
- puts "Another callback #{reply} #{data}"
139
- end
90
+ ```ruby
91
+ class MyPreReq < EM::Protocols::Zmq2::PreReq
92
+ def receive_reply(message, data, request_id)
93
+ puts "Received message #{message} and stored data #{data}"
94
+ end
95
+ end
96
+ req = MyPreReq.new
97
+ req.bind(...)
98
+ req.connect(...)
99
+ if request_id = req.send_request(['this is', 'message'], 'saved_data')
100
+ puts "Message sent"
101
+ else
102
+ puts "there is no free peer"
103
+ end
104
+
105
+ class MyReq < EM::Protocols::Zmq2::PreReq
106
+ def receive_reply(message, data, request_id)
107
+ puts "Received message #{message} and stored data #{data}"
108
+ end
109
+ end
110
+ req = MyReq.new
111
+ req.bind(...)
112
+ req.connect(...)
113
+ if request_id = req.send_request(['hi'], 'ho')
114
+ puts "Message sent"
115
+ end
116
+
117
+ req = EM::Protocols::Zmq2::ReqCb.new
118
+ req.bind('ipc://req')
119
+ timer = nil
120
+ request_id = req.send_request(['hello', 'world']) do |message|
121
+ EM.cancel_timer(timer)
122
+ puts "Message #{message}"
123
+ end
124
+ if request_id
125
+ timer = EM.add_timer(1) {
126
+ req.cancel_request(request_id)
127
+ }
128
+ end
129
+
130
+ req = EM::Protocols::Zmq2::ReqDefer.new
131
+ req.bind('ipc://req')
132
+ data = {hi: 'ho'}
133
+ deferable = req.send_request(['hello', 'world'], data) do |reply, data|
134
+ puts "Reply received #{reply} #{data}"
135
+ end
136
+ deferable.timeout 1
137
+ deferable.errback do
138
+ puts "Message canceled"
139
+ end
140
+ deferable.callback do |reply, data|
141
+ puts "Another callback #{reply} #{data}"
142
+ end
143
+ ```
140
144
 
141
145
  ### Router
142
146
 
@@ -144,51 +148,55 @@ Router stores peer identity in a message, as ZMQ router do.
144
148
  And it sends message to a peer, which idenitity equals to first message string.
145
149
  `PreRouter` does no any queue caching, `Router` saves message in queue per peer, controlled by highwatermark strategy.
146
150
 
147
- class MyPreRouter < EM::Protocols::Zmq2::PreRouter
148
- def receive_message(message)
149
- puts "Received message #{message} (and it contains envelope)"
150
- end
151
- end
152
- router = MyPreRouter.new
153
- router.bind(...)
154
- router.send_message(message)
155
-
156
- class MyRouter < EM::Protocols::Zmq2::Router
157
- def receive_message(message)
158
- puts "Received message #{message}"
159
- message[-1] = 'reply'
160
- send_message(message)
161
- end
162
- end
163
- router = MyPreRouter.new(hwm: 1000, hwm_strategy: :drop_first)
164
- router.bind(...)
165
- router.send_message(message)
151
+ ```ruby
152
+ class MyPreRouter < EM::Protocols::Zmq2::PreRouter
153
+ def receive_message(message)
154
+ puts "Received message #{message} (and it contains envelope)"
155
+ end
156
+ end
157
+ router = MyPreRouter.new
158
+ router.bind(...)
159
+ router.send_message(message)
160
+
161
+ class MyRouter < EM::Protocols::Zmq2::Router
162
+ def receive_message(message)
163
+ puts "Received message #{message}"
164
+ message[-1] = 'reply'
165
+ send_message(message)
166
+ end
167
+ end
168
+ router = MyPreRouter.new(hwm: 1000, hwm_strategy: :drop_first)
169
+ router.bind(...)
170
+ router.send_message(message)
171
+ ```
166
172
 
167
173
  ### Rep
168
174
 
169
175
  REP differs from Router mainly in methods signature.
170
176
 
171
- class EchoBangPreRep < EM::Protocols::Zmq2::PreRep
172
- def receive_request(message, envelope)
173
- message << "!"
174
- if send_reply(message, envelope)
175
- puts "reply sent successfuly"
176
- end
177
- end
178
- end
179
- rep = EchoBangPreRep.new
180
- rep.bind('ipc://rep')
181
-
182
- class EchoBangRep < EM::Protocols::Zmq2::Rep
183
- def receive_request(message, envelope)
184
- message << "!"
185
- if send_reply(message, envelope)
186
- puts "reply sent successfuly"
187
- end
188
- end
189
- end
190
- rep = EchoBangRep.new
191
- rep.bind('ipc://rep')
177
+ ```ruby
178
+ class EchoBangPreRep < EM::Protocols::Zmq2::PreRep
179
+ def receive_request(message, envelope)
180
+ message << "!"
181
+ if send_reply(message, envelope)
182
+ puts "reply sent successfuly"
183
+ end
184
+ end
185
+ end
186
+ rep = EchoBangPreRep.new
187
+ rep.bind('ipc://rep')
188
+
189
+ class EchoBangRep < EM::Protocols::Zmq2::Rep
190
+ def receive_request(message, envelope)
191
+ message << "!"
192
+ if send_reply(message, envelope)
193
+ puts "reply sent successfuly"
194
+ end
195
+ end
196
+ end
197
+ rep = EchoBangRep.new
198
+ rep.bind('ipc://rep')
199
+ ```
192
200
 
193
201
  ### Sub
194
202
 
@@ -197,19 +205,21 @@ Note that as in ZMQ 2.x filtering occurs on Sub side.
197
205
 
198
206
  Since subscriptions could be defined with callback passed to `:subscribe` option, `subscribe` or `subscribe_many` methods, you could use this class without overloading.
199
207
 
200
- class MySub < EM::Protocols::Zmq2::Sub
201
- def receive_message(message)
202
- puts "default handler"
203
- end
204
- end
205
- sub = MySub.new(subscribe: ['this', 'that'])
206
- sub.subscribe /^callback/i, do |message|
207
- puts "Callback subscribe #{message}"
208
- end
209
- sub.subscribe_many(
210
- proc{|s| s.end_with?("END")} => proc{|message| puts "TILL END #{message}"},
211
- '' => nil # also to default
212
- )
208
+ ```ruby
209
+ class MySub < EM::Protocols::Zmq2::Sub
210
+ def receive_message(message)
211
+ puts "default handler"
212
+ end
213
+ end
214
+ sub = MySub.new(subscribe: ['this', 'that'])
215
+ sub.subscribe /^callback/i, do |message|
216
+ puts "Callback subscribe #{message}"
217
+ end
218
+ sub.subscribe_many(
219
+ proc{|s| s.end_with?("END")} => proc{|message| puts "TILL END #{message}"},
220
+ '' => nil # also to default
221
+ )
222
+ ```
213
223
 
214
224
  ### Pub
215
225
 
@@ -219,14 +229,15 @@ Since subscriptions could be defined with callback passed to `:subscribe` option
219
229
 
220
230
  Since there is no incoming data, there is no need to overload methods.
221
231
 
222
- pub = EM::Protocols::Zmq2::PrePub.new
223
- pub.bind(...)
224
- pub.send_message(['hi', 'you'])
225
-
226
- pub = EM::Protocols::Zmq2::Pub.new
227
- pub.bind(...)
228
- pub.send_message(['hi', 'you'])
232
+ ```ruby
233
+ pub = EM::Protocols::Zmq2::PrePub.new
234
+ pub.bind(...)
235
+ pub.send_message(['hi', 'you'])
229
236
 
237
+ pub = EM::Protocols::Zmq2::Pub.new
238
+ pub.bind(...)
239
+ pub.send_message(['hi', 'you'])
240
+ ```
230
241
 
231
242
  ## Contributing
232
243
 
@@ -12,7 +12,11 @@ module EM
12
12
  attr :identity, :hwm
13
13
  attr_accessor :hwm_strategy
14
14
  attr_accessor :do_balance
15
- GENERATED = '%GN%'.freeze
15
+ if String.method_defined?(:b)
16
+ GENERATED = '%GN%'.b.freeze
17
+ else
18
+ GENERATED = '%GN%'.force_encoding('BINARY').freeze
19
+ end
16
20
 
17
21
  # Accept options, which are dependend on socket type
18
22
  # Common options are:
@@ -1,7 +1,7 @@
1
1
  module EventMachine
2
2
  module Protocols
3
3
  module Zmq2
4
- VERSION = '0.1.17'
4
+ VERSION = '0.1.18'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,48 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-zmq-tp10
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.1.17
4
+ version: 0.1.18
6
5
  platform: ruby
7
6
  authors:
8
7
  - Sokolov Yura 'funny-falcon'
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-12 00:00:00.000000000 Z
11
+ date: 2015-05-18 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- type: :runtime
14
+ name: eventmachine
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
20
+ type: :runtime
22
21
  prerelease: false
23
22
  version_requirements: !ruby/object:Gem::Requirement
24
- none: false
25
23
  requirements:
26
- - - ! '>='
24
+ - - ">="
27
25
  - !ruby/object:Gem::Version
28
26
  version: '0'
29
- name: eventmachine
30
27
  - !ruby/object:Gem::Dependency
31
- type: :development
28
+ name: ffi-rzmq
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
34
+ type: :development
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
- none: false
41
37
  requirements:
42
- - - ! '>='
38
+ - - ">="
43
39
  - !ruby/object:Gem::Version
44
40
  version: '0'
45
- name: ffi-rzmq
46
41
  description: Implementation of ZMQ2.x transport protocol - ZMTP1.0
47
42
  email:
48
43
  - funny.falcon@gmail.com
@@ -50,7 +45,7 @@ executables: []
50
45
  extensions: []
51
46
  extra_rdoc_files: []
52
47
  files:
53
- - .gitignore
48
+ - ".gitignore"
54
49
  - Gemfile
55
50
  - LICENSE
56
51
  - README.md
@@ -81,27 +76,26 @@ files:
81
76
  - tests/test_router.rb
82
77
  homepage: https://github.com/funny-falcon/em-zmq-tp10
83
78
  licenses: []
79
+ metadata: {}
84
80
  post_install_message:
85
81
  rdoc_options: []
86
82
  require_paths:
87
83
  - lib
88
84
  required_ruby_version: !ruby/object:Gem::Requirement
89
- none: false
90
85
  requirements:
91
- - - ! '>='
86
+ - - ">="
92
87
  - !ruby/object:Gem::Version
93
88
  version: 1.9.2
94
89
  required_rubygems_version: !ruby/object:Gem::Requirement
95
- none: false
96
90
  requirements:
97
- - - ! '>='
91
+ - - ">="
98
92
  - !ruby/object:Gem::Version
99
93
  version: '0'
100
94
  requirements: []
101
95
  rubyforge_project:
102
- rubygems_version: 1.8.24
96
+ rubygems_version: 2.4.4
103
97
  signing_key:
104
- specification_version: 3
98
+ specification_version: 4
105
99
  summary: Implementation of ZMQ2.1 transport protocol and main socket types using EventMachine
106
100
  for managing TCP/UNIX connections, doing nonblocking writes and calling callback
107
101
  on incoming messages.