crystalmq 0.0.1 → 0.0.2

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: df6d3b30398a787cd6e53bf63fbc9c23232f0479
4
- data.tar.gz: 52835e6aa112936319ce46f543ee7293613c6f25
3
+ metadata.gz: 66027d39db6fc4aad9c507b53fbbf4e9ba5a672b
4
+ data.tar.gz: 51c84757edab749ba5035a46e9fc0b04c238dd49
5
5
  SHA512:
6
- metadata.gz: cfef620c13035267d2fd8923acb2e759467590c146379366a554f5567473b30cb2a1ba291b0e9af6ce418118fca7e71fd5654104baec14256b179d2ea9e204e3
7
- data.tar.gz: 2be0d80fb77868dcba861f86a20ecc9626b7c0ce269ad52a8074e25e7249aa738765f47bd247671cbaf53aab7cb145f810954de3c0f6230024b2025785b7f0a4
6
+ metadata.gz: 79f62d2fc7bdff72b934b41322a7711cd4ab73ae257537ad8fa80cb8b042b1c31155953ce93cd662b9b6c9eff1a5b5147617c6adf20828ccd57c5e666f1dc8d7
7
+ data.tar.gz: 9359442b4d150f91bbba5722f26fd81a79fd06b689b55d33928cd5a9a8de4c46681024fb5b9f6d2836ff1332edcab65b880c643ab6ca9f550dddf0c842b2a6d8
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in basicjrpc.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Martin SImpson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Basic JRPC
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/jrpc`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'crystalmq'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install crystalmq
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/crystalmq/crystalmq-ruby.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jrpc"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/crystalmq.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ Gem::Specification.new do |spec|
3
+ spec.name = "crystalmq"
4
+ spec.version = "0.0.2"
5
+ spec.authors = ["Martin Simpson"]
6
+ spec.email = ["martin.simpson@crystalmq.io"]
7
+
8
+ spec.summary = "Crystal Message Queue Ruby Client"
9
+ spec.description = "A Client for the Crystal Message Queue written in Ruby"
10
+ spec.homepage = "http://crystalmq.io"
11
+ spec.license = "MIT"
12
+
13
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
14
+ spec.bindir = "exe"
15
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_development_dependency "bundler", "~> 1.11"
19
+ spec.add_development_dependency "rake", "~> 10.0"
20
+ spec.add_runtime_dependency 'msgpack'
21
+ end
data/lib/crystalmq.rb ADDED
@@ -0,0 +1,95 @@
1
+ require "msgpack"
2
+ require "socket"
3
+
4
+ class CrystalMQ
5
+ class MessagePayload
6
+ attr_reader :message
7
+
8
+ def initialize(message)
9
+ @message = message
10
+ end
11
+
12
+ def to_msgpack
13
+ { "message" => @message }.to_msgpack
14
+ end
15
+
16
+ def self.from_msgpack h
17
+ MessagePayload.new(h["message"])
18
+ end
19
+ end
20
+
21
+ class Consumer
22
+
23
+ class ConsumerPayload
24
+ attr_reader :topic, :channel
25
+ def initialize(topic, channel)
26
+ @topic = topic
27
+ @channel = channel
28
+ end
29
+
30
+ def to_msgpack
31
+ { "topic" => @topic, "channel" => @channel }.to_msgpack
32
+ end
33
+
34
+ def self.from_msgpack h
35
+ @topic = h["topic"]
36
+ @channel = h["channel"]
37
+ end
38
+ end
39
+
40
+ def initialize(host, topic, channel)
41
+ @socket = TCPSocket.new(host, 1235)
42
+ @socket.sync = true
43
+ @topic = topic
44
+ @channel = channel
45
+ end
46
+
47
+ def consume
48
+ @socket.write(ConsumerPayload.new(@topic, @channel).to_msgpack)
49
+ to_process = []
50
+ unpacker = MessagePack::Unpacker.new(@socket)
51
+
52
+ loop do
53
+ message = MessagePayload.from_msgpack(unpacker.read)
54
+ yield message.message
55
+ end
56
+ @socket.close
57
+ end
58
+ end
59
+
60
+ class Producer
61
+
62
+ class ProducerPayload
63
+ attr_reader :topic, :message
64
+
65
+ def initialize(topic, message)
66
+ @topic = topic
67
+ @message = message
68
+ end
69
+
70
+ def to_msgpack
71
+ { "topic" => @topic, "message" => @message }.to_msgpack
72
+ end
73
+
74
+ def self.from_msgpack h
75
+ @topic = h["topic"]
76
+ @message = h["message"]
77
+ end
78
+
79
+ end
80
+
81
+ def initialize(host, topic)
82
+ @socket = TCPSocket.new(host, 1234)
83
+ @socket.sync = true
84
+ @topic = topic
85
+ end
86
+
87
+ def write(message)
88
+ @socket.write(ProducerPayload.new(@topic, message).to_msgpack)
89
+ end
90
+
91
+ def terminate
92
+ @socket.close
93
+ end
94
+ end
95
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crystalmq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Simpson
@@ -54,11 +54,19 @@ dependencies:
54
54
  version: '0'
55
55
  description: A Client for the Crystal Message Queue written in Ruby
56
56
  email:
57
- - martin.c.simpson@gmail.com
57
+ - martin.simpson@crystalmq.io
58
58
  executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
- files: []
61
+ files:
62
+ - Gemfile
63
+ - LICENSE.txt
64
+ - README.md
65
+ - Rakefile
66
+ - bin/console
67
+ - bin/setup
68
+ - crystalmq.gemspec
69
+ - lib/crystalmq.rb
62
70
  homepage: http://crystalmq.io
63
71
  licenses:
64
72
  - MIT