deployable-zmq 0.1.0

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: 7b38da49f52f8b88d57529eb15df09ef2460506e
4
+ data.tar.gz: f55835752a470568a9667cbd5e745adfb6b4e2ff
5
+ SHA512:
6
+ metadata.gz: 64651d4e901506a85879df9884700c25fb4944b2bf0551a975c367c53fb50626e532b48d8001bc7570a0546436b9e5e1ff501e43f112f6aaccde5b0a28ff0298
7
+ data.tar.gz: d7868d05fdbae14a99bb9eaf9c1d8e3bb147ba464a7f20446d04b63c325aca47dec99925a5f8d6c5c9125649e3db2bd0dfed29069697aa6c0610e338638e1d50
data/.document ADDED
@@ -0,0 +1,3 @@
1
+ -
2
+ ChangeLog.md
3
+ LICENSE.txt
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ doc/
2
+ pkg/
3
+ .svn/
4
+ .gems/
5
+ .bundle/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format documentation
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown --title "deployable-zmq Documentation" --protected
data/ChangeLog.md ADDED
@@ -0,0 +1,4 @@
1
+ ### 0.1.0 / 2014-10-21
2
+
3
+ * Initial release:
4
+
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Deployable Ltd Matt Hoyle
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # deployable-zmq
2
+
3
+ * [Homepage](https://rubygems.org/gems/deployable-zmq)
4
+ * [Documentation](http://rubydoc.info/gems/deployable-zmq/frames)
5
+ * [Email](mailto:code at deployable.co)
6
+
7
+ ## Description
8
+
9
+ TODO: Description
10
+
11
+ ## Features
12
+
13
+ ## Examples
14
+
15
+ require 'deployable/zmq'
16
+
17
+ ## Requirements
18
+
19
+ ## Install
20
+
21
+ $ gem install deployable-zmq
22
+
23
+ ## Copyright
24
+
25
+ Copyright (c) 2014 Deployable Ltd Matt Hoyle
26
+
27
+ See {file:LICENSE.txt} for details.
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'rake'
5
+
6
+ begin
7
+ gem 'rubygems-tasks', '~> 0.2'
8
+ require 'rubygems/tasks'
9
+
10
+ Gem::Tasks.new
11
+ rescue LoadError => e
12
+ warn e.message
13
+ warn "Run `gem install rubygems-tasks` to install Gem::Tasks."
14
+ end
15
+
16
+ begin
17
+ gem 'rspec', '~> 3.1'
18
+ require 'rspec/core/rake_task'
19
+
20
+ RSpec::Core::RakeTask.new
21
+ rescue LoadError => e
22
+ task :spec do
23
+ abort "Please run `gem install rspec` to install RSpec."
24
+ end
25
+ end
26
+
27
+ task :test => :spec
28
+ task :default => :spec
29
+
30
+ begin
31
+ gem 'yard', '~> 0.8'
32
+ require 'yard'
33
+
34
+ YARD::Rake::YardocTask.new
35
+ rescue LoadError => e
36
+ task :yard do
37
+ abort "Please run `gem install yard` to install YARD."
38
+ end
39
+ end
40
+ task :doc => :yard
@@ -0,0 +1,60 @@
1
+ # encoding: utf-8
2
+
3
+ require 'yaml'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gemspec = YAML.load_file('gemspec.yml')
7
+
8
+ gem.name = gemspec.fetch('name')
9
+ gem.version = gemspec.fetch('version') do
10
+ lib_dir = File.join(File.dirname(__FILE__),'lib')
11
+ $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
12
+
13
+ require 'deployable/zmq/version'
14
+ Deployable::Zmq::VERSION
15
+ end
16
+
17
+ gem.summary = gemspec['summary']
18
+ gem.description = gemspec['description']
19
+ gem.licenses = Array(gemspec['license'])
20
+ gem.authors = Array(gemspec['authors'])
21
+ gem.email = gemspec['email']
22
+ gem.homepage = gemspec['homepage']
23
+
24
+ glob = lambda { |patterns| gem.files & Dir[*patterns] }
25
+
26
+ gem.files = `git ls-files`.split($/)
27
+ gem.files = glob[gemspec['files']] if gemspec['files']
28
+
29
+ gem.executables = gemspec.fetch('executables') do
30
+ glob['bin/*'].map { |path| File.basename(path) }
31
+ end
32
+ gem.default_executable = gem.executables.first if Gem::VERSION < '1.7.'
33
+
34
+ gem.extensions = glob[gemspec['extensions'] || 'ext/**/extconf.rb']
35
+ gem.test_files = glob[gemspec['test_files'] || '{test/{**/}*_test.rb']
36
+ gem.extra_rdoc_files = glob[gemspec['extra_doc_files'] || '*.{txt,md}']
37
+
38
+ gem.require_paths = Array(gemspec.fetch('require_paths') {
39
+ %w[ext lib].select { |dir| File.directory?(dir) }
40
+ })
41
+
42
+ gem.requirements = gemspec['requirements']
43
+ gem.required_ruby_version = gemspec['required_ruby_version']
44
+ gem.required_rubygems_version = gemspec['required_rubygems_version']
45
+ gem.post_install_message = gemspec['post_install_message']
46
+
47
+ split = lambda { |string| string.split(/,\s*/) }
48
+
49
+ if gemspec['dependencies']
50
+ gemspec['dependencies'].each do |name,versions|
51
+ gem.add_dependency(name,split[versions])
52
+ end
53
+ end
54
+
55
+ if gemspec['development_dependencies']
56
+ gemspec['development_dependencies'].each do |name,versions|
57
+ gem.add_development_dependency(name,split[versions])
58
+ end
59
+ end
60
+ end
data/gemspec.yml ADDED
@@ -0,0 +1,16 @@
1
+ name: deployable-zmq
2
+ summary: "ZMQ helper classes"
3
+ description: "Standard ZMQ Pattern classes"
4
+ license: MIT
5
+ authors: Deployable Ltd Matt Hoyle
6
+ email: code@deployable.co
7
+ homepage: https://rubygems.org/gems/deployable-zmq
8
+
9
+ dependencies:
10
+ deployable-patch: ~> 0.3
11
+ ffi-rzmq: ~> 2.0.1
12
+
13
+ development_dependencies:
14
+ rspec: ~> 3.1
15
+ rubygems-tasks: ~> 0.2
16
+ yard: ~> 0.8
@@ -0,0 +1,12 @@
1
+ require 'deployable/zmq/version'
2
+
3
+ # Some defaults to be used about the place
4
+
5
+ module Deployable; module Zmq
6
+
7
+ DEFAULT_BIND_PORT = 5563
8
+ DEFAULT_BIND_ADDRESS = '*'
9
+ DEFAULT_CONNECT_ADDRESS = 'localhost'
10
+
11
+ end; end
12
+
@@ -0,0 +1,72 @@
1
+ require 'deployable/zmq/version'
2
+ require 'deployable/zmq/defaults'
3
+ require 'deployable/patch/instance_class_variables'
4
+
5
+ require 'ffi-rzmq'
6
+ require 'json'
7
+
8
+
9
+ module Deployable; module Zmq
10
+
11
+ # Deployable::Zmq provides a generic set of helpers do you
12
+ # don't have to do so much leg work.
13
+
14
+ class Publish
15
+
16
+ @port = DEFAULT_BIND_PORT
17
+ @address = DEFAULT_BIND_ADDRESS
18
+
19
+ def initialize options = {}
20
+
21
+ @context = ZMQ::Context.new
22
+ @publisher = @context.socket ZMQ::PUB
23
+
24
+ @port = options.fetch :port, __class_ivg( 'port' )
25
+ @port = DEFAULT_BIND_PORT if @port.nil?
26
+
27
+ @address = options.fetch :address, __class_ivg( 'address' )
28
+ @address = DEFAULT_BIND_ADDRESS if @address.nil?
29
+
30
+ uri = "tcp://#{@address}:#{@port}"
31
+
32
+ unless rc = @publisher.bind( uri ) == 0
33
+ raise "zmq bind failed [#{rc}] [#{uri}]"
34
+ end
35
+
36
+ #log.debug "zmq publishing on [#{uri}]"
37
+ end
38
+
39
+ # String a simple string
40
+ def send_string label, message
41
+ @publisher.send_string label, ZMQ::SNDMORE
42
+ @publisher.send_string message
43
+ end
44
+
45
+ # Send an array of messages
46
+ def send_arr label, array
47
+ @publisher.send_string label, ZMQ::SNDMORE
48
+
49
+ # Everything but the last element
50
+ array[0..-2].each do |e|
51
+ @publisher.send_string e.to_s, ZMQ::SNDMORE
52
+ end
53
+ @publisher.send_string array.last.to_s
54
+ end
55
+
56
+ # Send an object in json
57
+ def send_json label, obj
58
+ # parse before send in case of issues
59
+ message = obj.to_json
60
+ @publisher.send_string label, ZMQ::SNDMORE
61
+ @publisher.send_string message
62
+ end
63
+
64
+ # End the connection
65
+ def end
66
+ @publisher.close
67
+ end
68
+
69
+ end
70
+
71
+
72
+ end;end;
@@ -0,0 +1,3 @@
1
+ require 'deployable/zmq/version'
2
+ require 'deployable/zmq/publish'
3
+ require 'deployable/zmq/subscribe'
@@ -0,0 +1,66 @@
1
+ require 'deployable/zmq/version'
2
+ require 'deployable/zmq/defaults'
3
+ require 'deployable/patch/instance_class_variables'
4
+
5
+ require 'ffi-rzmq'
6
+ require 'json'
7
+
8
+
9
+ module Deployable; module Zmq
10
+
11
+ # Deployable::Zmq provides a generic set of helpers do you
12
+ # don't have to do so much leg work.
13
+
14
+ class Subscribe
15
+
16
+ @port = DEFAULT_BIND_PORT
17
+ @address = DEFAULT_CONNECT_ADDRESS
18
+
19
+ def initialize options = {}
20
+ @context = ZMQ::Context.new
21
+ @subscriber = @context.socket ZMQ::SUB
22
+
23
+ @port = options.fetch :port, __class_ivg('port')
24
+ @port = DEFAULT_BIND_PORT if @port.nil?
25
+
26
+ @address = options.fetch :options, __class_ivg('address')
27
+ raise "No valid address [#{@address}]" if @address.nil? or @address == '*'
28
+
29
+ url = "tcp://#{@address}:#{@port}"
30
+
31
+ raise "Failed to connect to [#{url}] [#{rc}]" unless
32
+ rc = @subscriber.connect( url ) == 0
33
+
34
+ #log.debug "zmq subscribing to [#{url}]"
35
+
36
+ @subscribe = options.fetch( :subscribe, nil )
37
+
38
+ raise "Failed to subscribe to [#{url}] [#{rc}]" unless
39
+ @subscribe.nil? or
40
+ rc = @subscriber.setsockopt( ZMQ::SUBSCRIBE, 'REQ_COMP' ) == 0
41
+
42
+ end
43
+
44
+ # Recieve a message off the queue
45
+ def receive
46
+ @subscriber.recv_strings( parts = [] )
47
+ #log.debug "a queue item [%s]\n", parts.join(' ')
48
+ parts
49
+ end
50
+
51
+ # Watch a queue for messages
52
+ def go callback
53
+ loop do
54
+ callback.call receive
55
+ end
56
+ end
57
+
58
+ # End a subscription
59
+ def end
60
+ @subscriber.close
61
+ end
62
+
63
+ end
64
+
65
+
66
+ end;end
@@ -0,0 +1,6 @@
1
+ module Deployable
2
+ module Zmq
3
+ # deployable-zmq version
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ require 'deployable/zmq/version'
2
+
3
+ module Deployable; module Zmq
4
+
5
+
6
+ end; end
7
+
8
+
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+ require 'deployable/zmq/publish'
3
+
4
+ describe Deployable::Zmq::Publish do
5
+
6
+
7
+ it "should have a VERSION constant" do
8
+ expect( Module.const_get('VERSION') ).to_not be_empty
9
+ end
10
+
11
+
12
+ describe "binds" do
13
+
14
+ it "binds a new connection" do
15
+ @connection = Deployable::Zmq::Publish.new
16
+ end
17
+
18
+ it "binds a new connection on a port" do
19
+ @connection = Deployable::Zmq::Publish.new( port: 5123 )
20
+ end
21
+
22
+ it "binds a new connection to an address" do
23
+ @connection = Deployable::Zmq::Publish.new( address: '127.0.0.1' )
24
+ end
25
+
26
+ it "binds a new connection to an address and port" do
27
+ @connection = Deployable::Zmq::Publish.new( port: 5123, address: '127.0.0.1' )
28
+ end
29
+
30
+ after :each do
31
+ @connection.end if @connection
32
+ end
33
+
34
+ end
35
+
36
+
37
+ describe "sends" do
38
+
39
+ before :each do
40
+ @connection = Deployable::Zmq::Publish.new
41
+ end
42
+
43
+ after :each do
44
+ @connection.end if @connection
45
+ end
46
+
47
+ it "sends a string" do
48
+ @connection.send_string "label", 'something'
49
+ end
50
+
51
+ it "sends array of string" do
52
+ @connection.send_arr "label", ['1','2','3']
53
+ end
54
+
55
+ it "sends arrays of non strings" do
56
+ @connection.send_arr "label", [1,2,3]
57
+ end
58
+
59
+ it "sends json" do
60
+ @connection.send_json "label", { sometthing: 2 }
61
+ end
62
+
63
+ end
64
+
65
+
66
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ require 'deployable/zmq/pubsub'
3
+
4
+ describe 'Deployable::Zmq pubsub' do
5
+
6
+ it "should have a VERSION constant" do
7
+ expect( Module.const_get('VERSION') ).to_not be_empty
8
+ end
9
+
10
+ end
@@ -0,0 +1,5 @@
1
+ gem 'rspec', '~> 3.1'
2
+ require 'rspec'
3
+ require 'deployable/zmq/version'
4
+
5
+ include Deployable::Zmq
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'deployable/zmq/subscribe'
3
+
4
+ describe Deployable::Zmq::Subscribe do
5
+
6
+
7
+ it "should have a VERSION constant" do
8
+ expect( Module.const_get('VERSION') ).to_not be_empty
9
+ end
10
+
11
+
12
+ describe "connects" do
13
+
14
+ end
15
+
16
+
17
+ describe "recieves" do
18
+
19
+ end
20
+
21
+
22
+ end
data/spec/zmq_spec.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+ require 'deployable/zmq'
3
+
4
+ describe Deployable::Zmq do
5
+ it "should have a VERSION constant" do
6
+ expect( Module.const_get('VERSION') ).to_not be_empty
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deployable-zmq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Deployable Ltd Matt Hoyle
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: deployable-patch
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ffi-rzmq
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubygems-tasks
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.8'
83
+ description: Standard ZMQ Pattern classes
84
+ email: code@deployable.co
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files:
88
+ - ChangeLog.md
89
+ - LICENSE.txt
90
+ - README.md
91
+ files:
92
+ - ".document"
93
+ - ".gitignore"
94
+ - ".rspec"
95
+ - ".yardopts"
96
+ - ChangeLog.md
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - deployable-zmq.gemspec
101
+ - gemspec.yml
102
+ - lib/deployable/zmq.rb
103
+ - lib/deployable/zmq/defaults.rb
104
+ - lib/deployable/zmq/publish.rb
105
+ - lib/deployable/zmq/pubsub.rb
106
+ - lib/deployable/zmq/subscribe.rb
107
+ - lib/deployable/zmq/version.rb
108
+ - spec/publish_spec.rb
109
+ - spec/pubsub_spec.rb
110
+ - spec/spec_helper.rb
111
+ - spec/subscribe_spec.rb
112
+ - spec/zmq_spec.rb
113
+ homepage: https://rubygems.org/gems/deployable-zmq
114
+ licenses:
115
+ - MIT
116
+ metadata: {}
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 2.2.2
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: ZMQ helper classes
137
+ test_files: []
138
+ has_rdoc: