cztop 1.1.1 → 1.2.0
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/CHANGES.md +16 -0
- data/README.md +61 -56
- data/cztop.gemspec +2 -4
- data/lib/cztop/actor.rb +26 -22
- data/lib/cztop/certificate.rb +19 -11
- data/lib/cztop/message.rb +5 -1
- data/lib/cztop/send_receive_methods.rb +106 -2
- data/lib/cztop/socket/types.rb +18 -0
- data/lib/cztop/version.rb +1 -1
- data/lib/cztop/zsock_options.rb +16 -2
- metadata +3 -66
- data/.github/workflows/coverage.yml +0 -20
- data/.github/workflows/draft_api.yml +0 -27
- data/.github/workflows/stable_api.yml +0 -26
- data/.gitignore +0 -10
- data/.projections.json +0 -4
- data/.rspec +0 -2
- data/.rubocop.yml +0 -175
- data/.yardopts +0 -1
- data/Rakefile +0 -6
- data/ci/install-libczmq +0 -22
- data/ci/install-libzmq +0 -22
- data/examples/async/.gitignore +0 -1
- data/examples/async/Gemfile +0 -5
- data/examples/async/README.md +0 -1
- data/examples/async/async.rb +0 -35
- data/examples/ruby_actor/actor.rb +0 -100
- data/examples/simple_req_rep/rep.rb +0 -12
- data/examples/simple_req_rep/req.rb +0 -35
- data/examples/taxi_system/.gitignore +0 -2
- data/examples/taxi_system/Makefile +0 -2
- data/examples/taxi_system/README.gsl +0 -115
- data/examples/taxi_system/README.md +0 -276
- data/examples/taxi_system/broker.rb +0 -97
- data/examples/taxi_system/client.rb +0 -34
- data/examples/taxi_system/generate_keys.rb +0 -24
- data/examples/taxi_system/start_broker.sh +0 -2
- data/examples/taxi_system/start_clients.sh +0 -11
- data/examples/weather_pub_sub/pub.rb +0 -24
- data/examples/weather_pub_sub/sub.rb +0 -33
- data/lib/cztop/async.rb +0 -124
- data/perf/README.md +0 -80
- data/perf/inproc_lat.rb +0 -49
- data/perf/inproc_thru.rb +0 -42
- data/perf/local_lat.rb +0 -35
- data/perf/remote_lat.rb +0 -26
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cztop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrik Wenger
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01-
|
11
|
+
date: 2024-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: czmq-ffi-gen
|
@@ -122,20 +122,6 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: rubocop
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - "~>"
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: 1.36.0
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - "~>"
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: 1.36.0
|
139
125
|
- !ruby/object:Gem::Dependency
|
140
126
|
name: async
|
141
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,20 +136,6 @@ dependencies:
|
|
150
136
|
- - ">="
|
151
137
|
- !ruby/object:Gem::Version
|
152
138
|
version: 2.0.1
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: async-io
|
155
|
-
requirement: !ruby/object:Gem::Requirement
|
156
|
-
requirements:
|
157
|
-
- - ">="
|
158
|
-
- !ruby/object:Gem::Version
|
159
|
-
version: '0'
|
160
|
-
type: :development
|
161
|
-
prerelease: false
|
162
|
-
version_requirements: !ruby/object:Gem::Requirement
|
163
|
-
requirements:
|
164
|
-
- - ">="
|
165
|
-
- !ruby/object:Gem::Version
|
166
|
-
version: '0'
|
167
139
|
description: CZMQ binding based on the generated low-level FFI bindings of CZMQ
|
168
140
|
email:
|
169
141
|
- paddor@gmail.com
|
@@ -173,48 +145,18 @@ executables:
|
|
173
145
|
extensions: []
|
174
146
|
extra_rdoc_files: []
|
175
147
|
files:
|
176
|
-
- ".github/workflows/coverage.yml"
|
177
|
-
- ".github/workflows/draft_api.yml"
|
178
|
-
- ".github/workflows/stable_api.yml"
|
179
|
-
- ".gitignore"
|
180
|
-
- ".projections.json"
|
181
|
-
- ".rspec"
|
182
|
-
- ".rubocop.yml"
|
183
|
-
- ".yardopts"
|
184
148
|
- AUTHORS
|
185
149
|
- CHANGES.md
|
186
150
|
- Gemfile
|
187
151
|
- LICENSE
|
188
152
|
- README.md
|
189
|
-
- Rakefile
|
190
153
|
- bin/console
|
191
154
|
- bin/setup
|
192
|
-
- ci/install-libczmq
|
193
|
-
- ci/install-libzmq
|
194
155
|
- cztop.gemspec
|
195
|
-
- examples/async/.gitignore
|
196
|
-
- examples/async/Gemfile
|
197
|
-
- examples/async/README.md
|
198
|
-
- examples/async/async.rb
|
199
|
-
- examples/ruby_actor/actor.rb
|
200
|
-
- examples/simple_req_rep/rep.rb
|
201
|
-
- examples/simple_req_rep/req.rb
|
202
|
-
- examples/taxi_system/.gitignore
|
203
|
-
- examples/taxi_system/Makefile
|
204
|
-
- examples/taxi_system/README.gsl
|
205
|
-
- examples/taxi_system/README.md
|
206
|
-
- examples/taxi_system/broker.rb
|
207
|
-
- examples/taxi_system/client.rb
|
208
|
-
- examples/taxi_system/generate_keys.rb
|
209
|
-
- examples/taxi_system/start_broker.sh
|
210
|
-
- examples/taxi_system/start_clients.sh
|
211
|
-
- examples/weather_pub_sub/pub.rb
|
212
|
-
- examples/weather_pub_sub/sub.rb
|
213
156
|
- exe/z85decode
|
214
157
|
- exe/z85encode
|
215
158
|
- lib/cztop.rb
|
216
159
|
- lib/cztop/actor.rb
|
217
|
-
- lib/cztop/async.rb
|
218
160
|
- lib/cztop/authenticator.rb
|
219
161
|
- lib/cztop/beacon.rb
|
220
162
|
- lib/cztop/cert_store.rb
|
@@ -244,11 +186,6 @@ files:
|
|
244
186
|
- lib/cztop/z85/pipe.rb
|
245
187
|
- lib/cztop/zap.rb
|
246
188
|
- lib/cztop/zsock_options.rb
|
247
|
-
- perf/README.md
|
248
|
-
- perf/inproc_lat.rb
|
249
|
-
- perf/inproc_thru.rb
|
250
|
-
- perf/local_lat.rb
|
251
|
-
- perf/remote_lat.rb
|
252
189
|
homepage: https://rubygems.org/gems/cztop
|
253
190
|
licenses:
|
254
191
|
- ISC
|
@@ -264,7 +201,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
264
201
|
requirements:
|
265
202
|
- - ">="
|
266
203
|
- !ruby/object:Gem::Version
|
267
|
-
version: 3.
|
204
|
+
version: 3.2.0
|
268
205
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
269
206
|
requirements:
|
270
207
|
- - ">="
|
@@ -1,20 +0,0 @@
|
|
1
|
-
name: Coverage
|
2
|
-
|
3
|
-
on: [push,pull_request]
|
4
|
-
|
5
|
-
jobs:
|
6
|
-
build:
|
7
|
-
runs-on: ubuntu-22.04
|
8
|
-
steps:
|
9
|
-
- uses: actions/checkout@v4
|
10
|
-
- name: Set up Ruby
|
11
|
-
uses: ruby/setup-ruby@v1
|
12
|
-
with:
|
13
|
-
ruby-version: 3.3
|
14
|
-
- name: Install CZMQ
|
15
|
-
run: sudo apt-get install libczmq-dev
|
16
|
-
- name: Run the default task
|
17
|
-
run: |
|
18
|
-
gem install bundler
|
19
|
-
bundle install
|
20
|
-
env REPORT_COVERAGE=true bundle exec rake
|
@@ -1,27 +0,0 @@
|
|
1
|
-
name: DRAFT API
|
2
|
-
|
3
|
-
on: [push,pull_request]
|
4
|
-
|
5
|
-
jobs:
|
6
|
-
build:
|
7
|
-
runs-on: ubuntu-22.04
|
8
|
-
timeout-minutes: 15
|
9
|
-
steps:
|
10
|
-
- uses: actions/checkout@v4
|
11
|
-
- name: Set up Ruby
|
12
|
-
uses: ruby/setup-ruby@v1
|
13
|
-
with:
|
14
|
-
ruby-version: '3.3'
|
15
|
-
- name: Install ZMQ and CZMQ
|
16
|
-
run: |
|
17
|
-
export PKG_CONFIG_PATH=$HOME/lib/pkgconfig # custom libs (for linking)
|
18
|
-
env
|
19
|
-
env ZMQ_VERSION=HEAD ci/install-libzmq
|
20
|
-
env CZMQ_VERSION=HEAD ci/install-libczmq
|
21
|
-
- name: Run the default task
|
22
|
-
run: |
|
23
|
-
export LD_LIBRARY_PATH=$HOME/lib # custom libs (for execution)
|
24
|
-
env
|
25
|
-
gem install bundler
|
26
|
-
bundle install
|
27
|
-
bundle exec rake
|
@@ -1,26 +0,0 @@
|
|
1
|
-
name: STABLE API
|
2
|
-
|
3
|
-
on: [push,pull_request]
|
4
|
-
|
5
|
-
jobs:
|
6
|
-
build:
|
7
|
-
runs-on: ubuntu-22.04
|
8
|
-
strategy:
|
9
|
-
matrix:
|
10
|
-
ruby:
|
11
|
-
- '3.1'
|
12
|
-
- '3.2'
|
13
|
-
- '3.3'
|
14
|
-
steps:
|
15
|
-
- uses: actions/checkout@v4
|
16
|
-
- name: Set up Ruby ${{ matrix.ruby }}
|
17
|
-
uses: ruby/setup-ruby@v1
|
18
|
-
with:
|
19
|
-
ruby-version: ${{ matrix.ruby }}
|
20
|
-
- name: Install CZMQ
|
21
|
-
run: sudo apt-get install libczmq-dev
|
22
|
-
- name: Run the default task
|
23
|
-
run: |
|
24
|
-
gem install bundler
|
25
|
-
bundle install
|
26
|
-
bundle exec rake
|
data/.gitignore
DELETED
data/.projections.json
DELETED
data/.rspec
DELETED
data/.rubocop.yml
DELETED
@@ -1,175 +0,0 @@
|
|
1
|
-
AllCops:
|
2
|
-
TargetRubyVersion: 2.7
|
3
|
-
NewCops: enable
|
4
|
-
Layout/EmptyLineAfterMagicComment:
|
5
|
-
Enabled: true
|
6
|
-
Layout/ExtraSpacing:
|
7
|
-
AllowForAlignment: true
|
8
|
-
Layout/EmptyLines:
|
9
|
-
Enabled: false
|
10
|
-
Layout/EmptyLineBetweenDefs:
|
11
|
-
NumberOfEmptyLines: 2
|
12
|
-
Layout/MultilineOperationIndentation:
|
13
|
-
Enabled: true
|
14
|
-
Gemspec/DeprecatedAttributeAssignment: # new in 1.30
|
15
|
-
Enabled: true
|
16
|
-
Gemspec/RequireMFA: # new in 1.23
|
17
|
-
Enabled: true
|
18
|
-
Layout/LineContinuationLeadingSpace: # new in 1.31
|
19
|
-
Enabled: true
|
20
|
-
Layout/LineContinuationSpacing: # new in 1.31
|
21
|
-
Enabled: true
|
22
|
-
Layout/LineEndStringConcatenationIndentation: # new in 1.18
|
23
|
-
Enabled: true
|
24
|
-
Layout/SpaceBeforeBrackets: # new in 1.7
|
25
|
-
Enabled: true
|
26
|
-
Lint/AmbiguousAssignment: # new in 1.7
|
27
|
-
Enabled: true
|
28
|
-
Lint/AmbiguousOperatorPrecedence: # new in 1.21
|
29
|
-
Enabled: false
|
30
|
-
Lint/AmbiguousRange: # new in 1.19
|
31
|
-
Enabled: true
|
32
|
-
Lint/ConstantOverwrittenInRescue: # new in 1.31
|
33
|
-
Enabled: true
|
34
|
-
Lint/DeprecatedConstants: # new in 1.8
|
35
|
-
Enabled: true
|
36
|
-
Lint/DuplicateBranch: # new in 1.3
|
37
|
-
Enabled: true
|
38
|
-
Lint/DuplicateRegexpCharacterClassElement: # new in 1.1
|
39
|
-
Enabled: true
|
40
|
-
Lint/EmptyBlock: # new in 1.1
|
41
|
-
Enabled: true
|
42
|
-
Lint/EmptyClass: # new in 1.3
|
43
|
-
Enabled: true
|
44
|
-
Lint/EmptyInPattern: # new in 1.16
|
45
|
-
Enabled: true
|
46
|
-
Lint/IncompatibleIoSelectWithFiberScheduler: # new in 1.21
|
47
|
-
Enabled: true
|
48
|
-
Lint/LambdaWithoutLiteralBlock: # new in 1.8
|
49
|
-
Enabled: true
|
50
|
-
Lint/NoReturnInBeginEndBlocks: # new in 1.2
|
51
|
-
Enabled: true
|
52
|
-
Lint/NonAtomicFileOperation: # new in 1.31
|
53
|
-
Enabled: true
|
54
|
-
Lint/NumberedParameterAssignment: # new in 1.9
|
55
|
-
Enabled: true
|
56
|
-
Lint/OrAssignmentToConstant: # new in 1.9
|
57
|
-
Enabled: true
|
58
|
-
Lint/RedundantDirGlobSort: # new in 1.8
|
59
|
-
Enabled: true
|
60
|
-
Lint/RefinementImportMethods: # new in 1.27
|
61
|
-
Enabled: true
|
62
|
-
Lint/RequireRangeParentheses: # new in 1.32
|
63
|
-
Enabled: true
|
64
|
-
Lint/RequireRelativeSelfPath: # new in 1.22
|
65
|
-
Enabled: true
|
66
|
-
Lint/SymbolConversion: # new in 1.9
|
67
|
-
Enabled: true
|
68
|
-
Lint/ToEnumArguments: # new in 1.1
|
69
|
-
Enabled: true
|
70
|
-
Lint/TripleQuotes: # new in 1.9
|
71
|
-
Enabled: true
|
72
|
-
Lint/UnexpectedBlockArity: # new in 1.5
|
73
|
-
Enabled: true
|
74
|
-
Lint/UnmodifiedReduceAccumulator: # new in 1.1
|
75
|
-
Enabled: true
|
76
|
-
Lint/UselessRuby2Keywords: # new in 1.23
|
77
|
-
Enabled: true
|
78
|
-
Naming/BlockForwarding: # new in 1.24
|
79
|
-
Enabled: true
|
80
|
-
Security/CompoundHash: # new in 1.28
|
81
|
-
Enabled: true
|
82
|
-
Security/IoMethods: # new in 1.22
|
83
|
-
Enabled: true
|
84
|
-
Style/AndOr:
|
85
|
-
EnforcedStyle: conditionals
|
86
|
-
Style/InfiniteLoop:
|
87
|
-
Enabled: false
|
88
|
-
Style/ArgumentsForwarding: # new in 1.1
|
89
|
-
Enabled: true
|
90
|
-
Style/CollectionCompact: # new in 1.2
|
91
|
-
Enabled: true
|
92
|
-
Style/DocumentDynamicEvalDefinition: # new in 1.1
|
93
|
-
Enabled: true
|
94
|
-
Style/EmptyHeredoc: # new in 1.32
|
95
|
-
Enabled: true
|
96
|
-
Style/EndlessMethod: # new in 1.8
|
97
|
-
Enabled: true
|
98
|
-
Style/EnvHome: # new in 1.29
|
99
|
-
Enabled: true
|
100
|
-
Style/FetchEnvVar: # new in 1.28
|
101
|
-
Enabled: true
|
102
|
-
Style/FileRead: # new in 1.24
|
103
|
-
Enabled: true
|
104
|
-
Style/FileWrite: # new in 1.24
|
105
|
-
Enabled: true
|
106
|
-
Style/FrozenStringLiteralComment:
|
107
|
-
EnforcedStyle: always_true
|
108
|
-
Style/HashConversion: # new in 1.10
|
109
|
-
Enabled: true
|
110
|
-
Style/HashExcept: # new in 1.7
|
111
|
-
Enabled: true
|
112
|
-
Style/IfWithBooleanLiteralBranches: # new in 1.9
|
113
|
-
Enabled: true
|
114
|
-
Style/InPatternThen: # new in 1.16
|
115
|
-
Enabled: true
|
116
|
-
Style/MagicCommentFormat: # new in 1.35
|
117
|
-
Enabled: true
|
118
|
-
Style/MapCompactWithConditionalBlock: # new in 1.30
|
119
|
-
Enabled: true
|
120
|
-
Style/MapToHash: # new in 1.24
|
121
|
-
Enabled: true
|
122
|
-
Style/MultilineInPatternThen: # new in 1.16
|
123
|
-
Enabled: true
|
124
|
-
Style/NegatedIfElseCondition: # new in 1.2
|
125
|
-
Enabled: true
|
126
|
-
Style/NestedFileDirname: # new in 1.26
|
127
|
-
Enabled: true
|
128
|
-
Style/NilLambda: # new in 1.3
|
129
|
-
Enabled: true
|
130
|
-
Style/NumberedParameters: # new in 1.22
|
131
|
-
Enabled: true
|
132
|
-
Style/NumberedParametersLimit: # new in 1.22
|
133
|
-
Enabled: true
|
134
|
-
Style/ObjectThen: # new in 1.28
|
135
|
-
Enabled: true
|
136
|
-
Style/OpenStructUse: # new in 1.23
|
137
|
-
Enabled: true
|
138
|
-
Style/QuotedSymbols: # new in 1.16
|
139
|
-
Enabled: true
|
140
|
-
Style/RedundantArgument: # new in 1.4
|
141
|
-
Enabled: true
|
142
|
-
Style/RedundantInitialize: # new in 1.27
|
143
|
-
Enabled: true
|
144
|
-
Style/RedundantSelfAssignmentBranch: # new in 1.19
|
145
|
-
Enabled: true
|
146
|
-
Style/SelectByRegexp: # new in 1.22
|
147
|
-
Enabled: true
|
148
|
-
Style/StringChars: # new in 1.12
|
149
|
-
Enabled: true
|
150
|
-
Style/SwapValues: # new in 1.1
|
151
|
-
Enabled: true
|
152
|
-
Style/ClassAndModuleChildren:
|
153
|
-
Enabled: false
|
154
|
-
Style/StringConcatenation:
|
155
|
-
Enabled: false
|
156
|
-
Style/RescueModifier:
|
157
|
-
Enabled: false
|
158
|
-
Style/YodaCondition:
|
159
|
-
Enabled: false
|
160
|
-
Lint/AmbiguousRegexpLiteral:
|
161
|
-
Enabled: false
|
162
|
-
Style/WordArray:
|
163
|
-
Enabled: false
|
164
|
-
Style/Semicolon:
|
165
|
-
Enabled: false
|
166
|
-
Naming/MethodName:
|
167
|
-
Enabled: false
|
168
|
-
Style/EmptyMethod:
|
169
|
-
Enabled: false
|
170
|
-
Layout/EmptyLinesAroundClassBody:
|
171
|
-
Enabled: true
|
172
|
-
EnforcedStyle: empty_lines_except_namespace
|
173
|
-
Layout/EmptyLinesAroundModuleBody:
|
174
|
-
Enabled: true
|
175
|
-
EnforcedStyle: empty_lines_except_namespace
|
data/.yardopts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--private lib/**/*.rb - README.md LICENSE
|
data/Rakefile
DELETED
data/ci/install-libczmq
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
#!/bin/sh -x
|
2
|
-
# vim: ft=sh
|
3
|
-
set -e
|
4
|
-
mkdir -p ~/src
|
5
|
-
cd ~/src
|
6
|
-
|
7
|
-
case "$CZMQ_VERSION" in
|
8
|
-
HEAD)
|
9
|
-
echo "Using HEAD and compiling with --enable-drafts ..."
|
10
|
-
git clone https://github.com/zeromq/czmq czmq
|
11
|
-
CONFIGURE_OPTS="--enable-drafts=yes"
|
12
|
-
;;
|
13
|
-
*)
|
14
|
-
echo '$CZMQ_VERSION not set.'
|
15
|
-
exit 1
|
16
|
-
esac
|
17
|
-
|
18
|
-
cd czmq
|
19
|
-
./autogen.sh
|
20
|
-
./configure --prefix=$HOME $CONFIGURE_OPTS
|
21
|
-
make
|
22
|
-
make install
|
data/ci/install-libzmq
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
#!/bin/sh -x
|
2
|
-
# vim: ft=sh
|
3
|
-
set -e
|
4
|
-
mkdir -p ~/src
|
5
|
-
cd ~/src
|
6
|
-
|
7
|
-
case "$ZMQ_VERSION" in
|
8
|
-
HEAD)
|
9
|
-
echo "Using HEAD and compiling with --enable-drafts ..."
|
10
|
-
git clone https://github.com/zeromq/libzmq libzmq
|
11
|
-
CONFIGURE_OPTS="--enable-drafts=yes"
|
12
|
-
;;
|
13
|
-
*)
|
14
|
-
echo '$ZMQ_VERSION not set.'
|
15
|
-
exit 1
|
16
|
-
esac
|
17
|
-
|
18
|
-
cd libzmq
|
19
|
-
./autogen.sh
|
20
|
-
./configure --prefix=$HOME $CONFIGURE_OPTS
|
21
|
-
make
|
22
|
-
make install
|
data/examples/async/.gitignore
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
/Gemfile.lock
|
data/examples/async/Gemfile
DELETED
data/examples/async/README.md
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Run: `bundle exec ./async.rb`
|
data/examples/async/async.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
#! /usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'cztop/async'
|
4
|
-
|
5
|
-
Async do |task|
|
6
|
-
task.async do |t|
|
7
|
-
socket = CZTop::Socket::REP.new("inproc://req_rep_example")
|
8
|
-
io = Async::IO.try_convert socket
|
9
|
-
|
10
|
-
socket.options.rcvtimeo = 50 # ms
|
11
|
-
|
12
|
-
loop do
|
13
|
-
msg = io.receive
|
14
|
-
puts "<<< #{msg.to_a.inspect}"
|
15
|
-
io << msg.to_a.map(&:upcase)
|
16
|
-
rescue IO::TimeoutError
|
17
|
-
break
|
18
|
-
end
|
19
|
-
|
20
|
-
puts "REP done."
|
21
|
-
end
|
22
|
-
|
23
|
-
task.async do
|
24
|
-
socket = CZTop::Socket::REQ.new("inproc://req_rep_example")
|
25
|
-
io = Async::IO.try_convert socket
|
26
|
-
|
27
|
-
10.times do |i|
|
28
|
-
io << "foobar ##{i}"
|
29
|
-
msg = io.receive
|
30
|
-
puts ">>> #{msg.to_a.inspect}"
|
31
|
-
end
|
32
|
-
|
33
|
-
puts "REQ done."
|
34
|
-
end
|
35
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'cztop'
|
3
|
-
|
4
|
-
##
|
5
|
-
# This example shows how to create a simple actor using a Ruby block.
|
6
|
-
# Of course it also supports the CZMQ-native way, passing a pointer to
|
7
|
-
# a C function. That's how CZTop::Beacon, CZTop::Authenticator, ... are
|
8
|
-
# implemented.
|
9
|
-
#
|
10
|
-
|
11
|
-
counter = 0
|
12
|
-
actor = CZTop::Actor.new do |msg, pipe|
|
13
|
-
# This block is called once for every received message.
|
14
|
-
|
15
|
-
case command = msg[0]
|
16
|
-
when "UPCASE"
|
17
|
-
# Upcase second message frame and send back.
|
18
|
-
word = msg[1]
|
19
|
-
puts ">>> Actor converts #{word.inspect} to uppercase."
|
20
|
-
pipe << word.upcase
|
21
|
-
when "COUNT"
|
22
|
-
# Count up.
|
23
|
-
counter += 1
|
24
|
-
puts ">>> Actor has incremented counter to: #{counter}"
|
25
|
-
when "PRODUCE"
|
26
|
-
# Produce multiple messages.
|
27
|
-
num = msg[1].to_i
|
28
|
-
puts ">>> Actor produces #{num} messages."
|
29
|
-
num.times { |i| pipe << "FOO #{i+1}/#{num}" }
|
30
|
-
else
|
31
|
-
# crashes actor #=> Actor#dead? and Actor#crashed? will return true
|
32
|
-
# also, Actor#exception will return this exception.
|
33
|
-
raise "invalid command: #{command}"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
puts ">>> Actor created."
|
37
|
-
|
38
|
-
##
|
39
|
-
# Let actor count.
|
40
|
-
#
|
41
|
-
# Actor#<< is thread-safe.
|
42
|
-
#
|
43
|
-
actor << "COUNT"
|
44
|
-
actor << "COUNT"
|
45
|
-
actor << "COUNT"
|
46
|
-
actor << "COUNT"
|
47
|
-
actor << "COUNT"
|
48
|
-
actor << "COUNT"
|
49
|
-
|
50
|
-
|
51
|
-
##
|
52
|
-
# Request a response from actor.
|
53
|
-
#
|
54
|
-
# Actor#request is thread-safe and ensures that the right response gets
|
55
|
-
# returned.
|
56
|
-
#
|
57
|
-
puts actor.request(["UPCASE", "foobar"]).inspect
|
58
|
-
#=> #<CZTop::Message:0x7f98c8d96000 frames=1 content_size=6 content=["FOOBAR"]>
|
59
|
-
|
60
|
-
|
61
|
-
##
|
62
|
-
# Let actor produce some messages.
|
63
|
-
#
|
64
|
-
# Actor#receive is thread-safe, but doesn't guarantee any particular order.
|
65
|
-
#
|
66
|
-
actor << %w[ PRODUCE 5 ]
|
67
|
-
puts actor.receive[0] #1
|
68
|
-
puts actor.receive[0] #2
|
69
|
-
puts actor.receive[0] #3
|
70
|
-
puts actor.receive[0] #4
|
71
|
-
puts actor.receive[0] #5
|
72
|
-
|
73
|
-
##
|
74
|
-
# Let actor die.
|
75
|
-
#
|
76
|
-
# Blocks until dead.
|
77
|
-
actor.terminate
|
78
|
-
actor.dead? #=> true
|
79
|
-
actor.crashed? #=> false
|
80
|
-
actor.exception #=> nil, because it didn't crash
|
81
|
-
|
82
|
-
|
83
|
-
__END__
|
84
|
-
Example output:
|
85
|
-
|
86
|
-
>>> Actor created.
|
87
|
-
>>> Actor has incremented counter to: 1
|
88
|
-
>>> Actor has incremented counter to: 2
|
89
|
-
>>> Actor has incremented counter to: 3
|
90
|
-
>>> Actor has incremented counter to: 4
|
91
|
-
>>> Actor has incremented counter to: 5
|
92
|
-
>>> Actor has incremented counter to: 6
|
93
|
-
>>> Actor converts "foobar" to uppercase.
|
94
|
-
#<CZTop::Message:0x7f81c55bdca0 frames=1 content_size=6 content=["FOOBAR"]>
|
95
|
-
>>> Actor produces 5 messages.
|
96
|
-
FOO 1/5
|
97
|
-
FOO 2/5
|
98
|
-
FOO 3/5
|
99
|
-
FOO 4/5
|
100
|
-
FOO 5/5
|
@@ -1,12 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'cztop'
|
3
|
-
|
4
|
-
# create and bind socket
|
5
|
-
socket = CZTop::Socket::REP.new("ipc:///tmp/req_rep_example")
|
6
|
-
puts "<<< Socket bound to #{socket.last_endpoint.inspect}"
|
7
|
-
|
8
|
-
# Simply echo every message, with every frame String#upcase'd.
|
9
|
-
while msg = socket.receive
|
10
|
-
puts "<<< #{msg.to_a.inspect}"
|
11
|
-
socket << msg.to_a.map(&:upcase)
|
12
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'cztop'
|
3
|
-
|
4
|
-
# connect
|
5
|
-
socket = CZTop::Socket::REQ.new("ipc:///tmp/req_rep_example")
|
6
|
-
puts ">>> Socket connected."
|
7
|
-
|
8
|
-
# simple string
|
9
|
-
socket << "foobar"
|
10
|
-
msg = socket.receive
|
11
|
-
puts ">>> #{msg.to_a.inspect}"
|
12
|
-
|
13
|
-
# multi frame message as array
|
14
|
-
socket << %w[foo bar baz]
|
15
|
-
msg = socket.receive
|
16
|
-
puts ">>> #{msg.to_a.inspect}"
|
17
|
-
|
18
|
-
# manually instantiating a Message
|
19
|
-
msg = CZTop::Message.new("bla")
|
20
|
-
msg << "another frame" # append a frame
|
21
|
-
socket << msg
|
22
|
-
msg = socket.receive
|
23
|
-
puts ">>> #{msg.to_a.inspect}"
|
24
|
-
|
25
|
-
##
|
26
|
-
# This will send 20 additional messages:
|
27
|
-
#
|
28
|
-
# ./req.rb 20
|
29
|
-
#
|
30
|
-
if ARGV.first
|
31
|
-
ARGV.first.to_i.times do
|
32
|
-
socket << ["fooooooooo", "baaaaaar"]
|
33
|
-
puts ">>> " + socket.receive.to_a.inspect
|
34
|
-
end
|
35
|
-
end
|